0% found this document useful (0 votes)
18 views4 pages

Notes 14-01-2026

Java is a simple, object-oriented, and platform-independent programming language that emphasizes security and robustness. It supports multithreading, high performance through Just-In-Time compilation, and is portable across different architectures. The Java Virtual Machine (JVM) plays a crucial role in executing Java bytecode, ensuring that Java programs can run on any platform.

Uploaded by

inayatansari1060
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)
18 views4 pages

Notes 14-01-2026

Java is a simple, object-oriented, and platform-independent programming language that emphasizes security and robustness. It supports multithreading, high performance through Just-In-Time compilation, and is portable across different architectures. The Java Virtual Machine (JVM) plays a crucial role in executing Java bytecode, ensuring that Java programs can run on any platform.

Uploaded by

inayatansari1060
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

Main Features of Java

operator
pointers,
1. Simple C/C++ such as more
features of simpler and
removes complex
Java is easy to learn and use. It making
programs

(through classes),
overloading, and multiple inheritance and
reliable. inheritance,
polymorphism,

2. Object-Oriented encapsulation,
software.
such as maintainable
Java follows object-oriented principles modular, reusable, and Virtual
abstraction, which help in developing system
having a
Java
3. Platfornm Independent run on anyAnywhere (WORA)".
bytecode, which can
into
Java programs are compiled Once, Run
the principle "Write
TIhis supports checking, absence
of
aenine (JVM). verification, runtime
4. Secure such as bytecode applications.
security features
network-based
strong it suitable for
Java provIdes manager, making
built-in security and
pointers, and a exception handling,
management,
5. Robust memory errors.
through strong leaks and runtime
emplhasizes reliability prevent memory
Java collection, which help
automatic garbage concurrently within a single
6. Multithreaded
allowing multiple
tasks to execute
multithreading, utilization.
Java supports and efficient CPU
better performance
program, leading to (Remote Method
7. Distributed technologies such as RMI
applications using
distributed
Java supportsnetworking APIs,and web services.
Invocation), converting bytecode
performance by
8. High Performance
compilation, which improves
Just-In-Time(JIT)
Javauses at runtime.
into native machine code because the bytecode
is
9. Architecture Neutral architecture
underlying hardware
independent of the
Javaprograms are processor.
not tied to any specific behavior across
different
consistent
10. Portable standard data types and
ensures portability bydefining
Java
platforms. debugging.
11. Interpreted
JVM, allowing dynamic execution and easy
Java bytecode is interpreted by the
flexible and extensible
12. Dynamic libraries at runtime, enabling
supports dynamic loading of classes and
Java
applications.

Structure of a Java Program


order):
of the following parts (in
Java program generally consists (Optional)
A
1. Documentation Comments version, etc.
Used to describe the program, author,
prints Hello World */
/** This program
2. Package Statement (Optional) class belongs.
Specifies the package to which the
package mypackage;
3. Import Statements (Optional)
Used to include predefined or user-defined classes.
import [Link];

1
4. Interface Declarations (Optional)
Interfaces are declared before class definitions.
interface Sample {
void display ():
5. Class Definition (Mandatory)
Every Java program must have at least one class.
class MyClass {
1/ class body

6. Main Method (Mandatory for Execution)


The entry point of the program.
public static void main (String [) args) {
// program logic
}
7. Statements and Expressions
Thesecontain the actual executable code.
System. out .println ("Hello World");

Simple Example of Java Program Structure


Documentation comment
package demo;
import [Link]. *;
class Helloworld {
public static void main (String [] args) {
System. [Link] ("Hello, Java! "):
}

Java Virtual Machine (JVM)


The Java Virtual Machine (JVM) is an abstract machine that enables a computer to run Java
programs. It provides a runtime environment in which Java bytecode
is executed.
The Java Virtual Machine is a software-based engine that interprets or compiles Java bytecode
intomachine-specific instructions, allowing Java programs to run on any platform.

Role of JVM in Java


1. Java source code (.java)is compiled by the Java compiler (javac) into bytecode (. class).
2. TheJVM loads this bytecode and executes it on the host machine.
3. This makes Java platform independent.
Main Functions of JVM
1. Class Loader
Loads class files into memory when required.
2. Bytecode Verifier
Checks bytecode for security violations and ensures it follows Java standards.
3 Execution Engine
Executes bytecode using:
Interpreter
Just-In-Time (JIT) Compiler
4. Runtime Data Areas
Manages memory such as:
Method Area
o Heap

2
Stack
Program Counter Register
Native Method Stack
5. Garbage Colleetor
automatically renmoves unused objects to free memory.
Difference between JVM, JRE, and JDK
JRE (Java Runtime JDK (Java Development
Feature JVM (Java Virtual Machine) Environment) Kit)
|A complete toolkit to
Aruntime environment to
An abstract machine that develop and run Java
Definition executes Java bytecode run Java programs programs

Executes .class files Runs Java applications


|Develops, compiles, debugs,
Purpose land runs Java programs
Class loader, execution JVM + core libraries +
engine, memory areas, JRE +development tools
Contains supporting files
garbage collector
Includes XNo XNo Yes (javac)
Compiler
Includes JVM Yes |VYes Yes
Used By JVM internally End users Java developers
Platform Yes (platform-specific JVM) Yes Yes
Dependent
Can Create Java XNo |Yes
XNo
Programs
Examples of javac, java, javadoc,
Tools jar, jshell

Relationship Between JVM, JRE, and JDK


JDK D JRE D JVM
JVM runs the bytecode
JREDrovides the environment to run Java programs
JDK provides tools to develop Java programs
Java Tokens
In Java,a token is the smallest individual unit of a program. Java programs are made up of various
types of tokens, each havinga specific meaning.
Various Tokens of Java
Java tokens are broadly classified into the following categories:
1. Keywords
Keywords are reserved words that have predefined meanings. Java 21 has 53 keywords. These keywords
cannot be used as identifiers (variable names, class names, method names, etc.)
abstract assert boolean break byte
case catch char class const*

Continue default do double else


enum extends final finally float
for goto* if implements import
instanceof int interface long native
new package private protected public
return short static strictfp Super

3
switch synchronized this throw throws
transient try void volatile while
2. Identifiers
ldentifiers are names given to variables, methods, classes, interfaces, etc.
Rules for identifiers:
It is sequence of letters (A-Z or a-z), digits (0-9). .and $
Must begin with a letter (A-Z or a-z), , ors
Cannot start with a digit
Cannot be a keyword
Case-sensitive

Examples:
count. Student, totalMarks, sum
3. Literals
Literals are constant values used in a program.
Types of literals:
Integer literals: An integer literal in Java is a constant numeric value without any fractional part.
Integer literals are used to represent whole numbers in aJava program.
Types of Integer Literals: Java supports four types of integer literals, based on the number system
used:
1. Decimal (Base 10)
Uses digits 0-9
Most commonly used
No prefix
Example: 25, -67, 1089
2. Octal (Base 8)
Uses digits 0-7
Prefix: 0 (zero)
Example: 012, 017
3. Hexadecimal (Base 16)
Uses digits 0-9 and letters A-F /a-f
Prefix: 0x or 0X
Example: OxlA, 0XF2
4. Binary (Base 2) (Java 7 and later)
Uses digits 0 and |
Prefix: 0b or 0B
Example: 0b1010, OB1111
Special Features of Integer Literals
Underscores in Numeric Literals (Java 7+)
Underscores ()can be used to improve readability
Cannot be at the beginning or end, or next to prefixes
Example: I_000_000, 0b1010_1 100
Default Type
Integer literals are of type int by default
To specify long, use suffix L or l (recommended: L)
Examples: 100L, 1234567890L
Floating-point literals: A floating-point literal in Java is a numeric constant that represents a real
number, that is, a number with a fractional part or expressed in exponential (scientific) notation.
Types of Floating-Point Literals
Java supports two types of floating-point literals, based on their data type:

Common questions

Powered by AI

The Java Virtual Machine (JVM) plays a crucial role in ensuring portability of Java programs by providing a platform-independent execution environment . It interprets compiled Java bytecode into machine-specific instructions, allowing programs to run on any system having the appropriate JVM implementation, irrespective of hardware or operating system differences . This abstraction layer provided by the JVM, along with Java's use of bytecode, embodies the 'Write Once, Run Anywhere' principle, a unique advantage of Java over many other programming languages .

The absence of pointers in Java improves security by minimizing the risk of common vulnerabilities such as unauthorized memory access and buffer overflows, which are prevalent in languages like C/C++ that use explicit pointers . This lack of pointers also enhances reliability by eliminating errors that occur from pointer arithmetic, contributing to Java's robustness by reducing complex memory management issues and potential runtime errors .

Java's object-oriented principles facilitate software development by promoting modularity, reusability, and maintainability . Encapsulation hides implementation details, exposing only necessary interfaces, which simplifies component interaction and improves security. Inheritance allows for hierarchical class relationships and code reuse. Polymorphism supports interface-based programming, enabling flexibility in code behavior. Lastly, abstraction provides a means to establish a clear separation between an object's interface and its implementation, enhancing the software architecture .

Java's simplicity, achieved through the removal of complicated features like pointers, operator overloading, and multiple inheritance, makes it easier to use and reliable, which is crucial for developing stable network-based applications . Moreover, security in Java is enhanced by features like bytecode verification, absence of pointers, runtime checks, and the presence of a built-in security manager. These features ensure that Java applications are less vulnerable to malicious attacks and errors, making Java preferable for network-dependent tasks .

The Java Just-In-Time (JIT) compiler enhances performance by converting bytecode into native machine code at runtime, which is more efficient for execution by the processor . This process allows frequently executed sequences of bytecode to be compiled into a single block of code, reducing the overhead of interpretation during execution, leading to significant performance improvements especially in loops or recursive algorithms .

Underscores are used in numeric literals in Java to enhance readability by visually separating groups of digits, much like commas or spaces in other contexts . For example, writing 1_000_000 makes it clearer that the number is one million. However, underscores cannot be placed at the beginning or end of a numeral, nor adjacent to a decimal point or suffix, and they must be placed between digits . This formatting feature is particularly useful in large literals to reduce errors in reading and understanding numeric values .

Java supports various types of literals including integer literals, floating-point literals, and others . Integer literals can be based on different number systems: decimal (base 10), octal (base 8), hexadecimal (base 16), and binary (base 2). They denote whole numbers, and the type defaults to int unless specified as long with an 'L' suffix. Floating-point literals represent real numbers with fractional parts or in scientific notation and differ primarily in their data type, being either 'float' or 'double', with 'double' as the default type .

Java's multithreading capability improves application performance by allowing multiple threads to execute concurrently, which can increase CPU utilization and improve the overall throughput of applications . It enables tasks such as background data loading, service requests, and animations to be handled simultaneously without slowing down user interactions. However, challenges include potential issues with thread safety, race conditions, and deadlocks, requiring careful management of thread resources and synchronization to ensure consistent and error-free execution .

The JVM (Java Virtual Machine) is responsible for executing Java bytecode on the host machine, enabling platform independence by translating bytecode into machine instructions . The JRE (Java Runtime Environment) provides the runtime environment to run Java applications, including the JVM and core libraries . The JDK (Java Development Kit) is a complete toolkit for developing, compiling, and running Java programs, which includes the JRE as well as development tools like the compiler . JRE is used by end-users primarily to run Java programs, while the JDK is used by developers to create Java programs .

Java's platform independence is primarily supported through its use of bytecode and the JVM. Java source code is compiled into bytecode, which can be executed on any system with a JVM, regardless of the underlying hardware platform . Features contributing to this include architecture neutrality, where Java bytecode is not tied to any specific processor architecture, and platform-independent data types ensuring consistency across different environments . This enables the fundamental 'Write Once, Run Anywhere' capability that is a hallmark of Java applications .

You might also like