Thursday 1 November 2018

JAVA Basics ?

Hi All, In this post I'll start from Java Basic.What is Java why famous and what?

Java Became Famous because it is platform independent.
Plat for Independent ? lang like c/c++ when we compile the prog we'll run the prog in the compiled env or os but java is a language where we can write the prog in one os and run in another.
Java built and run on top of the JVM so the layer b/w java and os is JVM.

                                                   Java ---- JVM --- OS
so we can write java prog and run anywhere, that is the reason java called platform independent.
we can relate platform to out railway station, we have different different railway platform where train stop and passenger used to catch their train in the same way to run the prog in different platform(OS) we need basic requirement for most of the language but java is the platform independent language.
java not adhere with the platform we can run java prog in any platform.
hope sounds better.
Java Prog Platform - There are 4 java platform.
  • Java Platform, Standard Edition (Java SE)
  • Java Platform, Enterprise Edition (Java EE)
  • Java Platform, Micro Edition (Java ME)
  • JavaFX
So next thought in our mind what is the diff ? or where should we use to SE/EE/ME/FX ?


Java SE -This is the core Java programming platform. It contains all of the libraries and APIs that any Java programmer should learn like java.io,java.lang,java.math,java.util,java.net etc.
Java EE -The Java platform (Enterprise Edition) differs from the Java Standard Edition Platform (Java SE) in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier Java software, based largely on modular components running on an application server.
In other words, if your application demands a very large scale, distributed system, then you should consider using Java EE. Built on top of Java SE, it provides libraries for database access (JDBC, JPA), remote method invocation (RMI), messaging (JMS), web services, XML processing, and defines standard APIs for Enterprise JavaBeans, servlets, portlets, Java Server Pages, etc.
Java ME -This is the platform for developing applications for mobile devices and embedded systems such as set-top boxes. Java ME provides a subset of the functionality of Java SE, but also introduces libraries specific to mobile devices. Because Java ME is based on an earlier version of Java SE.
Java FX -JavaFX is a platform for creating rich internet applications using a lightweight user-interface API. JavaFX applications use hardware-accelerated graphics and media engines to take advantage of higher-performance clients and a modern look-and-feel as well as high-level APIs for connecting to networked data sources. JavaFX applications may be clients of Java EE platform services.

Hope Guys everything clear.Next question in your mind may be what is JVM and how Java works or steps to run the Java prog ?
Life Cycle of Java -Life cycle of java includes 3 steps -
Java Prog(JavaFile) -->Compiler-->Bye Code(Class file)-->JVM(Machine readable code)
Not to be in hurry just wait !
Java File ?
Compiler, Interpreter or JIT ?
Class File ?
JVM ?
what is it man? where are we ?
Let me explain all hold on a minute ...

Java File - Basically Java File is the file which contains many lines of code in java Language and saved with .java extension.
Compiler, Interpreter or JIT - We can understand the concept like India having different states and all state has different language, we have one international school where English is common language.teacher gave assignment to students in English and students Discussed Problem in their house in local language and solve the prob so output for all the students are same. 

here intermediate language English, which is very close to machine language called "Byte code"
Local language like OS(Windows32,64,linux, solaris etc).
School Students like a Interpreter.
Teacher like an Compiler.


The Compiler of java called as javac converts source code into a Intermediate file known as Bytecode file. The Bytecode file is unique for all types of OS means bytecode is platform independent

Now The Interpreter of java (java) converts Bytecode into the specific OS compatible machine code . This code will vary according to OS.
Now What i s Bytecode file ? why it is called as Bytecode file ?
Bytecode is just like Shorthand language that store each keyword of java as a sign. and each sign takes 1 byte of memory in RAM. Hence the name called as Bytecode file.

Why we use both - Compiler as well as Interpreter in Java(Need of Separate compiler and Interpreter) ?

At the time of C and C++, only Compiler was there that converts source code into specific OS machine code. The machine code was OS dependent that varied from OS to OS.

The problem the programmer were facing that They had to design a different compiler for different Operating System that is too difficult, Too time consuming and much Costly.

Then Sun Microsystem take the whole Initiative by making :

a Unique compiler that produce Platform Independent Bytecodes and

the Specific JVM(Java Virtual Machine)or Interpreter that converts bytecodes into machine code that will vary from OS to OS.
making different JVM for different OS was much easier and economical than the whole Compiler.
JIT - It is a compiler which takes chunks of code(Which is necessary among the Many Loc) and interpret line by line which save the time and increase the  performance.
Class File - Class file Which contains Bytecode ,Non Human readable code Human can't read and those are Machine independent Codes.Compiler generates those bytecode.
JVM -JVM is a engine that provides runtime environment to drive the Java Code or applications. It converts Java bytecode into machines language. JVM is a part of JRE(Java Run Environment).
JVM Architecture -
Let's understand the Architecture of JVM. It contains classloader, memory area, execution engine etc.
1) ClassLoader -The class loader is a subsystem used for loading class files. It performs three major functions viz. Loading, Linking, and Initialization.

2) Method Area -JVM Method Area stores class structures like metadata, the constant runtime pool, and the code for methods.

3) Heap -All the Objects, their related instance variables, and arrays are stored in the heap. This memory is common and shared across multiple threads.

4) JVM language Stacks -Java language Stacks store local variables, and it’s partial results. Each thread has its own JVM stack, created simultaneously as the thread is created. A new frame is created whenever a method is invoked, and it is deleted when method invocation process is complete.

5)  PC Registers -PC register store the address of the Java virtual machine instruction which is currently executing. In Java, each thread has its separate PC register.

6) Native Method Stacks -Native method stacks hold the instruction of native code depends on the native library. It is written in another language instead of Java.

7) Execution Engine -It is a type of software used to test hardware, software, or complete systems. The test execution engine never carries any information about the tested product.

8) Native Method interface -The Native Method Interface is a programming framework. It allows Java code which is running in a JVM to call by libraries and native applications.

9) Native Method Libraries -Native Libraries is a collection of the Native Libraries(C, C++) which are needed by the Execution Engine.

Software Code Compilation & Execution process
In order to write and execute a software program, you need the following

1) Editor – To type your program into, a notepad could be used for this

2) Compiler – To convert your high language program into native machine code

3) Linker – To combine different program files reference in your main program together.

4) Loader – To load the files from your secondary storage device like Hard Disk, Flash Drive, CD into RAM for execution. The loading is automatically done when you execute your code.

5) Execution – Actual execution of the code which is handled by your OS & processor.
C code Compilation and Execution process
To understand the Java compiling process in Java. Let's first take a quick look to compiling and linking process in C.
Suppose in the main, you have called two function f1 and f2. The main function is stored in file a1.c.

Working of Java Virtual Machine(JVM) & its Architecture
Working of Java Virtual Machine(JVM) & its Architecture
Function f2 is stored in a file a3.c
Working of Java Virtual Machine(JVM) & its Architecture
All these files, i.e., a1.c, a2.c, and a3.c, is fed to the compiler. Whose output is the corresponding object files which are the machine code.
Working of Java Virtual Machine(JVM) & its Architecture
The next step is integrating all these object files into a single .exe file with the help of linker. The linker will club all these files together and produces the .exe file.
Working of Java Virtual Machine(JVM) & its Architecture
During program run, a loader program will load a.exe into the RAM for the execution.
Working of Java Virtual Machine(JVM) & its Architecture

Java code Compilation and Execution in Java VM

Let's look at the process for JAVA. In your main, you have two methods f1 and f2.
  • The main method is stored in file a1.java
  • f1 is stored in a file as a2.java
  • f2 is stored in a file as a3.java
Working of Java Virtual Machine(JVM) & its Architecture
The compiler will compile the three files and produces 3 corresponding .class file which consists of BYTE code. Unlike C, no linking is done.
The Java VM or Java Virtual Machine resides on the RAM. During execution, using the class loader the class files are brought on the RAM. The BYTE code is verified for any security breaches.
Working of Java Virtual Machine(JVM) & its Architecture
Next, the execution engine will convert the Bytecode into Native machine code. This is just in time compiling. It is one of the main reason why Java is comparatively slow.
Working of Java Virtual Machine(JVM) & its Architecture
NOTE: JIT or Just-in-time compiler is the part of the Java Virtual Machine (JVM). It interprets part of the Byte Code that has similar functionality at the same time.
Cheers Guys :)

No comments:

Eclipse With Python

Hi Guys, Today i'll share how to start python project in eclipse IDE. to start Py development in eclipse we need to add Py Dev plugi...