1: Quizzes Flashcards
What is the correct method signature for the ‘main’ method used to allow a Java class to serve as a stand-along program?
public static void main(String[] args)
When you compile a java program, what is produced?
Object code, which is also called bytecode. (.class file)
When you compile a java program, what kind of file is produced?
A .class file.
All java programming language statements must end with what?
A semicolon ;
You have just written a program that compiles and runs without showing any error messages. However, it does not produce the correct results. What kind of error do you have?
A logic error.
What is the mechanism used in the second line of code below that allows a programmer to force a potentially unsafe conversion between data types?
double size = 4.67;
int s = (int)size;
A cast
Name 10 Java keywords
public, class, static, void, boolean, char, double, else, final, float, for, if, import, int, long, new, package, private, return, short, throw, throws, while
What type of characters are used to define the beginning and end of a Java block, such as a class or method definition?
Curly braces { }
Name three important characteristics of a class name.
- For good style, it should be capitalized.
- It must match the name of the file where it is stored.
- It must be one word (no spaces).
The process of breaking a large programming task down into a series of smaller ones is called…
Procedural decomposition.
The process of breaking a large programming task down into a series of smaller ones is called…
Procedural decomposition.
What is the correct syntax for a method header with parameters?
public static int example(int x, int y) {
What is the term when you have 2 methods in a class with the same name, but different parameter lists?
Method overloading
What is the keyword used to indicate that a method returns no value?
void
What is the name of the package that contains Scanner?
java.util
When you want to call a method on an object, in other words - send the object a message - what is the proper syntax?
objectName.methodName()
Name the different data types that represent integer values (from smallest to largest).
byte, short, int, long
Name the different data types that represent floating point numbers (from smallest to largest).
float, double
Name the eight primitive data types.
byte, short, int, long, float, double, char, boolean
What is a binary operator?
Any operator that takes two operands.
What’s the name of an expression where the binary operator has two operands of different data types?
Mixed-type expression.
Even though widening is legal from type long to type float, what can happen?
Widening from type long to type float is legal, because the range of possible float values includes the range of all possible long values. However, some loss of precision is possible in such a conversion because a long value can have as many as 19 significant figures, whereas a float is limited to about 7.
Rank the primitive data types from narrowest to widest.
boolean (true/false) & byte (integer) –> char (characters) & short (integer) –> int (integer) –> long (integer) –> float (floating point numbers) –> double (floating point numbers)
“The scope of this type of variable begins with its declaration inside a method and ends at the end of the block in which it is declared.” What kind of variable is it?
Local variable