✔️ Correct Code :
public class Home{
public static void main (String[] args){
System.out.println("hello world");
}
}
❌ 1. Class name and file name don’t match.
public class home{}
my actual file name is Home.java, above the code class name is home.
File name must be Home.java
Otherwise you will get a compile error
OUTPUT ERROR:
❌ 2. Wrong main method syntax
public static void main (String{} args){ }
✔️ What is String[] args?
- It is an array of strings
- It stores command line arguments when the program runs
❌ 3. Missing semicolon (;)
System.out.println("hello world")
👉 You must add ;
❌ Otherwise error
OUTPUT ERROR:
❌ 4. Wrong capital letters
system.out.println("Hello");
👉 Java is case-sensitive
✔️ Correct is System
OUTPUT ERROR:
❌ 5. Missing curly braces { }
public class Home {
public static void main(String[] args) {
System.out.println("Hi");
👉 You forgot closing }
❌ This will cause an error
OUTPUT ERROR:
❌ 6. Missing quotes
System.out.println("Hello World);
👉 Strings need quotes " "
✔️ Correct: "Hello World"
OUTPUT ERROR:
❌ 7. Confusion between print and println
System.out.print("Hi");
System.out.print("Hello");
👉 Output will be on the same line
✔️ println prints on a new line
OUTPUT :







Top comments (0)