Chapter 2 - Elementary Programming Flashcards
What are “identifiers”?
Identifiers are names for naming elements such as variables, constants, methods, classes, packages in a program
What are the naming rules for identifiers?
- Can be letters, digits, underscores and dollar signs
- Must begin with letter or underscore.
- Can not be a reserved word.
What is a named constant?
A named constant represents permanent data that never changes
How is a named constant declared?
By using the keyword “final”
What are the integer types in Java?
byte, short, int, and long. Representing different sizes in ascending order
What are the floating-point types in Java?
They are float and double, representing two different presicions
How can you convert a value from one type to another?
You can do this explicitly by using the (type)value notation
What does it mean to widen a type?
Casting a variable of a type with a small range to a variable of a type with a larger range
What does it mean to narrow a type?
Casting a variable of a type with a large range to a variable of a type with a smaller range
what is “char”?
A reserved word, and a type that represents a single character
What is the UNIX epoch?
Midnight of January 1, 1970 is known as the UNIX epoch. System.currentTimeMillis() returns the number of milliseconds since the UNIX epoch
Which of the following are correct ways to declare variables? A. int length; int width; B. int length, width; C. int length; width; D. int length, int width;
A and B are correct
To improve readability and maintainability, you should declare ____ instead of using literal values such as 3.14159
Constants
Which of these data types requires the most amount of memory? A. long B. int C. short D. byte
long
If a number is too large to be stored in a variable of the float type, it \_\_\_ A. causes overflow B. causes underflow C. causes no error D. cannot happen in Java
It causes overflow