My Java Notes
My Java Notes
Java was designed with core principles: simplicity, robustness, security, high
performance, portability, multi-threading, and dynamic interpretation.
Features of Java
The Java codes are first compiled into byte code (machine-independent code). Then
the byte code runs on Java Virtual Machine (JVM) regardless of the underlying
architecture.
Java syntax is similar to C/C++. But Java does not provide low-level programming
functionalities like pointers. Also, Java codes are always written in the form of
classes and objects.
For example, non-primitives are always references in Java. So we cannot pass large
objects (like we can do in C++) to functions, we always pass references in Java.
One more example, since there are no pointers, bad memory access is also not
possible.
When compared with Python, Java kind of fits between C++ and Python. The programs
are written in Java typically run faster than corresponding Python programs and
slower than C++. Like C++, Java does static type checking, but Python does not.
The Java compiler (javac) converts the source code into bytecode, which is stored
in a .class file. This bytecode is platform-independent and can be executed on any
machine with a JVM.
JDK=JRE+Development Tools
if you are only interested in running Java programs on your machine then you can
easily do it using Java Runtime Environment. However, if you would like to develop
a Java-based software application then along with JRE you may need some additional
necessary tools, which is called JDK.
Execution Engine
Execution engine executes the “.class” (bytecode). It reads the byte-code line by
line, uses data and information present in various memory area and executes
instructions. It can be classified into three parts:
Interpreter: It interprets the bytecode line by line and then executes. The
disadvantage here is that when one method is called multiple times, every time
interpretation is required.
Just-In-Time Compiler(JIT) : It is used to increase the efficiency of an
interpreter. It compiles the entire bytecode and changes it to native code so
whenever the interpreter sees repeated method calls, JIT provides direct native
code for that part so re-interpretation is not required, thus efficiency is
improved.
Garbage Collector: It destroys un-referenced objects. For more on Garbage
Collector, refer Garbage Collector.