Java Fundamentals
what is java
- Object Oriented Programming.
- WORA( Write Once Run any where).
- The Java language was created by James Gosling in June 1991.
- Java Provides development and deployment environment.
- It is similar in syntax to C++.
- It is robust provides exception handling and automatic garbage collection.
- Designed for the distributed environment.
- Supports Multithreading
Java History
Java was designed for hand-held devices and set-top boxes. It was originally named as Oak but became unsuccessful, so in 1995, Sun changed its name to JAVA. James Gosling’s goals were to implement a virtual machine and a language that has a familiar C/C++ style of notation. The first public implementation was Java 1.0 in 1995. It promised “Write Once, Run Anywhere” (WORA).
WORA
The goal of WORA is to write an application and run anywhere.
Java Kick Start
Java Development Kit(JDK)
JDK = javac compiler + .jar (libraries) + javadoc + jdb + JRE
JDK – JDK is a software package which is used to develop and deploy java applications.
JDK consists
a) javac compiler – it is use to convert .java file into .class file
b) JAR Files – A jar files are java API’s , which contains number of classes and interfaces. For Example to make a database connection with oracle we require ojdbc.jar.
c) Javadoc – through this utility we can make Java documentaion for any java program.
d) Jdb- jdb is a java debugger.
e) JRE – See in the next slide.
JRE (Java Runtime Environment)- A JRE is required to run Java applications interpretively on a target hardware and operating system platform.
JRE = JVM (Java Virtual machine)+ jar files (libraries)
JVM
a) JVM is a software that is plat form specific. For example for Linux platform
b) You require a Linux based JVM , for windows platform you require a windows based JVM.
c) Now in these days JVM is bundled with Internet explorer and With other types of browsers.
JVM performs the following tasks
a) Class Loader Loads:- all the .class file, necessary for the execution of a program.
b) Byte code Verifier:- It ensures the code does not no illegal data conversion, no stack over flow, not violate system integrity.
c) JIT :- (Just In time compiler) JIT work as a cache for the JVM interpreted code. It memorized the repeated code instructions (that is interpreted by the JVM) and when JVM reqiure the same set of instructions so JIT provides these instructions to the JVM , so JVM does not interpret the same instructions again
d) Generate Native Code:- The JVM and the Java API are built for every O/S platform. The Java API calls to the O/S API.
e) Class Loader:- The Java Classloader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine.
f) When the JVM is started, three class loaders are used
- Bootstrap class loader
- Extensions class loader
- System class loader
The bootstrap class loader:- loads the core Java libraries (<JAVA_HOME>/lib directory). This class loader, which is part of the core JVM, is written in native code.
The extensions class loader:- loads the code in the extensions directories (<JAVA_HOME>/lib/ext or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.
The system class loader:- loads code found on java.class.path, which maps to the system CLASSPATH variable. This is implemented by the sun.misc.Launcher$AppClassLoader class
First Java Program
Step 1: Write Code
Example:
class Fun {
public static void main(String args[])
{
System.out.println(“Yep ! “);
}
}
Step 2: Save Code with class Name
Fun.java
Step 3: Compile the code
javac A.java ( when you compile the code it will generate an intermediate code (Byte code) it is not a machine code.
Step 4: run the Program
java Fun ( running the program by starting the JVM with the A.class. The JVM translates the bytecode into something the underlying platform understands , and runs your program.
Programme Observation
When the JVM starts running , it looks for the class that is at the command line. Then it starts looking for a specially written method that looks exactly like:
public static void main(String args[])
{
//Your Code Here
}
You can define main method in the following ways
a) public static void main(String args[])
b) static public void main(String args[])
c) public static void main(String …a) // Allowed in JDK 1.5 or higher
d) static public void main(String …a) //Allowed in jdk1.5 or higher
- The main method is public , because java is package centric language.
- Now JVM has to access your main method from outside your package. That’s why it set to as public.
- The main method also static , because static is loaded on the compile Time and not required to instantiate.
- The main method is void , because it does not required to return any thing to the JVM.
- String args[] is used for command line arguments , where String is a Java class.
System.out.println(“Yep ! ”);
Where
- System is a final class, found in java.lang package.
- Out is an object of PrintStream class and it declare static in the System Class.
- Println(String msg) this is a method define in the PrintStream class. Used to print on console and print in new line


