week01 Intro Flashcards
Explain about class in Java
class is a blueprint that defines a type, behaviour, and attribute
What is behaviour of class in Java?
what an object of a class can do
What is attribute of class in Java?
variables for an object
What does instantiate mean in Java?
to create an instance(object) of a class
Explain how Java works
.java file are compiled to .class file containing Java Bytecode. Java Bytecode is executed just-in-time by Java Virtual Machine(JVM) , then JVM interprets the Bytecode.
What letter case is used for class names in Java?
TitleCase
What letter case is used for variables and methods in Java?
camelCase
Why is Java strongly-typed?
because every ‘thing’ has a type
Expalin why Java is statically-typed
Variables in Java need a declared type, and a variable can store a single data type.
What is an identifier in other word?
a variable
What does initialization mean in Java?
to assign a value to a variable
What are the special points of primitive in Java?
- no special object created on the heap. the value is stored where it is used
- primitive can only store data within a specified range
- immutable.
What size is byte?
8 bits(integers in the range[-128, 127])
List 8 primitives
- byte
- short
- int
- long
- float
- double
- char
- boolean
What is the order of widening conversion in Java?
byte -> short -> int -> long -> float -> double
char -> int -> long -> float -> double
We may lose precision when converting from what to what? (widening)
when converting from a long to a float
What is the order of narrowing conversion in Java?
double -> float -> long -> int -> short -> byte/char
char -> byte/short
When we do narrowing conversion, range is preserved. true or false
false. range is not preserved. when widening, range is preserved.
When we do narrowing conversion, we may lose what? Answer all.
precision and magnitude
when widening, we may lose precision only.
How many operators in Java?
38
A Java variable whose data type is a primitive stores …
a value
A Java variable whose data type is a class stores …
an address
“Primitive can store null”
true or false?
false. we can’t assign null to primitive types.
we can pass null as a parameter to a method that expects an object reference.
new operator is used for what?
to instantiate a class(to create an object)
Why is String a special class?
because we can instantiate with a literal
例:
String greeting = “Hi”;
What does cross-platform distribution mean?
we can execute Java bytecode on any system as long as if you have JVM on your system