Java J2EE-Unit-1
Java J2EE-Unit-1
University
MSc 1st Semester
Course: Java & J2EE Unit-
Presented By
1 Chaithra C S
Course Code: 23MSCS110 Assistant Professor
Dept of Computer Applications
JSSSTU Mysuru
History of Java
• Java started out as a research project.
James
Gosling
Java Logo
Versions of Java
Version Codename Year Features Added
JDK 1.0 Oak Jan23,1996 -
Rebirth of Inner classes JavaBeans, JDBC, RMI, Reflection, AWT.
JDK 1.1 Feb19,1997
Java
JIT compiler, Collections, IDL & CORBA, strictfp, Java
J2SE 1.2 Playground Dec8, 1998
Plug-in.
HotSpot JVM, JavaSound, Java Naming and Directory
J2SE 1.3 Kestrel May8, 2000 Interface, Java Platform Debugger Architecture.
• It interprets the byte code into the machine code depending upon the
underlying OS and hardware combination. JVM is platform dependent. (It
uses the class libraries, and other supporting files provided in JRE)
Java Terminology (contd…)
ØJava Runtime Environment:
A runtime environment which implements Java Virtual Machine, and
provides all class libraries and other facilities necessary to execute
Java programs. This is the software on your computer that actually
runs Java programs.
JRE = JVM + Java Packages Classes (like util, math, lang, awt, swing
etc) +runtime libraries.
Class Loader Java Class
Java Byte Code
Libraries
Source Verifier Java
Execution
Java Byte
codes Procedure
move Java Just-in-time
Java
locally or Interpreter Compiler
Compiler
through
n/w
Run Time System
MAC Others
Hardware
Architecture of JVM
Java Virtual Machine
As the program runs, the virtual machine places all objects the program
instantiates onto the heap.
As each new thread comes into existence, it gets its own pc register
(program counter) and Java stack.
Libraries
JVM
JRE
Operating System
Hardware
Java Program Execution
• A Java program requires JVM (part of JRE) to execute Java code. When java
application starts to executes, Java Virtual Machine also starts.
• Bytecode has instructions that Java Virtual Machine can understand and
execute.
• JVM converts the Bytecode to machine specific code.
• Java Bytecode can be copied on to any machine that has JVM and
executed. This is what makes Java Platform Independent.
• “Write Once, Run any where”
Binary form of a .class file
public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello, World!");
}
}
0000: cafe babe 0000 002e 001a 0a00 0600 0c09 ................
0010: 000d 000e 0800 0f0a 0010 0011 0700 1207 ................
0020: 0013 0100 063c 696e 6974 3e01 0003 2829 .....<init>...()
0030: 5601 0004 436f 6465 0100 046d 6169 6e01 V...Code...main.
0040: 0016 285b 4c6a 6176 612f 6c61 6e67 2f53 ..([Ljava/lang/S
0050: 7472 696e 673b 2956 0c00 0700 0807 0014 tring;)V........
0060: 0c00 1500 1601 000d 4865 6c6c 6f2c 2057 ........Hello, W
0070: 6f72 6c64 2107 0017 0c00 1800 1901 0005 orld!...........
0080: 4865 6c6c 6f01 0010 6a61 7661 2f6c 616e Hello...java/lan
0090: 672f 4f62 6a65 6374 0100 106a 6176 612f g/Object...java/
00a0: 6c61 6e67 2f53 7973 7465 6d01 0003 6f75 lang/System...ou ...
Features of Java Language
ØSimple
ØObject Oriented
ØCompile, Interpreted and High Performance
ØPortable
ØReliable
ØSecure
ØMultithreaded
ØDynamic
ØDistributed
ØArchitecture-Neutral
Java Features
• Simple
• No pointers
• Automatic garbage collection
• Rich pre-defined class library
• Object Oriented
• Focus on the data (objects) and methods manipulating the data
• All methods are associated with objects
• Potentially better code organization and reuse
Java Features
• Compile, Interpreted and High Performance
• Java compiler generate byte-codes, not native machine code
• The compiled byte-codes are platform-independent
• Java byte codes are translated on the fly to machine readable instructions in
runtime (Java Virtual Machine)
• Easy to translate directly into native machine code by using a just-in-time compiler.
• Portable
• Same application runs on all platforms
• The sizes of the primitive data types are always the same
• The libraries define portable interfaces
Java Features
• Reliable/Robust
• Extensive compile-time and runtime error checking
• No pointers but real arrays. Memory corruptions or unauthorized
memory accesses are impossible
• Automatic garbage collection tracks objects usage over time
• Secure
• Java’s robustness features makes java secure.
• Access restrictions are forced (private, public)
Java Features
• Multithreaded
• It supports multithreaded programming.
• Need not wait for the application to finish one task before beginning
another one.
Dynamic
Libraries can freely add new methods and instance variables without any
effect on their clients
Interfaces promote flexibility and reusability in code by specifying a set
of methods an object can perform, but leaves open how these methods
should be implemented .
Java Features
• Distributed
• Java is designed for the distributed environment of the Internet, because
it handles TCP/IP protocols.
• Allows objects on two different computers to execute procedures
remotely by using package called Remote Method Invocation (RMI).
• Architecture-Neutral
• Goal of java designers is “write once; run anywhere, any time, forever.”
JVM: perspectives
• JVM can be looked as
• a runtime instance: JVM life cycle begins when applications starts
to run ( that is when main method is called) and ends when the
application ends.
• the abstract specification: Specification that Java team at Sun
(Oracle) provides which tells JVM makers how they must design
JVM for their OS.
• a concrete implementation: JVM that is built specifically targeted
for an OS based on abstract specification .
Automatic garbage collection
• The garbage collector is a tool that attempts to free unreferenced memory
(memory occupied by objects that are no longer in use by the program) in
programs.
• Automatic garbage collection is an integral part of Java and its run-time
system.
• Java technology has no pointers. So there is no question of allocation and
freeing by programmers.
• Does that mean Java does not support dynamic memory allocation?
• No. It means that Java takes care of memory and relieves the programmers
from memory-related hassles.
• java –verbose:gc can be used to get more information about garbage
collection process.
Object Oriented Programming Concepts
•Objects
•Classes
•Data abstraction and Encapsulation
•Inheritance
•Polymorphism
•Dynamic Binding
A class is collection of objects of similar type or it is a template.
Ex: fruit mango;
The wrapping up of data and functions into a single unit ( called class) is known
as encapsulation. Data encapsulation is the most striking features of a class.
Inheritance is the process by which objects of one class acquire the properties
of another class. The concept of inheritance provides the reusability.
Polymorphism:
It allows the single method to perform different actions based on the
parameters.
•The principle of data hiding helps the programmer to build secure programs.
• Object-oriented databases
• CAD/CAM systems
ØWhat is the Difference b/w OO and OB Languages?
In Object based languages inheritance is not supported so that
dynamic polymorphism also not supported.
E.g. VB,VC++.
void states that the main method will not return any value.
}
void display(){
System.out.println("display:main");
}
}