L02: Java Fundamentals and Console Input Flashcards
What does each of these comments represent: //, /*….. /, /**……/?
Single line comment, multi-line comment, Javadoc comment.
What are the 3 restrictions to identifiers?
Can’t begin with a digit, can’t be a reserved word, limit length?
What are the allowed identifiers?
Letters, numbers, underscore (_), $.
What are the guidelines for class names, constants, and variables/methods?
Class Names; MyClass, Car
Constants: MAXIMUM, NUM_OF_WHEELS
Variables, methods: aVariable, fordCar, car_mercedes
Is “Class” a valid identifier?
Yes. The reserved word is “class” not “Class”
is “1AbC” a valid identifier?
No. Starts with a digit
What are the 4 primitive types to represent int in order of size?
byte, short, int, long.
What are the 2 ways to represent floating point numbers in order of size?
float, double.
What is a char and what is one unique property related to casting?
Stores a single character, and has a unique unicode value. This is why char can be cast to int.
What modifier does a constant variable use? What happens if this variable is modified?
final. Throws a compile-error since final variable cannot be modified.
What are variables?
Store information, creates a location in memory, must be declared before it is used (ex. int total;) If variable has no value, default value is used.
How are Java Class libraries organized?
They are organized into packages. (ex.java.text).
How do you import a class (list 2 ways)?
import java.text.DecimalFormat (import the class only)
import java.text.* (imports the entire class)
What are the 2 necessary steps to use a scanner?
import java.util.Scanner; // import class
Scanner input = new Scanner(); // Create object
When you are done reading inputs, what should be done?
Close the scanner using scanner.close()