Objectives: - To Be Able To
Objectives: - To Be Able To
To be able to:
To be able to differentiate between Structured Oriented
Programming and OOP.
To be able to understand the difference between two
object oriented languages like C++ and JAVA.
To be able to understand the data storage in JVM.
To be able to understand the PATH, CLASSPATH setting.
WHAT WE DO IN JAVA
Overview
JDBC
IS JAVA WORKING ?
Our Target
Compiling and Running HelloWorld
Compiling HelloWorld.java
javac HelloWorld.java
Running an application
java HelloWorld
Note: Before compile and run the JAVA code need to set the PATH
and CLASSPATH environment variables.
TestGreeting.java
1//
2//Sample"HelloWorld"application
3//
4publicclassTestGreeting{
5publicstaticvoidmain(Stringargs[]){
6Greetinghello=newGreeting("Hello");
7hello.greet("World");
8}
9}
Greeting.java
1//TheGreetingclassdeclaration
2publicclassGreeting{
3privateStringsalutation;
4
5publicGreeting(Strings){
6salutation=s;
7}
8
9publicvoidgreet(Stringwhom){
10System.out.println(salutation+""+whom);
11}
12}
The difference with Java is that it uses bytecode - a special type of machine
code thats why JAVA is compiled and interpreted type of language.
JVM Architecture
The Heap:
All Java objects take their storage from the heap
Whenever you need to create an object, you simply write the code
to create it by using new, and the storage is allocated on the heap
when that code is executed.
JVM Architecture
Class Loader
Byte-Code verifier
JVM Architecture
JVM Architecture
Garbage Collection
Java has a garbage collector, which looks at all the
objects that were created with new and figures out which
ones are not being referenced anymore. Then it releases
the memory for those objects, so the memory can be
used for new objects.
memory yourself.
Garbage Collection
Garbage Collection Algorithm
The algorithm performs two basic things:
1. Detect garbage objects.
(maintain a tree of objects)
2. To reclaim heap space.
Some functions available for requesting the garbage
collection: (Gives a suggestion to JVM)
Runtime.getRuntime().gc().
System.gc();
System.gc() simply calls Runtime.getRuntime().gc(). And
Runtime.getRuntime().gc() invokes a native method in the JVM.
Version 1.1:
Improvements include better event handling, inner classes,
improved JVM.
Microsoft developed its own 1.1. compatible Java Virtual
Machine for the Internet Explorer.
Many browsers in use are still compatible only with 1.1.
Swing packages of greatly improved graphics became
available during this time but not included with the core
language.
Version 1.3:
Performance enhancements including the Hotspot
virtual machine.
Version 5.0:
version 6.0:
Assignment
Write a Java class that can print Welcome to
Java Programming
Learn the difference between PATH, CLASSPATH,
JAVA_HOME Environment variables and be able
to set them up.
Explain the importance of JVM in JAVA
and its architecture.
Modularize a JAVA class and explain its meaning.
Learn and point out why we moved from
structured programming to OOP.