0
0
Javaprogramming~20 mins

Writing first Java program - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Java First Program Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Java program?
Look at this Java program. What will it print when run?
Java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}
AHello, Java!
Bhello, java!
CHello Java
DCompilation error
Attempts:
2 left
💡 Hint
Check the exact text inside the quotes and capitalization.
🧠 Conceptual
intermediate
1:30remaining
What is the role of the main method in a Java program?
In Java, what does the main method do?
AIt stores all the variables used in the program.
BIt automatically saves the program to a file.
CIt is the starting point where the program begins execution.
DIt defines the layout of the user interface.
Attempts:
2 left
💡 Hint
Think about what happens when you run a Java program.
🔧 Debug
advanced
2:00remaining
What error does this Java program produce?
Look at this Java code. What error will it cause when compiled?
Java
public class Test {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
ASyntax error: missing curly brace
BNo error, prints Hello World
CRuntime error: NullPointerException
DSyntax error: missing semicolon
Attempts:
2 left
💡 Hint
Check the end of the System.out.println line.
📝 Syntax
advanced
1:30remaining
Which option correctly declares the main method in Java?
Choose the correct way to write the main method header in Java.
Astatic public void main(String args)
Bpublic static void main(String[] args)
Cpublic void static main(String args[])
Dvoid public static main(String[] args)
Attempts:
2 left
💡 Hint
Remember the order and types in the method signature.
🚀 Application
expert
2:00remaining
How many lines will this Java program print?
Consider this Java program. How many lines will it print when run?
Java
public class CountLines {
    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            System.out.println("Line " + i);
        }
    }
}
A3
B4
C0
D1
Attempts:
2 left
💡 Hint
Count how many times the loop runs.