0% found this document useful (0 votes)
31 views10 pages

Java Notes-1

Java is a high-level, object-oriented programming language designed for platform independence, security, and robustness, following the 'Write Once, Run Anywhere' principle. It features simplicity, portability, multithreading, and a rich set of libraries, making it suitable for various applications from web to mobile. Developed by Sun Microsystems in 1991, Java has evolved into a widely used language maintained by Oracle Corporation.

Uploaded by

aistories791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views10 pages

Java Notes-1

Java is a high-level, object-oriented programming language designed for platform independence, security, and robustness, following the 'Write Once, Run Anywhere' principle. It features simplicity, portability, multithreading, and a rich set of libraries, making it suitable for various applications from web to mobile. Developed by Sun Microsystems in 1991, Java has evolved into a widely used language maintained by Oracle Corporation.

Uploaded by

aistories791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is java?

Java is a high-level, object-oriented, general-purpose programming language designed to be


platform-independent, secure, and robust. It is widely used for building standalone, web-based,
enterprise, and mobile applications.

Java follows the philosophy:

“Write Once, Run Anywhere (WORA)”

This means a Java program compiled on one platform can run on any other platform without
modification, provided a JVM is available.

Features of Java

1) Simple:
●​ Java is very simple and easy to learn (Nursery Level) programming language.
●​ We can write Java programs very easily.
●​ To learn Java no prior knowledge is required.
●​ Most of the complex or confusing features of other languages C, C++ like Pointers etc. are
removed in Java.
2) Platform Independent:
If we write java program once, we can run on any platform. i.e Java follows Write Once Run and
Anywhere (WORA) principle.

3) Architecture-Neutral:
Java program never communicates with the platform directly. Changes and upgrades in operating systems,
processors and system resources will not force any changes in Java Programs.

4) Portable:
We can carry the java byte code to any platform without making any changes.​
(Mobile Number Portability in India)

5) Secure:
●​ Java programs never communicate directly with the machine. First converted into byte code and
then converted into machine code by the JVM.
●​ If the byte code contains any problem, then JVM won’t allow that code to run and will raise
VerifyError. Internally inside JVM, ByteCode verifier is responsible to verify the byte code.
●​ Hence Java programs won’t cause any problem to the System.

6) Object Oriented Programming Language:


●​ Java is Object Oriented Programming language like C++. Most of the times in java, we have to
handle everything in terms of Object.
●​ Java provides support for the following OOP features like​
Encapsulation, Inheritance,Polymorphism, etc

7) Multithreaded:
●​ In the case of multithreading, multiple threads can run simultaneously and can perform specified
tasks simultaneously, so that performance of the application will be improved.
●​ Java provides inbuilt support for multi threading by providing a rich API.

8) Robust:
●​ Java is strongly typed language. Compiler will check each and every declaration and assignments
at compile time only for type compatibility. If any problem wrt types, then at compile time only
we can identify the problem.
●​ Java provides Garbage Collector for automatic memory management. Hence there is no chance of
memory related problems.
●​ Java provides inbuilt Exception handling, which prevents abnormal termination of the program at
runtime.
●​ Java is platform independent and it can run on any platform.
●​ Because of all these facilities, the chance of failing the program at runtime is very very less and
Hence Java is Robust.

9) Distributed:
If the application is distributed across multiple machines (JVMs), such type of application is called
Distributed Application. Java provides inbuilt support for Distributed programming with RMI and EJB.

10) Compiled and Interpreted:


Java is both Compiled and Interpreted Programming language. First Java compiler compiles java code
and generates machine independent Byte Code. At runtime JVM interprets this byte code into machine
code and executes that machine code.

11) High Performance:


Java is relatively faster than traditional interpreted languages, since byte code is “close” to native code.
But Java is still somewhat slower than C or C++.

12) Dynamic:
In the case of Java programs, all .class files won’t be loaded at the beginning. At runtime if JVM required
any class then only the corresponding .class file will be loaded (Dynamic loading). The main advantage is
program will always get latest version of class file and memory utilization will be improved.

History of Java
1.​ Java is a high-level, object-oriented programming language developed by James Gosling and his
team at Sun Microsystems in 1991.
2.​ The development started as part of the Green Project, whose main aim was to design a
programming language for embedded systems such as televisions, set-top boxes, and electronic
devices.
3.​ Initially, the language was named Oak, inspired by an oak tree outside James Gosling’s office.
Later, the name was changed to Java due to trademark issues. Java was officially released in
1995.
4.​ The major reason behind the development of Java was the limitations of existing languages like C
and C++, which were platform dependent and complex. Java introduced the concept of Write
Once, Run Anywhere (WORA) by using bytecode and the Java Virtual Machine (JVM),
making it platform independent.
5.​ In 1998, Java was divided into three editions: J2SE, J2EE, and J2ME, which helped Java expand
into desktop, enterprise, and mobile domains. In 2010, Sun Microsystems was acquired by
Oracle Corporation, which continues to maintain and enhance Java.
6.​ Thus, Java evolved as a secure, portable, and robust programming language widely used in
modern software development.

Timeline- History of java



JDK VS JRE VS JVM

1.​ JDK
The Java Development Kit (JDK) is the central environment for creating Java
applications.
Definition and Purpose
• JDK stands for Java Development Kit.
• It is a complete software development environment used by developers to write,
compile, and debug Java programs and applets.
• It physically exists as a software package installed on a computer.
Core Composition
The JDK is a superset of the JRE (Java Runtime Environment). It can be summarized
by the following formula:
JDK=JRE+DevelopmentTools
Because it includes the JRE, the JDK allows you to both develop and run Java
applications.
3. Key Components and Tools
The JDK includes several essential tools that perform specific tasks during the
development process:
• javac (Java Compiler): Translates your human-readable Java source code (.java files)
into bytecode (.class files) that the computer can understand.
• java (Java Interpreter): The launcher that reads and executes the compiled bytecode.
• jdb (Java Debugger): A tool used to detect and remove errors (debugging) in a
program.
• javadoc: A documentation generator that automatically creates HTML-formatted
documentation from your code.
• appletviewer: Used for testing and viewing Java applets (small programs meant for
web browsers).
• javap (Java Disassembler): Translates machine code back into a human-readable
format.
4. Key Characteristics
• Platform Dependent: While Java code is platform-independent, the JDK itself is
platform-dependent. This is because each operating system (Windows, Mac, Linux)
requires its own specific version of the compiler and tools.
• Target User: It is primarily intended for Java developers rather than end-users, who
only need the JRE to run finished applications.
• Size: Because it includes a full suite of development tools and libraries, its installation
size is much larger than that of the JRE or JVM.
5. Relationship with JRE and JVM
The relationship between these three components is hierarchical:
• JDK⊃JRE⊃JVM.
• The JDK contains the JRE, which in turn contains the JVM (Java Virtual Machine).
• The JVM acts as the "engine" that executes the code, while the JRE provides the
necessary libraries, and the JDK provides the tools to create that code

2.​ JRE
The Java Runtime Environment (JRE) is the part of the Java software system
that provides the necessary tools and environment to run Java applications.
Unlike the JDK, which is for development, the JRE is intended for the end-user
who simply needs to execute compiled Java programs.
Core Components
The JRE bundles several essential pieces of software required for a program to
function:
• Java Virtual Machine (JVM): The engine that interprets and executes the
bytecode.
• Standard Class Libraries: A set of pre-written code (like [Link]) that the
JVM uses during runtime to perform standard tasks.
• Deployment Technologies: Includes tools like the Java Plug-in and Java
Web Start.
• User Interface Toolkits: Contains libraries for graphical components such as
Abstract Window Toolkit (AWT) and Swing.
• Integration Libraries: Resources like JDBC (for database connectivity) and
JNDI (for naming and directory interfaces).
Key Functions and Purpose
• Software Layer: The JRE acts as a software layer that runs on top of a
computer's operating system (OS).
• Bytecode Execution: It takes compiled .class files (bytecode) and uses the
JVM to translate them into machine-specific code so they can run on the local
hardware.
• Runtime Support: It provides all the necessary resources (libraries and files)
that a specific Java program requires to run.

3.​ JVM
The Java Virtual Machine (JVM) is the heart of the Java execution process. It is
described as an abstract machine or a software-based virtual computer that provides the
environment required to execute Java bytecode,.

Definition and Role

• Abstract Machine: It is called a "virtual" machine because it does not physically exist;
it is a specification that provides a runtime environment,.

• Role: Its primary function is to act as an intermediary between compiled Java


bytecode and the host operating system/hardware.

• Relationship: The JVM is a subset of the JRE and is bundled within both the JDK and
JRE,,.

2. Main Operations

The JVM performs four essential tasks to ensure a program runs correctly:

1. Loads code: via the Classloader.

2. Verifies code: via the Bytecode Verifier to ensure security,.

3. Executes code: via the Execution Engine.

4. Provides runtime environment: for the application to function,.

3. JVM Architecture & Components

The internal structure of the JVM is divided into several specialized subsystems:

• Classloader: This is a subsystem used to load class files. It performs three major
functions: Loading, Linking, and Initialization,.

• JVM Memory Areas:


◦ Class Area: Stores per-class structures such as the runtime constant pool, field, and
method data,.

◦ Heap: The runtime data area where all objects are allocated,.

◦ Stack: Stores "frames" and holds local variables and partial results,.

◦ Program Counter (PC) Register: Contains the address of the JVM instruction
currently being executed,.

◦ Native Method Stack: Contains all the native methods used in the application,.

• Execution Engine: This component executes the instructions. It contains:

◦ Interpreter: Reads the bytecode stream and executes instructions line-by-line,.

◦ Just-In-Time (JIT) Compiler: Improves performance by compiling parts of the


bytecode that have similar functionality into native machine code, reducing compilation time,.

• Native Method Interface (JNI): A framework that allows Java code to communicate
with applications written in other languages like C or C++,.

4. Key Management Features

• Garbage Collector: A technique that automatically manages memory by reclaiming


memory occupied by objects that are no longer in use. This relieves programmers from manual
memory management,,.

• Bytecode Verifier: Acts as a gatekeeper to ensure the code does not disturb the
interpreter or compromise system security.

• Security Manager: Java programs run inside a "sandbox," adding an extra layer of
protection against malicious code,.

5. Platform Independence vs. Dependence

• Java is platform-independent because the same bytecode can run on any system that
has a JVM installed,.

• JVM is platform-dependent, meaning it must be implemented separately for each


operating system (Windows, Mac, Linux) so it can translate universal bytecode into the specific
native machine code of that platform,.

The Execution Flow


The standard flow of code through the JVM is: Java Source (.java) → Compiler (javac)
→ Bytecode (.class) → Classloader → Bytecode Verifier → Interpreter/JIT Compiler →
Hardware
JVM Architecture

You might also like