...
Java is a high-level, object-oriented, class-based programming language developed by Sun Microsystems and released in 1995. It’s widely used for web apps, enterprise software, mobile apps (Android), and backend systems.
Key Traits:
Platform-independent (Write Once, Run Anywhere)
Object-oriented
Secure and robust
Widely used in enterprise applications
A variable is a container for storing data values. Java is statically typed, so you must declare the type.
int age = 25;
String name = "Maya";
Data types specify the size and type of variable values.
int, float, double, char, boolean, byte, short, long
String, Array, Class, Interface, etc.
System.out.println("Hello, Ardiland!");
➕ Arithmetic: +, -, *, /, %
⚖️ Relational: ==, !=, >, <, >=, <=
🧠 Logical: &&, ||, !
🖊️ Assignment: =, +=, -=, etc.
Used to perform different actions based on conditions.
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
Loops repeat code blocks based on a condition.
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
A method is a block of code that runs when it's called. Used for code reusability.
public static void greet(String name) {
System.out.println("Hello " + name);
}
A class is a blueprint for creating objects. It defines properties and methods.
class Student {
String name;
int age;
}
An object is an instance of a class.
Student s1 = new Student();
s1.name = "Christian";
s1.age = 20;
Encapsulation – Hide data using private access
Inheritance – Child class inherits parent
Polymorphism – Many forms of the same method
Abstraction – Hide complex logic behind simple interfaces
Java handles runtime errors using try, catch, and finally blocks.
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
}
int[] numbers = {1, 2, 3, 4};
String msg = "Hello";
System.out.println(msg.length());
An interface is a contract. A class must implement all of its methods.
interface Animal {
void sound();
}
An abstract class can have both implemented and unimplemented methods.
💻 Desktop software
📱 Android development
🌐 Web backend (Spring, JSP)
🏢 Enterprise systems (banks, insurance)
🔌 Embedded systems
🚀 Big Data (Hadoop uses Java)
Q: What will be the output?
int x = 10;
System.out.println(x > 5 && x < 15);
✅ Answer: true – both conditions are satisfied.