JAVA


How Java Works?.

In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into.class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes — the machine language of the Java Virtual Machine (Java VM). The java launcher tool then runs your application with an instance of the Java Virtual Machine.


How JAVA Capable of Running on Multiple Platforms?.

Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris TMOperating System (Solaris OS), Linux, or Mac OS.


The Java platform has 2 components:
  • Java Virtual Machine (JVM) – ‘JVM’ is a software that can be ported onto various hardware platforms. Bytecodes are the machine language of the JVM.
  • Java Application Programming Interface (Java API) – set of classes written using the Java language and run on the JVM.
Advantages of Object Oriented Programming Language?.


The Object Oriented Programming Languages directly represent the real life objects like Car, Jeep, Account,
Customer etc. The features of the OO programming languages like polymorphism, inheritance and 
encapsulation make it powerful. [Tip: remember pie which, stands for Polymorphism, Inheritance and 
Encapsulation are the 3 pillars of OOPL]


Inheritance : should be only used when subclass ‘is a’ superclass. example House(sub class) is a Building(Super Class) 


Polymorphism: The ability of a single variable of a given type to be used to reference objects of

different types, and automatically call the method that is specific to the type of object the variable references.

Overloadingoverriding and dynamic method binding are three types of polymorphism.


Encapsulation: Refers to keeping all the related members (variables and methods) together in an object. Specifying member variables as private can hide the variables and methods. Objects should hide their inner workings from the outside view.

Difference Between Interface and Abstract Class,When Should You Use Them?.

  • Interface (Multiple Interface Inheritance)
    • Have no implementation code. All methods are abstract
  • Abstract Class ( Implementation Inheritance)
    • Abstract classes let you define some default behavior and force subclasses to provide any specific 
    • behavior.
Java Does not supports Multiple Inheritance

Getting started with Java

Downloading & Installing the JDK

     Before you can develop Java applications, you'll need to download the Java Development Kit (JDK). You may prefer at a later time to use a third party IDE, such as Eclipse, MyEclipse, IntelliJ, NetBeans,Visual J++ or Borland JBuilder, but it is important to become familiar with the basics of Java first.

The Most Current version you can find at  http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u26-download-400750.html


Step 1
Double click the JDK down loaded file, the executable extracts the required Contents to the temporary directory and then License agreement screen  appears. On the license agreement page read and accept the license and the click the next button .
Step 2
The custom setup screen appears as follows.
Step 3
Click on the change button to change the installation directory to "c:\jdk1.5.0_06" as shown in the following screen. Most of the Time it takes the default directory like c:\Programm Files\Java\jdk1.5.0_06
and click on the "OK" button. After clicking on the "OK" button installation begins:
Step 4
In the next window installer asks for the installing the runtime as shown in the following screen:
Step 5
Click on next button install the J2SE runtime on your machine. Next screen shows the browser selection:
Click on the "Next" button.
Step 6
Once the installation is finished it shows you the final screen indications the success. Now you have successfully installed J2SE on your machine. Installer shows the following final confirmation window as shown below:
Click on the "Finish" button to exit from the installer.
Configuring the installation on windows machine:
In this Section we will add some settings to the windows environment so that the java compiler and runtime becomes available for compiling and running the java application.
Go to the control panel and double click on "System Properties" and to to the advance tab. 
and add "c:\jdk1.5.0_06\bin" to path variable:
PATH: is a system variable used to tel to OS all locations of exec files.
PATH set to c:\jdk1.5.0_06\bin
The commands of "javac" and "java" (amongst others), are not system commands, they are Java commands. Meaning, that if you are in the Java bin directory, then the computer understands what these commands mean. If you are out of that directory, then the computer doesn't understand what these commands mean.

Set the PATH variable if you want to be able to conveniently run the executables (javac.exejava.exejavadoc.exe, and so on) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable every time you run it, such as:
C:\Program Files\Java\jdk1.6.0\bin\javac MyClass.java
The PATH can be a series of directories separated by semicolons (;)
CLASSPATH : Is Pure java variable, which is used to tel locations of all jar/zip(classes) files to Compiler.
CLASSPATH set to c:\jdk1.5.0_06\lib

Understanding JDK Directory Structure

This section introduces the Directory and file structure of JDK (Software Development Kit). The following figure shows jdk1.5.0 software stored in 'c' directory that has multiple subdirectories like bin, demo, include and jre etc. to hold all important developing and testing tools. See detail information bellow.

JDK Directory Structure:




Subdirectories of the JDK:
The jdk1.5.0 has following directory:


Bin directory - The bin directory provides all inessential tools for developing and testing the program through the help of command provided by Java compiler.
Demo directory - This directory consists many applications and applets with source code. 
Include directory - It contains all header files like for 'C' programming language that enables you to combine C code into a Java program.
Jre directory - When you run any java program then you have to compile it by the help of  Java interpreter or Java Runtime Environment (JRE). The SDK uses the internal adaptation of JRE, which containing in the jre root directory.
Lib directory - This is a most important directory for development tools that contains libraries and it's supported files.
Docs directory - It is the last directory of Software Development Kit that assists you to store the Java documents. The docs directory is an optional directory.
Files of the SDK:
JDK1.5.0 directory has following files that provide the detail information about it.
README.html : The jdk1.5.0 directory provides an html file that contains the detail information of SDK shown on the web browser. This file contains all system requirements, features and documentation links to represents all information's about the jdk1.5.0.
scr.zip: The zip file is a collection of one of more files that has been compressed or stored to '.zip' extension. Similarly, the scr.sip file contains the source code of SDK. It become necessary to extract the file that contain the source code from the ZIP file. 
I am sure you dont understand completely even if you read completely,still you have questions in your mind what is JVM(Java Virtual Machine),JDK,JRE,Compiler,.class file,PATH,CLASSPATH.It is not one day process to learn every thing,continuous learning process.