declarations_qa Flashcards

1
Q

What is an object’s state?

A

Collectively, the values assigned to an object’s instance variables make up the object’s state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the behavior of a class or an object?

A

Behavior is defined by the methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Inheritance in Java: Who knows who?

A

The superclass does not know its subclasses. The subclass knows its superclass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Encapsulation

A

A component can hide its data from other components. Thus the data can’t be updated without the component’s approval or knowledge.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What about Java’s memory management?

A

Java provides automatic memory management. It’s positive consequences: no need for pointers, less memory leaks ??

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where is Java code executed?

A

Inside a JVM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the JVM and what are its benefits?

A

It provides kind of a ‘sandbox’ environment where the Java code runs. Benefits: some security, cross-platform execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does it mean that Java is multithreaded?

A

Programs can use many operating system processes at the same time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which Java features are helpful for distributed computing?

A

Serialization: converting a Java object into a portable form.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are identifiers?

A

The names of different things: classes, interfaces, variables, methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What can identifiers start with?

A

letter, currency character ($, € etc.), a connecting character (e.g. _) NOT: digit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What can the other characters of identifiers contain?

A

letters, currency characters, connecting characters, numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Are Java identifiers case sensitive?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the naming conventions for classes?

A

noun, capitalized, if it contains multiple words: CamelCase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the naming conventions for interfaces?

A

adjective, capitalized, if it contains multiple words: CamelCase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the naming conventions for methods?

A

verb or verb-noun pair, 1st: lowercase then CamelCase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the naming conventions for variables?

A

1st: lowercase then CamelCase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Are there constants in Java?

A

There’s no such language construct, but static final variables are de facto constants.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are the naming conventions for constants?

A

all uppercase, _ as separator between words (There’re no actual constants in Java. static final variables are de facto constants.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How many classes can a source code file contain?

A

Max. 1 public and arbitrary amount of non-public

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the scope of package and import statements?

A

They apply to all classes within a source code file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which parts does a source code file contain?

A

0 or 1 package statement; 0 or more import statements; 1 or more class declarations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the rules for the name of a source code file which does not contain a public class?

A

No name match necessary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does the javac command do?

A

It compiles Java source code into .class files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does the java command do?
It invokes a JVM and launches a .class file.
26
How does the syntax of the java command look like?
java [options] class [args]
27
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
28
java.util.ArrayList How do you call this kind of name?
Fully qualified name.
29
What's the difference between Java's import and C's #include?
#include copies code. import only saves some typing. ??
30
What's the syntax for the static import?
import static
31
What is the opposite of nested class?
top-level class
32
What kind of modifiers are there?
access: public, protected, private; nonaccess: strictfp, final, abstract
33
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
34
Which access controls can be used for a class?
public default
35
What does it mean that class Dummy has access to class House?
Dummy can create an instance of House extend House access certain methods and variables within House
36
What is the Java Universe?
??
37
Which nonaccess modifiers can you not use together?
abstract, final
38
Where can you use the strictfp modifier?
class, method
39
What is a final class?
a class which can not be subclassed
40
Where do you encounter final classes?
in own code: rarely; in the Java core libraries: more often (e.g. String)
41
Can you compile and execute an abstract class?
Yes. If it has a main method with the according signature, it will be executed.
42
What kind of methods can an abstract class have?
abstract, non-abstract, static
43
Can you have an abstract method in a concrete class?
no
44
In which package does a class without a package declaration belong?
The default package.
45
What are the default modifiers for an interface?
abstract
46
What is the default access control for an interface?
default
47
public abstract interface Rollable; public interface Rollable What's the difference?
Nothing
48
What are the default modifiers for an interface method?
public abstract
49
What is the default access control for an interface method?
public
50
What are the possible access controls for an interface method?
public default
51
What are the implicit modifiers for a constant in an interface?
public static final
52
interface Foo { int BAR=42; } class Dummy implements Foo { } How can you reference BAR in Dummy?
BAR
53
What is the access control for default interface methods?
public
54
Can a default interface method be final?
no
55
What's the access control for static interface methods?
public
56
Can a static interface method be final?
no
57
Can you declare a static interface method without a method body?
no
58
Can you invoke a static interface method without the method's type?
no
59
What are members?
methods and instance variables
60
Which access control levels can a member have?
all 4
61
Which meanings does 'default' have?
The 'default' access control level. A default interface method.
62
What does the reference `this` refer to?
The currently executing object. The object running the code where you see the `this` reference.
63
Can you override a private method?
no
64
Can a protected member be accessed outside the package?
Yes, in the subclasses
65
What can a subclass outside the package do with a protected member?
It can see it only through inheritance
66
Can access modifiers be applied to local variables?
no
67
Which modifiers can be applied to local variables?
only `final`
68
Method arguments are esentially the same as ...
local variables
69
What is an abstract method?
A method that has been declared but not implemented.
70
Who has to implement an abstract method?
The first concrete superclass of the abstract class.
71
What is the opposite of an abstract class?
concrete
72
Which access modifier can't be used with `final`?
private
73
What is an overloaded method?
a method using the same identifier but different arguments
74
What does the synchronized keyword mean?
A method can be accessed only by one thread at a time. The keyword can be applied only to methods.
75
Which access control level can be matched with synchronized?
all
76
Where can you apply the native modifier?
only for methods
77
How many var-arg parameters can you have in a method?
only 1. This must be in the last position of the parameter list
78
What happens if you make a new object?
At lest one constructor is invoked. The instance variables are initialized.s
79
What are the differences between constructors and methods?
No return value. Can not be overridden. No static, related to overriding: final, abstract
80
What types of variables are there in Java?
primitive (at the end of the day always a numeric value) reference variables
81
What are the primitive types in Java?
char boolean integer types in order: byte, short, int, long float, double
82
What does it mean that a numeric type is signed?
Its value can be positive or negative.
83
Can an instance variable be marked static?
No. In that case it would become static.
84
Which modifiers can you use for instance variables?
access level; final transient
85
volatile
A modifier. It can be applied only to variables.
86
transient
A modifier used only for instance variables. transient instance variables are ignored at serialization.