Structures of JAVA

JAVA

Features of Java 

  • Everything is a class in Java - Java is a pure Object Oriented Language 
    • The way how Java executes in the first place(without creating an object) is by defining a static function (usually we call it main) that will run even without creating an object.  
  • A package in java is a collections of classes 
  • Java is interpreted language (compiler + interpreter) 
  • Java can run on many different operating systems without modifying the source code 
    • This is why Java is called platform independent language unlike C/C++ 
    • Java is platform independent thanks to the JVM(Java Virtual Machine) 
  • Java generates .class files (C/C++ will generate .exe files)
  • Java has garbage collection which handles automatic memory allocation and de-allocation by counting reference to an object. 
  • There are 3 interrelated components for developing and running Java programs 
    1. JVM 
    2. JRE
    3. JVM

JVM (Java Virtual Machine) 

Before moving on, let's briefly discuss how Java actually works on the programmers perspective. 
  1. Code a java source code 
  2. Compile to java byte code 
    1. For linux, you can use javac command. This command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the JVM.
    2. Note that the filename must have the same name as the public class name in that file, which is the way to tell JVM that this is an entry point. (exception on private classes) 
    3. When being compiled, the JVM searches the current directory and the JAR file containing the Java platform class files. 
  3. Run on java virtual machine 
Compiling Java source code to Java byte code

This is just an example of the most simple way to compile java code. Now let's dive into more JVM. 
So, what is the purpose of the JVM? There are 2 primary functions provided by JVM. 
  1. Allow Java programs to run on any device or operating system.
  2. Manage and optimize program memory.
When Java was first released in 1995, all computer programs were written to a specific operating system, and program memory was managed by the software developer. 
So Why is JVM is called Java Virtual Machine ?? Because JVM is an abstraction of an underlying actual machine. Regardless of what OS or hardware is actually present, the JVM creates a predictable environment for programs to run within. Unlike a true virtual machine, however, the JVM doesn't create a virtual machine OS. It would be more accurate to describe the JVM as a managed runtime environment, or a process virtual machine. 

JRE(Java Runtime Environment)

  • JRE is a software layer that runs on top of a computer's operating system and provides the class libraries and other resources that a specific Java program needs to run 
  • JRE combines Java code created using the JDK with the necessary libraries required to run it on a JVM and then creates an instance of the JVM that executes the resulting program. 
  • How JRE works ? 
    • Class Loader : The Java class loader dynamically loads all classes necessary to run a Java program. Since Java classes are only loaded into memory when they're required, the JRE uses class loader to automate this process on demand. 
    • Bytecode verifier : This ensures the format and accuracy of Java code before passing the code to interpreter. In the event that code violates system integrity of access rights, the class will be considered corrupted and won't be loaded. 
    • Interpreter : After the bytecode successfully loads, the Java interpreter creates an instance of the JVM that allows the Java program to be executed natively on the underlying machine.


JDK(Java Development Kit)

  • Set of tools for developing Java applications. 
  • Every JDK includes a compatible JRE, because running a Java program is part of the process of developing a Java program. 

JAR(Java Archive) 

  • Package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc) into one file for distribution. 
  • Includes a Java-specific manifest file and have a .jar extension. 
  • The entries in the manifest file describe how to use the JAR file. 
  • A JAR file allows Java runtime to efficiently deploy an entire application, including its classes and their associated resources, in a single request. 

REFERENCE 

Comments

Popular posts from this blog

What is URI(URN, URL)

Spring Boot JPA - Pagination

Java Data Structures VS Python, C/C++ Data Structures

Spring Boot JPA - What is JPA, Entity, Repository

Design Pattern - Proxy