In this lesson, we are going to explain the core Java Architecture.
Java was conceived by a team of engineers in Sun Microsystems in 1991 as a part of a research project, which was led by James Gosling and Patrick Naughton.
It was initially called Oak but was renamed as Java in 1995. This is designed to be small, simple, and portable across platforms and operating systems, both at the source and at the binary level, which means that the same Java program can run on any machine.
Features of Java
Java is an Object Oriented Language. Object-Oriented design is a technique that helps the programmer visualize the program using real-life objects.
Java is a Simple Language. The reason is, Certain complex features like operator overloading, multiple inheritance, pointers, explicit memory de allocation are not present in Java language.
Using Java we can write Robust Programs. The Two main reasons for program failure are: (1) memory management mistakes (2) mishandled run time errors.
Java has solution to these problems.
(1)With Java, Memory management is very easy since the de allocation is done by the garbage collector automatically.
(2)Java provides object oriented exception handling to manage run time errors.
Java is platform independent i.e Architecture Neutral / Portable (The idea behind it is – Write once, Run anywhere)
Java is an Interpreter based language. With Java, the program needs to be compiled only once, and the code generated by the Java compiler can run on any platform.
Java is platform independent at both the source and the binary level.
Java can be easily ported on any type of system and irrespective of the operating system being used. Java achieves this portability due to its feature of Implementation Independency.
Java is a secured programming language because it provides the user with a Virtual Firewall between the applications and the computer thus ensuring that the data in the user’s system is protected by any possible Infectious contents. This is achieved by confining the Java program within the Java Runtime Environment.
Multithreading is the capability for a program to perform several tasks simultaneously within a program. A good example of mutithreading would be one of the game software where the GUI display, sound effect, timer control and score updating are happening within the same process simultaneously. In network programming, a server can serve multiple clients at the same time via mutithreading.
Java is designed for the distributed environment of the Internet. Java allows objects on two different computers to execute procedures remotely.
Java is a language that is platform independent. A platform is the hardware and software environment in which a program runs
Once compiled, code will run on any platform without recompiling or any kind of modification. This is made possible by making use of a Java Virtual Machine commonly known as JVM.
The source code of Java will be stored in a text file with extension .java
The Java compiler compiles a .java file into byte code. Byte code is a binary language.
The byte code will be in a file with extension .class
The .class file that is generated is the machine code of this processor.
The byte code is interpreted by the JVM The byte code is interpreted by the JVM.
JVM varies from platform to platform, or, JVM is platform dependent
JVM can be considered as a processor purely implemented with software.
The interface that the JVM has to the .class file remains the same irrespective of the
under lying platform.
This makes platform independence possible.
The JVM interprets the .classfile to the machine language of the underlying platform.
The underlying platform processes the commands given by the JVM.
The JVM Runtime Environment
The byte code are stored in class files. At runtime the byte codes that make up a java software program are loaded, checked, and run in an interpreter. The interpreter has two functions: it executes bytecodes, and makes the appropriate calls to the underlying hardware.
The Java runtime environment runs code compiled for a JVM and performs four main tasks:
- Loads Code-Performed by the class loader
- Verifies Code-Performed by the byte code verifier
- Executes Code-Performed by the runtime interpreter
- Garbage Collection – De allocates memory not being used
The class loader loads all classes needed for the execution of a program. The class loader adds security by separating the namespaces for the classes of the local file system from those imported from network sources.
Once all the classes have been loaded, the memory layout of the executable file is determined. At this point specific memory addresses are assigned to symbolic references and the lookup table is created. Because memory layout occurs at runtime, the java technology interpreter adds protection against unauthorized access into the restricted areas of code.
Java software code passes several tests before actually running on your machine. The JVM puts the code through a bytecode verifier that tests the format of code fragments and checks code fragments for illegal code i.e. code that forges the pointers, violates access rights on objects, or attemptsto change object type.
The bytecode verifier makes four passes on the code in a program. It ensures that the code follows the JVM specifications and does not violate system integrity.
If the verifier completes all four passes without returning an error message, then the following is ensured.The classes follow the class file format of the JVM specification.
There are no access restriction violations.
The code causes no operand stack overflows or underflows.
No illegal data conversions
When no references to an object exist, that object is assumed to be no longer needed and the memory occupied by the object can be reclaimed. This is done by Garbage Collection. Garbage Collection occurs sporadically during the execution of the program.
When certain objects are required to perform some action when they are destroyed then those actions can be added by defining finalize()method.Java Runtime calls that method whenever it is aboutto recycle an object of that class.
The GC runs periodically, checking for objects that are no longer referenced by any running state or indirectly through other referenced objects. Right before an object is freed, the Java Run time calls the finalize() method on that object.