JAVA questions
What is a class?
A class is a blueprint or prototype from which objects are created.
What is a package?
A package is a namespace for organizing classes and interfaces in a logical manner. Placing your code into packages makes large software projects easier to manage.
What is an interface?
An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface.
What is an object?
An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.
An ___ is a container object that holds a fixed number of values of a single type.
Array.
Statements may be grouped into ___.
Blocks.
A block is a group of zero or more statements between balanced ___ and can be used anywhere a single statement is allowed.
Braces.
When you compile a program written in the Java programming language, the compiler converts the human-readable source file into platform-independent code that a Java Virtual Machine can understand. What is this platform-independent code called?
Bytecode.
What is the first thing you should check if you see the following error at runtime: Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp.java.
Check your classpath. Your class cannot be found.
The following code snippet is an example of a ___. 1 * 2 * 3
Compound expression.
Operators may be used in building ___, which compute values.
Expressions.
What is data encapsulation?
Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation — a fundamental principle of object-oriented programming.
What is inheritance?
Inheritance provides a powerful and natural mechanism for organizing and structuring your software.
A local variable stores temporary state; it is declared inside a ___.
Method.
The term "instance variable" is another name for ___.
Non-static field.
A variable declared within the opening and closing parenthesis of a method is called a ___.
Parameter.
Statements are roughly equivalent to sentences in natural languages, but instead of ending with a period, a statement ends with a ___.
Semicolon.
Expressions are the core components of ___.
Statements.
The term "class variable" is another name for ___.
Static field.
What is the correct signature of the main method?
The correct signature is public static void main(String[] args) or public static void main(String... args)
What parameters does the main method define?
The main method defines a single parameter, usually named args, whose type is an array of String objects.
What are the eight primitive data types supported by the Java programming language?
They are: byte, short, int, long, float, double, boolean, char.
When declaring the main method, which modifier must come first, public or static?
They can be in either order, but the convention is public static.
The program has an error that needs to be fixed so that the program successfully compiles and runs. What is the error? class HelloWorldApp2 { public static void main(String[] args) { System.out.println("Hello World!); // Display the string. } }
To fix the mistake, you need to close the quotation marks around the string. Here is the correct line of code: System.out.println("Hello World!"); //Display the string.
What is a "method signature"?
Two of the components of a method declaration comprise the method signature—the method's name and the parameter types. public double calculateAnswer(double wingSpan, int numberOfEngines, double length, double grossTons) { //do the calculation here } The signature of the method above is: calculateAnswer(double, int, double, double)
Which of the following is not a valid comment: a. /** comment */ b. /* comment */ c. /* comment d. // comment
c is an invalid comment.
Character strings are represented by the class ___.
java.lang.String