declarations_qa Flashcards
What is an object’s state?
Collectively, the values assigned to an object’s instance variables make up the object’s state.
What is the behavior of a class or an object?
Behavior is defined by the methods.
Inheritance in Java: Who knows who?
The superclass does not know its subclasses. The subclass knows its superclass
Encapsulation
A component can hide its data from other components. Thus the data can’t be updated without the component’s approval or knowledge.
What about Java’s memory management?
Java provides automatic memory management. It’s positive consequences: no need for pointers, less memory leaks ??
Where is Java code executed?
Inside a JVM.
What is the JVM and what are its benefits?
It provides kind of a ‘sandbox’ environment where the Java code runs. Benefits: some security, cross-platform execution
What does it mean that Java is multithreaded?
Programs can use many operating system processes at the same time.
Which Java features are helpful for distributed computing?
Serialization: converting a Java object into a portable form.
What are identifiers?
The names of different things: classes, interfaces, variables, methods.
What can identifiers start with?
letter, currency character ($, € etc.), a connecting character (e.g. _) NOT: digit
What can the other characters of identifiers contain?
letters, currency characters, connecting characters, numbers
Are Java identifiers case sensitive?
yes
What are the naming conventions for classes?
noun, capitalized, if it contains multiple words: CamelCase
What are the naming conventions for interfaces?
adjective, capitalized, if it contains multiple words: CamelCase
What are the naming conventions for methods?
verb or verb-noun pair, 1st: lowercase then CamelCase
What are the naming conventions for variables?
1st: lowercase then CamelCase
Are there constants in Java?
There’s no such language construct, but static final variables are de facto constants.
What are the naming conventions for constants?
all uppercase, _ as separator between words (There’re no actual constants in Java. static final variables are de facto constants.)
How many classes can a source code file contain?
Max. 1 public and arbitrary amount of non-public
What is the scope of package and import statements?
They apply to all classes within a source code file.
Which parts does a source code file contain?
0 or 1 package statement; 0 or more import statements; 1 or more class declarations
What are the rules for the name of a source code file which does not contain a public class?
No name match necessary.
What does the javac command do?
It compiles Java source code into .class files.
What does the java command do?
It invokes a JVM and launches a .class file.
How does the syntax of the java command look like?
java [options] class [args]
What is the signature of the method which the JVM starts?
public static void main(String[] args) The String array can have another name, can be declared using var-args syntax
java.util.ArrayList How do you call this kind of name?
Fully qualified name.
What’s the difference between Java’s import and C’s #include?
include copies code. import only saves some typing. ??
What’s the syntax for the static import?
import static
What is the opposite of nested class?
top-level class
What kind of modifiers are there?
access: public, protected, private; nonaccess: strictfp, final, abstract
How many access controls and access modifiers are there in Java?
3 access modifiers, 4 access controls (levels of access) public protected private + default or package
Which access controls can be used for a class?
public default