MyMisPal
← Java lessons
Lesson 1 of 9

Your first Java program

Java is a strict, well-structured language behind banking systems, large enterprise software and Android apps, and much of ERP software such as Oracle is built with it. Many MIS programmes teach it in the first programming course.

JAVA
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, MyMisPal!");
        System.out.println(3 + 4);
    }
}
Output
Hello, MyMisPal!
7
public class MainAll Java code lives in a class, named the same as the file: Main.java
public static void mainThe entry point where execution starts
System.out.printlnPrints and moves to a new line
;Every statement ends with a semicolon
{ }Start and end of every block
Java is compiled: write Main.java, compile with javac Main.java, run with java Main. You need a JDK (for example from adoptium.net) or an IDE such as IntelliJ IDEA or VS Code.

print stays on the same line; println moves to the next one:

JAVA · inside main
System.out.print("A");
System.out.print("B");
System.out.println();
System.out.println("C");
Output
AB
C
Same idea in both languages
Python
print("Hello, MyMisPal!")
Java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, MyMisPal!");
    }
}
Spotted a mistake on this page, or have an idea to improve the site?