Core Java · Lesson 1
Introduction to Java
Why Java Matters
Java is one of the most widely used programming languages in the world because it is powerful, portable, and reliable. It is used in enterprise systems, Android apps, backend services, and large-scale web platforms. Java follows the principle of “write once, run anywhere,” which means code can be compiled into bytecode and run on any machine with a compatible Java Virtual Machine (JVM). This makes Java a great choice for building software that needs to work across different operating systems and environments.
What Java Is and Why It Stays Relevant
Java was created to be simple, object-oriented, and secure. It introduced concepts like classes, object-oriented programming, automatic memory management, and platform independence. Even today, Java is still relevant because it powers business applications, financial systems, and many large enterprise platforms. Companies continue to trust Java for long-term, maintainable systems because of its stability, rich ecosystem, and strong tooling.
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
This simple program prints a message to the console. The public class HelloJava defines a class, and main is the starting point for the program. Every Java application begins execution from a main method.
Java Architecture: JVM, JRE, and JDK
Java has three important parts:
- JDK (Java Development Kit): includes the compiler, tools, and libraries needed to develop Java programs.
- JRE (Java Runtime Environment): contains the runtime libraries and JVM required to run Java applications.
- JVM (Java Virtual Machine): executes Java bytecode and provides platform independence.
The Java code you write is compiled into bytecode, and the JVM interprets or optimizes that bytecode for the operating system it is running on.
public class JavaRuntimeDemo {
public static void main(String[] args) {
System.out.println("Java version: " + System.getProperty("java.version"));
System.out.println("Operating system: " + System.getProperty("os.name"));
System.out.println("Java home: " + System.getProperty("java.home"));
}
}
Java Features That Make It Powerful
Java has several features that make it a strong language for real-world software development:
- Platform independence through the JVM
- Object-oriented programming with classes and objects
- Strong memory management using garbage collection
- Multi-threading support for concurrent applications
- Security features such as bytecode verification and access control
- Large ecosystem with libraries, frameworks, and tools
class Student {
private String name;
private int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public void displayInfo() {
System.out.println("Student: " + name + ", Age: " + age);
}
}
public class JavaFeaturesDemo {
public static void main(String[] args) {
Student student = new Student("Aisha", 21);
student.displayInfo();
}
}
In this example, Student is a class with state (name, age) and behavior (displayInfo). Java organizes programs around objects, which helps keep code structured and reusable.
Java Syntax and Basic Program Structure
A Java program usually contains:
- package declarations (optional)
- imports
- class definitions
- fields and methods
- a
mainmethod for execution
Java is case-sensitive, and braces {} define blocks of code. Each statement usually ends with a semicolon ;.
import java.util.Scanner;
public class BasicInputOutput {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.println("Welcome, " + name + "!");
scanner.close();
}
}
This program reads input from the user and prints a welcome message. Java makes it straightforward to handle user interaction, file input, API requests, and more with its standard library.
Java in Real-World Projects
Java is heavily used in backend services, banking systems, large enterprise applications, and distributed systems. Companies often use Java with frameworks like Spring Boot to build scalable web services. It works especially well when a project needs long-term maintainability, strong typing, and a mature ecosystem.
public class BankAccount {
private String accountNumber;
private double balance;
public BankAccount(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Deposited: " + amount);
}
}
public void printSummary() {
System.out.println("Account: " + accountNumber + " | Balance: " + balance);
}
}
public class JavaRealWorldDemo {
public static void main(String[] args) {
BankAccount account = new BankAccount("ACC-1001", 2500.0);
account.deposit(500.0);
account.printSummary();
}
}
This type of object model is common in real business systems: data is stored in objects, methods define behavior, and code stays organized around clear responsibilities.
| Java Concept | Meaning | Example |
|---|---|---|
| JDK | Tools for developing Java apps | Compiler, debugger, JAR tools |
| JRE | Runtime environment for Java apps | JVM + standard libraries |
| JVM | Executes Java bytecode | Runs .class files |
| Class | Blueprint for objects | class Student |
| Method | Block of reusable code | main(), displayInfo() |
| Object | Instance of a class | new Student(...) |
Common Mistake: Thinking Java is only for desktop apps. In reality, Java is widely used for web backends, APIs, banking systems, and cloud services. Another common mistake is ignoring the difference between JDK, JRE, and JVM. Each has a different purpose, and understanding their roles helps you configure projects correctly.
Best Practices for Learning Java
- Start with small programs and understand
main()before exploring frameworks - Learn the Java syntax and object-oriented model early
- Practice writing classes and methods instead of memorizing code patterns
- Run programs from the command line to understand the build and execution flow
- Use Java docs and compiler errors to learn from mistakes
- Build simple projects before moving into Spring Boot or enterprise patterns
Java is a strong language to learn because it teaches disciplined programming habits, object design, and scalable application architecture. Once you understand the basics, the rest of the Java ecosystem becomes much easier to navigate.
Quiz Check