Tuesday, April 7, 2015

Learn Java-PART 1



History of java

In 1991, Sun Microsystems engineers led James Gosling decided to develop a language for consumer device like (Cable boxes etc). Consumers want to be hardware independent (means independent application, suppose you develop a application software in windows but it not capable to run on Unix) but hands on those person who free from these tenses. Since different manufactures would use different CPUs, different systems configurations but this language is ready to run on all platforms. The project as code name ‘GREEN’.

In this time, Sun microsystem uses UNIX for their project. We uses C++ language in this project because c++ language was used object oriented’. The original name of the language was oak. And later  they changed the name(oak) to java in January 1995.

Finally, one big step was taken on 7 dec 1995 when Microsoft signed a letter of interest with sun for java technology source license.

Where it used?

Probably Java is used.
1.      Desktop Application such as acrobat reader, Antivirus etc.
2.      Web Application
3.      Enterprise application such as banking application
4.      Mobile such as android and java ME
5.      Embedded system
6.      Smart card
7.      Robotics
8.      Games etc.

Java is high level language. It is completely hardware  independent language means “write once, run anywhere and at anytime, forever”. Programs are run by an interpreter that converts the byte code to the appropriate native machine code.

Byte code: byte code consists of optimized set of instruction that are not specific to processor. We get byte code after compiling the java program using a compiler called javac.

Native code: native code is computer programming (code) that is compiled to run with a particular processor and its set of instruction.

JVM, JRE, JIT and JDK

JVM (java virtual machine):- the bytecode is to be executed by java runtime environment (JRE) which is called as java virtual machine. The program that are running on JVM must be compiled into a binary format which is denoted by .class files.
The  JVM execute .class or .jar files, by either interpreting it or using a just in time compiler (JITc).

Note: the JIT is used for compiling and not for interpreting the file. 

1.      JVM is like a specification (map) of documentation.

2.      JRE is like a implementation of document, it is not an open source.

3.      JDK (java development kit)- it is the collection of JRE and package file.

Note: every source code (.java) generate the .class file.

Firstly we are install the jdk in our computer.

Path set: there are two way  of run the java program.

1.      Computer icon right click -> property ->advanced system -> environment variable -> System variable -> new -> variable name is path and Variable value is address of the bin file.

C:/program files/java/jdk/bin

This the permanent method of path save of java program. You can be save anywhere in computer and run program.

2.      C drives -> program file -> java -> jdk -> bin -> save the program.

Simple program

Class A
{
Public static void main(String arr[])
{
System.out.println(“hello”);
}
}
Compile -> javac A.java
Execution -> java A

BY default java classes and packages are distributed in .jar format.
.jar file is the compress format of the file.

Note:  Java is open source. So you can check rt.java. it is the compress file of classes and package. This is provided by sun microsystem as part of JDK.
C:\program file\java\jdk\jre\lib\rt.jar

E:\jar -> describe all keyword
E:\jar –xf rt.jar

Void: No return type. If there is an error in the program then o.s check it and give the message.

Public : JRE is the outside part of the class. JRE call the main method and access specifier.

Static: In a class there are two type of members.

1.      Instance Member
2.      Class Member

Instance member: this member represent attributes

And behavior of individual object.

Class Member:- class member represent attribute & behavior of the whole class.

Note:  static keyword denotes class members.

By default all the member of a class are instance member.

Method: first letter of each word except the first word of the method is capitalized.
print();

getPrioprity();

getKeyMathodMap();       etc.

String arr[] : main method is to used command line argument. It is represent I/P provided by command prompt with name of command.

System: it is the final class in java.lang package. System class facility provided input, output, error, loading file & library.

Out: out is static member of the system class and is type printstream class.

Println: it is the method of printstream class.

Example:

 class printstream
{
Public void print(String s)
{
-------
}
Public void println(String s)
{
-------
}
Class system
{
Public static printstream out;
{------
}


                                                          Author-Ravi Kumar