Introduction to Java

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");
  }
}
                
Variables and Data Types

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;
                
Methods and Scope

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+ "!");
}
                
Control Flow and Loops

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);
}
                
Classes and Objects

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;
}