and Answers with Certified Solutions
What is Java used for?
✔✔ Java is used to develop applications for web, mobile, desktop, and enterprise systems.
Why is Java called an object-oriented language?
✔✔ Java is object-oriented because it is based on objects and classes to organize code.
What does the `public static void main(String[] args)` method do?
✔✔ It serves as the entry point for Java programs where execution starts.
Can a Java file have more than one class?
✔✔ Yes, a Java file can contain multiple classes, but only one can be `public`.
What is the purpose of the `import` statement in Java?
✔✔ It allows access to Java classes from other packages.
1
,How do you print text to the console in Java?
✔✔ By using `System.out.println("Hello, world!");`.
What is a variable in Java?
✔✔ A variable is a container that holds a value in memory.
How do you declare a constant in Java?
✔✔ By using the `final` keyword before a variable.
What is the default value of an `int` in Java?
✔✔ The default value of an `int` is `0`.
How do you take user input in Java?
✔✔ By using `Scanner` with `System.in`.
What does `++` do in Java?
✔✔ It increases a variable’s value by 1.
2
,Can you run a Java program without a `main` method?
✔✔ No, unless using special cases like JavaFX or static blocks.
What is the `new` keyword used for?
✔✔ It is used to create new objects in Java.
What happens if you forget a semicolon in Java?
✔✔ The program will not compile and show a syntax error.
What is a Java `class`?
✔✔ A class is a blueprint for creating objects.
Can a `class` have more than one constructor?
✔✔ Yes, by using constructor overloading.
What does the `void` keyword mean?
✔✔ It means a method does not return a value.
3
, Can you assign a `String` to an `int` variable?
✔✔ No, because they are different data types.
What does `if` do in Java?
✔✔ It checks a condition and executes code if true.
What is the purpose of `else` in Java?
✔✔ It provides an alternative block if the `if` condition is false.
How do you create an array in Java?
✔✔ By using `int[] numbers = new int[5];`.
Can an array store different data types?
✔✔ No, an array can only store elements of the same type.
What is the purpose of a loop in Java?
✔✔ A loop repeats a block of code multiple times.
4