0
0
Javaprogramming~20 mins

What is Java - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Java Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
What is Java primarily used for?

Java is a popular programming language. What is its main use?

ACreating mobile apps, web applications, and large systems
BOnly for designing websites with HTML and CSS
CWriting scripts to automate Excel spreadsheets
DBuilding hardware devices and microchips
Attempts:
2 left
💡 Hint

Think about where you see Java programs running, like apps or websites.

Predict Output
intermediate
1:30remaining
What is the output of this Java code?

Look at this Java program and choose the output it produces when run.

Java
public class Main {
    public static void main(String[] args) {
        int x = 5;
        int y = 10;
        System.out.println("Sum is: " + (x + y));
    }
}
ASum is: 15
BSum is: 510
CSum is: x + y
DSum is: 5 + 10
Attempts:
2 left
💡 Hint

Remember that parentheses change how expressions are calculated in Java.

Predict Output
advanced
1:30remaining
What does this Java code print?

Analyze the code and select the exact output it produces.

Java
public class Main {
    public static void main(String[] args) {
        String s = "Java";
        s += 123;
        System.out.println(s);
    }
}
AJava 123
BJava123
CJava+123
DError: cannot add int to String
Attempts:
2 left
💡 Hint

In Java, adding a number to a string converts the number to text.

🔧 Debug
advanced
1:30remaining
What error does this Java code cause?

Look at this Java code and choose the error it produces when compiled.

Java
public class Main {
    public static void main(String[] args) {
        int number = "100";
        System.out.println(number);
    }
}
ASyntax error: missing semicolon
BVariable number might not have been initialized
CType mismatch: cannot convert from String to int
DNo error, prints 100
Attempts:
2 left
💡 Hint

Check the type of the value assigned to an int variable.

🧠 Conceptual
expert
2:00remaining
Which feature makes Java platform-independent?

Java is called platform-independent. What feature allows this?

AJava programs must be rewritten for each operating system
BJava programs are written in machine code for each platform
CJava uses HTML to run in browsers
DJava Virtual Machine (JVM) that runs bytecode on any device
Attempts:
2 left
💡 Hint

Think about how Java runs the same program on different computers without changes.