Java is a popular, class-based, object-oriented programming language.
It is designed to have as few implementation dependencies as possible, enabling cross-platform use.
Java applications are typically compiled to bytecode and run on the Java Virtual Machine (JVM).
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
- Platform-independent via JVM
- Strongly typed
- Widely used in enterprise and Android development
Variables in Java hold data of specific types and must be declared before use.
Java supports primitive types such as int, double, and boolean, as well as reference types like objects.
String name = "Mico";
int age = 25;
double salary = 45000.00;
boolean isEmployee = true;
- int
- double
- boolean
- char
- String
Methods in Java define reusable blocks of code that perform specific tasks.
Scope determines where variables and methods can be accessed within the code.
public void greet() {
System.out.println("Welcome " +name+ "!");
}
- Public scope
- Private scope
- Protected scope
Java uses control flow statements to make decisions and repeat actions.
Loops allow execution of code blocks multiple times based on conditions.
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
- if/else
- switch
- for loop
- while loop
Classes are blueprints for creating objects, which encapsulate data and behavior.
Objects are instances of classes with their own state and methods.
Public class Person {
String name;
int age;
}
- Class properties
- Constructors
- Methods
- Inheritance