Core Java – Java Architecture Basics

Java was invented by James Gosling , and initially was called as Oak.

Oak was renamed as Java in 1995.

Goal of java was Platform Independence , it work across multiple platform like MAC,Windows,Linux etc.

Java Architecture

We can divide JVM Architecture in two environment as below :

1.Compile Time Environment

2.Runtime Environment

1.Compile Time Environment : In compile time environment Java Compiler convert java source (.java file )code to Java Byte code (.class file).

2.Runtime Environment : Runtime Environment is JVM

When we run java program , Java Byte code move to Runtime Environment , where it is loaded by class loader which is part of JVM. Class Loader load user defined classes and Java predefined inbuilt classes from local disk to memory.

ByteCode verifier , verifies bytecode and confirm that bytecode not contain harmful instruction which are harmful to JVM,now bytecode class file will get executed in Execution Engine

Execution Engine have two translator to convert java byte code to machine code :

1.Java Interpreter

2.Just In Time Compiler

java interpreter translate all single line statement into machine code and send it to processor for execution.

Just In time compiler translate and execute all looping statements and repeated method call.

Runtime System is a memory area which is divided into 5 parts :

1.Stack Area – All class code and method code stored on Stack Area .Local variable and referenced variables also stored on stack

2.Heap Area – java objects created and stored under heap area.

3.Method Area – methods get executed in method area in separate frames.

4.PC register Area – maintain address of next instruction to be executed by processor

5.Native Method Area – native method (from c,cpp) get executed here.

finally Processor send result to operating system,and OS display result on console.

Java Runtime Environment

The Java Virtual Machine (JVM) is the cornerstone of the Java platform and is responsible for executing Java bytecode. It provides a runtime environment for Java applications, offering various services such as memory management, bytecode execution, security, and garbage collection. To understand the internals of the JVM, let’s explore its key components and processes in more depth.

  1. Class Loader:
    The Class Loader subsystem is responsible for loading Java classes into memory. It takes care of locating, loading, and verifying class files. The JVM uses a hierarchical class loading mechanism, consisting of three main class loaders: Bootstrap Class Loader, Extensions Class Loader, and Application Class Loader. The class loaders work together to load classes from different sources, such as the system classpath, external libraries, and dynamically generated classes.
  2. Bytecode Verifier:
    The Bytecode Verifier ensures that the bytecode being executed is safe and adheres to the rules defined by the Java language specification. It performs static analysis on the bytecode, checking for type safety, code integrity, and other security-related constraints. The verifier ensures that the bytecode doesn’t violate any runtime safety rules before it is executed.
  3. Interpreter and Just-In-Time (JIT) Compiler:
    The JVM executes Java bytecode using an interpreter, which reads and interprets the bytecode instructions one by one. The interpreter provides platform independence by executing the bytecode on any JVM implementation. However, interpreting bytecode can be relatively slow. To improve performance, the JVM employs a Just-In-Time (JIT) compiler. The JIT compiler dynamically analyzes the bytecode at runtime, identifies frequently executed portions of code (hotspots), and compiles them into machine code specific to the underlying hardware. The compiled code is then executed directly, leading to significant performance gains.
  4. Runtime Data Areas:
    The JVM manages memory using various runtime data areas:
  • Method Area: It stores class-level structures, including method bytecode, field information, and constant pool. Each loaded class has its own representation in the Method Area.
  • Heap: The Heap is the runtime data area used for object allocation. All objects and their instance variables reside in the Heap. The JVM manages memory allocation and deallocation, and performs garbage collection to reclaim unused objects.
  • Java Stack: Each thread in the JVM has its own Java Stack, which stores method call frames. A method call frame contains local variables, method parameters, and other data related to the method’s execution. Stack frames are pushed and popped as methods are called and returned.
  • PC Register: The Program Counter (PC) Register keeps track of the current execution point in the bytecode. It stores the address of the next bytecode instruction to be executed.
  • Native Method Stack: The Native Method Stack is used to execute native (non-Java) methods. It is separate from the Java Stack and handles native method calls.
  1. Garbage Collection (GC):
    The JVM manages memory allocation and deallocation through its garbage collection mechanism. The GC automatically reclaims memory occupied by objects that are no longer referenced. It frees developers from manual memory management tasks and helps prevent memory leaks. The JVM implements different garbage collection algorithms, such as Mark-and-Sweep, Copying, and Generational GC, to efficiently manage memory usage.
  2. Security Manager:
    The Security Manager is a crucial component of the JVM’s security architecture. It enforces a set of security policies to control the behavior of Java applications. The Security Manager restricts access to system resources and protects against unauthorized actions. It ensures that Java code operates within a secure sandbox, preventing malicious actions and potential exploits.

These are the key components of the JVM and the underlying processes involved in executing Java applications. The JVM’s design and architecture enable platform independence, memory management, bytecode execution, and various optimizations to deliver efficient and secure Java program execution.

Java architecture encompasses various algorithms and data structures that are utilized in different aspects of the Java platform. Let’s explore some commonly used algorithms in Java architecture:

1.Sorting Algorithms:
Sorting algorithms are essential for ordering elements in collections or arrays. Java provides efficient sorting algorithms such as:

  • Quicksort: A divide-and-conquer algorithm that partitions the array and recursively sorts the sub-arrays.
  • Mergesort: A divide-and-conquer algorithm that divides the array into halves, recursively sorts them, and then merges the sorted halves.
  • Timsort: A hybrid sorting algorithm that combines insertion sort and mergesort techniques.

2.Hashing Algorithms:
Hashing algorithms are used for various purposes, including hash table implementations, cryptographic operations, and data integrity checks. Java provides several hashing algorithms, such as:

  • MD5 (Message Digest 5): Produces a 128-bit hash value.
  • SHA-1 (Secure Hash Algorithm 1): Produces a 160-bit hash value.
  • SHA-256 (Secure Hash Algorithm 256-bit): Produces a 256-bit hash value.

3.Encryption Algorithms:
Encryption algorithms are vital for secure communication and data protection. Java supports various encryption algorithms, including:

  • AES (Advanced Encryption Standard): A symmetric encryption algorithm widely used for securing sensitive data.
  • RSA (Rivest-Shamir-Adleman): An asymmetric encryption algorithm used for secure key exchange and digital signatures.
  • Triple DES (Data Encryption Standard): A symmetric encryption algorithm that applies the DES algorithm three times for increased security.

4.Compression Algorithms:
Compression algorithms are utilized to reduce the size of data for efficient storage and transmission. Java includes several compression algorithms, such as:

  • Deflate: A widely used compression algorithm that combines LZ77 and Huffman coding.
  • GZIP: A compression algorithm that uses Deflate with additional headers and checksums.
  • ZIP: A file compression format that combines multiple files or directories into a single archive.

5.Search Algorithms:
Search algorithms are essential for finding elements within collections or arrays. Commonly used search algorithms in Java include:

  • Binary Search: An efficient algorithm that divides the search space in half at each step, assuming the data is sorted.
  • Linear Search: A simple algorithm that checks each element in sequence until the desired element is found.

These are just a few examples of algorithms used in Java architecture. The Java platform encompasses a wide range of algorithms and data structures to support various functionalities and performance optimizations. Java’s extensive standard library provides developers with a rich set of algorithms to handle diverse programming requirements. Additionally, Java allows developers to implement custom algorithms and data structures to cater to specific needs.

Have Great Learning

Leave a Reply

Your email address will not be published. Required fields are marked *