LEARN JAVA
DAY 1
BY:
CODE DETROX
What is Java?
• Java is a programming language and a platform. Java is a high level, robust,
object-oriented and secure programming language.
• Java was developed by Sun Microsystems (which is now the subsidiary of
Oracle) in the year 1995. James Gosling is known as the father of Java.
• Platform: Any hardware or software environment in which a program runs,
is known as a platform. Since Java has a runtime environment (JRE) and API,
it is called a platform.
Applications of Java
• Desktop Applications: Media player, Acrobat Reader
• Web Applications: IRCTC, Javatpoint
• Enterprise Apps: Banking systems
• Mobile Apps
• Embedded Systems
• Smart Cards
• Robotics
• Games
Features of Java
1. Simple
2. Object-Oriented
3. Platform Independent
4. Secured
5. Robust
6. Architecture-Neutral
7. Portable
8. High-Performance
9. Dstributed
[Link]
[Link]
Feature: Simple
• Easy syntax based on C++
• Removed complex features (explicit pointers, operator overloading)
• Automatic Garbage Collection → No need for manual memory
cleanup
Feature: Object-Oriented
• Everything in Java is an object
• Organizes software into objects containing data + behavior
Feature: Platform Independent
• Write Once, Run Anywhere (WORA)
• C/C++ → platform dependent machine code
• Java → bytecode runs on JVM on any system
Feature: Secure
• No explicit pointers
• Programs run inside JVM sandbox
• Prevents viruses & harmful code execution
Feature: Robust
• Strong memory management
• No pointers → prevents memory corruption
• Automatic Garbage Collection removes unused objects
Feature: Architecture Neutral
• No implementation-dependent features
• Fixed size for primitive data types
Feature: Portable
• Java bytecode can run on any platform
• No need for reimplementation
Feature: High Performance
• Bytecode is close to native machine code
• JIT compiler improves speed
Feature: Distributed
• Java supports distributed computing
• Used to build distributed applications
Feature: Multithreaded
• Thread = separate executing program
• Java can handle multiple tasks simultaneously
Feature: Dynamic
• Supports dynamic class loading (classes loaded on demand)
• Supports native methods from C/C++
First Java Program – Keywords
• class → defines a class
• public → access modifier (visible everywhere)
• static → no object needed to call method (saves memory)
• void → method returns no value
main() Method Details
• main() = program entry point
• String[] args → command-line arguments
• [Link]() → prints output
• System = class, out = PrintStream object, println() = method
What Happens at Runtime
JDK, JRE, and JVM
JVM
•JVM is an abstract virtual machine.
•Called a virtual machine because it does not physically exist.
•It is a specification, not a software.
•Provides the runtime environment to execute Java bytecode.
•Converts bytecode → machine code.
•Ensures platform independence (Write Once, Run Anywhere).
•Handles tasks like memory management, garbage collection,
security.
JRE
•JRE = Java Runtime Environment.
•A set of software tools required to run Java applications.
•Provides the runtime environment for executing Java programs.
•Contains JVM + essential libraries + class files.
•Does not contain development tools like compiler.
•Used by end-users who only run Java programs, not develop them.
JDK
•JDK = Java Development Kit.
•A software development environment for building Java apps.
•It physically exists (installable software).
•Contains JRE + development tools (compiler, debugger, jar, javadoc).
•Includes javac compiler to convert source code → bytecode.
•Required by developers to write, compile, and run Java programs.
Java Variables
• A variable is a container that stores a value during program
execution.
• A variable represents a memory location.
• Each variable must be assigned a data type.
• Types of Java variables: Local, Instance, Static.
Local Variable
• Declared inside a method, constructor, or block.
• Accessible only within its method/block.
• Other methods cannot access it.
• Cannot be declared using the static keyword.
Instance Variable
• Declared inside a class but outside any method.
• Each object has its own copy of instance variables.
• Stores object-level data.
• Not declared as static.
Static Variable
• Declared using the static keyword.
• Belongs to the class, not to objects.
• Only one copy is shared among all objects.
• Used for common/shared values (e.g., schoolName, companyName).