31 Questions
What are the three properties of a variable in Java?
Memory location, data type, name
Which of the following is NOT a Java primitive data type?
String
What is the result of the expression $14 / 4$ in Java?
3
Which operator is used for multiplication in Java?
What is a method in Java?
A set of code which is referred to by name
What are the numeric data types in Java?
Byte, short, int, long, float, double
Which part of a method defines the access type of the method?
Modifier
What is the data type of the value returned by a method with no return value?
void
What is the purpose of a parameter in a method?
Placeholder for passed values
How would you call a method m1 from class A in another class B?
A.m1()
What is used to declare an effectively constant variable in Java?
static final
How are Java constants typically declared?
In ALL CAPS
What symbols are used to indicate comments in Java?
// and /* */
Which characters can be used in Java identifiers?
Letters, digits, underscores (_), and dollar signs ($)
What is the role of an identifier in Java?
To name variables, constants, methods, classes, and packages
Which keyword precedes package identifiers in Java?
package
Which of the following is a correct example of variable initialization in Java?
int x=5;
What is the result of the expression $20 ext{ % }3$ in Java?
2
Which of the following is a Java primitive data type?
Double
In Java, which keyword precedes package identifiers?
package
What is the role of an identifier in Java?
To name a class, method, or variable
What are the three properties of a variable in Java?
Memory location, data type, value
Which of the following is NOT a part of a method in Java?
Parameter Type
What is the role of a static variable declared with the final modifier in Java?
To make the variable globally accessible and unchangeable
How are comments indicated in Java?
By using double slashes (//)
What is the purpose of an identifier in Java?
To name variables, methods, classes, and packages
Which characters are allowed in Java identifiers?
Letters, digits, underscores (_), and dollar signs ($)
What are Java constants typically declared in?
All capital letters
What is the result of the expression $9.0 / 2$ in Java?
$4.5$
Which keyword precedes package identifiers in Java?
packageID
In Java, what does the modifier 'void' indicate for a method?
The method returns no value
Study Notes
Variables in Java
- A variable in Java has three properties: data type, variable name, and value.
- The data type determines the type of value a variable can hold.
- The variable name is a unique identifier for the variable.
- The value is the actual data stored in the variable.
Primitive Data Types in Java
- byte, short, int, long, float, double, boolean, char are the numeric and boolean primitive data types in Java.
- String is not a primitive data type in Java.
Arithmetic Operations in Java
- The / operator is used for division in Java.
- The $14 / 4$ expression in Java results in 3 (integer division).
- The $20 % 3$ expression in Java results in 2 (modulus operator).
- The $9.0 / 2$ expression in Java results in 4.5 (floating-point division).
- The * operator is used for multiplication in Java.
Methods in Java
- A method in Java is a block of code that can be called multiple times from different parts of a program.
- A method has a name, return type, parameters, and a body.
- The access type of a method is defined by the access modifier (public, private, etc.).
- A method with no return value has a return type of void.
- Parameters in a method are used to pass values to the method.
- To call a method m1 from class A in another class B, an object of class A needs to be created, and then the method can be called using the object.
Constants in Java
- An effectively constant variable in Java is declared using the final keyword.
- Java constants are typically declared using the final static keywords.
- Comments in Java are indicated using // for single-line comments and /* */ for multi-line comments.
- Java identifiers can contain letters, digits, _, and $, but cannot start with a digit.
- The role of an identifier in Java is to name a variable, method, or other programming element.
- The keyword package precedes package identifiers in Java.
Method Declaration in Java
- A method declaration in Java specifies the method's name, return type, parameters, and access type.
- The void keyword indicates that a method does not return a value.
- A static variable declared with the final modifier in Java is a constant and cannot be changed once initialized.
- Variables in Java can be initialized using the assignment operator (=).
Test your knowledge on Java variable declarations and initializations. This quiz covers the basics of storing different types of data in memory locations using variables and their identifiers.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.