Java Features and Basics
Features of Java
Platform Independent: Java programs are compiled into bytecode, which can run on any
system with a Java Virtual Machine (JVM).
Object-Oriented: Java is based on Object-Oriented Programming principles, which
include encapsulation, inheritance, and polymorphism.
Simple and Easy to Learn: Java has a clear and straightforward syntax, making it
beginner-friendly.
Secure: Java provides a secure environment by eliminating pointer-related issues and
having built-in security features.
Robust: Java includes strong memory management and exception handling capabilities.
Multithreaded: It allows the execution of multiple threads simultaneously, improving
performance.
High Performance: Though not as fast as C++, Java’s Just-In-Time (JIT) compiler ensures
good performance.
Distributed: Java supports distributed computing through technologies like RMI and
EJB.
Dynamic: Java programs can dynamically load classes and support runtime data
modification.
What is Object-Oriented Programming?
Object-Oriented Programming (OOP) is a programming paradigm that organizes code into
objects, which contain both data (fields) and behaviors (methods). The main principles of
OOP are:
Encapsulation: Bundling data and methods together, restricting direct access to some
components.
Inheritance: Allowing one class to inherit the properties and methods of another.
Polymorphism: Enabling a single interface to represent different types.
Abstraction: Hiding the complex implementation details and showing only the essential
features of an object.
What is a Java Compiler?
The Java Compiler (javac) is a program that converts Java source code (written in .java files)
into bytecode (stored in .class files). This bytecode is platform-independent and can be
executed by the JVM.
What is Bytecode?
Bytecode is the intermediate code generated by the Java compiler. It is a low-level,
platform-independent set of instructions that the JVM interprets and executes. Bytecode
ensures that Java programs can run on any device with a JVM, making Java platform-
independent.
What is JVM?
The Java Virtual Machine (JVM) is a runtime environment that executes Java bytecode. It
provides platform independence by translating bytecode into machine-specific instructions.
The JVM also includes features like:
Classloader: Loads classes into memory.
Bytecode Verifier: Checks the validity and security of bytecode.
Execution Engine: Converts bytecode into machine code and executes it.
What is a Source Program?
A source program is the original Java code written by a programmer in .java files. This code
is human-readable and needs to be compiled into bytecode by the Java compiler before
execution.
All Data Types in Java
Java has two categories of data types:
1. Primitive Data Types
byte: 1 byte, stores whole numbers from -128 to 127.
short: 2 bytes, stores whole numbers from -32,768 to 32,767.
int: 4 bytes, stores whole numbers from -2³¹ to 2³¹-1.
long: 8 bytes, stores large whole numbers from -2⁶³ to 2⁶³-1.
float: 4 bytes, stores fractional numbers up to 7 decimal digits.
double: 8 bytes, stores fractional numbers up to 15 decimal digits.
char: 2 bytes, stores a single 16-bit Unicode character.
boolean: 1 bit, stores either true or false.
2. Non-Primitive Data Types
String
Arrays
Classes
Interfaces
Enums