Ticker

6/recent/ticker-posts

Header Ads Widget

Introduction to Java architecture


INTRODUCTION TO JAVA ARCHITECTURE

    Java is a programming language which is an object-oriented programming language as a base for the whole language.

    It can be used in various domains such as web development, software development, mobile development, and all domains in computer science degrees.

    How Java code gets executed:

    Java file (human readable form --> .class file (byte code) ---> machine code (0&1)

    Java file is firstly converted into .class file using javac compiler which is done for the whole program in one go and using that .class file is converted to machine code which is done by interpreter line by line.

    More about platform-independent:

    • It means that byte code can run all operating systems. 
    • We need to convert source code to machine code so the computer can understand. 
    • The computer helps in doing this by turning it into executable code. 
    • This executable code is a set of instructions for the computer. 
    • After compilation c/c++ code will generate executable files like .exe, .sh which is platform dependent. 
    • In java, we get byte code; JVM converts this byte code to machine code. 
    • Java is platform-independent, but JVM is platform dependent. 
    • Executable code is the one that runs programs and software applications. 

    JDK vs JRE vs JVM vs JIT

    • JDK consists of JRE and a development kit. 
    • JRE consists of JVM and library classes. 
    • JVM consists of JIT. 

    JDK:

    • JDK provides an environment to develop and run the java program. 
    • It is a package that includes:
      • Development tools - to provide the environment to develop your program. 
      • JRE- to execute your program. 
      • A compiler - javac: c language-based
      • Archiver - jar
      • Doc's generator - Javadoc
      • Interpreter /to order

    JRE:

    • JRE is an installation package that provides an environment to only run the program
    • JRE consists of
      • Deployment technologies
      •  User interface toolkits
      • Integration libraries
      • Base Libraries
      • JVM
    • After getting the .class file, the next thing happens at runtime.
      • Class loads all the classes needed to execute the program.
      • JVM sends code to a byte code verifier to check the code format.

    COMPILE-TIME:

    JAVA FILE ---> CLASS FILE (JVM EXECUTION)
    With the help of the javac compiler.

    JIT:

    • Those methods are repeated.
    • JIT provides direct machine code so that re-interpretation of the program is not necessary.
    • Make execution faster.
    • Garbage collector.

    INTERPRETER:

    • Lines by line execution.
    • When one method is called many times, it will interpret repeatedly.

    Runtime:

    Class loader--> byte code verifier ---> interpreter ---> runtime ---> hardware


    How JVM works class loader:

    • Loading:

      • Reads .class file and generates binary data
      •  An object of this class is created in the heap

    • Linking:

      •  JVM verifies the .class file.
      •  Allocate memory for class variables and data types.
      •  Replace symbolic reference from the type with direct reflection.

    • Initialization:

      •  All static variables are assigned with their values.
      • Defined in the code and static block.
    JVM consists of stack and heap memory allocation.

    Working on Java architecture:

    Java source code ---> JDK ---> BYTE CODE ---> JVM, HARDWARE ---> JRE

    I hope that you have gained some new knowledge about how Java architecture works internally and how each component depends on the execution of the program for converting readable code into machine code.

    Post a Comment

    0 Comments