Introduction To Java
Java is a high level, Object Oriented Programming language developed by James Gosling and his team at Sun MicroSystem. Java is initially called “Oak” then later it renamed Java. It is maintained by Oracle.
Java main principle is
Write Once, Run Anywhere
Which means Java is a platform Independent we can run this code in all the other system like windows, mac and linux.
Java is used to build Web applications, Desktop applications, games and backend services.
How Java Works?
When we write a program in java, we save it with .java extension. Then the source code is converted into bytecode with .class extension using java compiler. Then bytecode is converted into machine code (0s and 1s) using interpreter.
Byte Code is an intermediate code which can only understood by JVM.
Get Vignesh’s stories in your inbox
Join Medium for free to get updates from this writer.
So everyone has a doubt, whether java is compiled or interpreted language. Java is a both compiled and interpreted language. It uses java compiler to convert source code into bytecode and it converts that bytecode into machine code using an interpreter.
Architecture of Java
JDK
- It provides environment to develop and run the code.
- It is a package that includes
— Development tools
— JRE
— Compiler
— Archiver
— Docs generator
— Interpreter / loader
JRE
- It is an installation package that provides environment to only run the program.
- It consists of :
— Deployment technologies
— User interface toolkits
— Integration libraries
— Base libraries
— JVM
JVM
- JVM converts bytecode into machine code.
- It is a heart of java. It loads, verifies and executes the bytecode.
- It has several responsibilities.
1. Loads classes
2. Verifies bytecode
3. Executes bytecode
JIT
- Converts the frequently executed bytecode into native machine code once. So it doesn’t need to be interpreted repeatedly.
- Example : Imagine you are travelling from home to college every day. The first time, we use google map. The second time, we use google map. Third time, we use google map. That is inefficient cause it is a same route. Instead after traveling few times, we memorize the route. That exactly what JIT does.
Different between compiler and interpreter
Compiler
— It executes the entire source code.
— Produce output file(.class in java and .exe in c/c++).
— Errors all shown after compilation the entire program.
— Faster execution
Interpreter
— It executes line by line.
— Doesn’t produce an output file.
— Errors are shown one at a time as it encounters them.
— Slower execution.









