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
Q

What does the java command do?

A

It invokes a JVM and launches a .class file.

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

How does the syntax of the java command look like?

A

java [options] class [args]

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

What is the signature of the method which the JVM starts?

A

public static void main(String[] args) The String array can have another name, can be declared using var-args syntax

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

java.util.ArrayList How do you call this kind of name?

A

Fully qualified name.

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

What’s the difference between Java’s import and C’s #include?

A

include copies code. import only saves some typing. ??

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

What’s the syntax for the static import?

A

import static

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

What is the opposite of nested class?

A

top-level class

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

What kind of modifiers are there?

A

access: public, protected, private; nonaccess: strictfp, final, abstract

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

How many access controls and access modifiers are there in Java?

A

3 access modifiers, 4 access controls (levels of access) public protected private + default or package

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

Which access controls can be used for a class?

A

public default

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

What does it mean that class Dummy has access to class House?

A

Dummy can create an instance of House extend House access certain methods and variables within House

36
Q

What is the Java Universe?

A

??

37
Q

Which nonaccess modifiers can you not use together?

A

abstract, final

38
Q

Where can you use the strictfp modifier?

A

class, method

39
Q

What is a final class?

A

a class which can not be subclassed

40
Q

Where do you encounter final classes?

A

in own code: rarely; in the Java core libraries: more often (e.g. String)

41
Q

Can you compile and execute an abstract class?

A

Yes. If it has a main method with the according signature, it will be executed.

42
Q

What kind of methods can an abstract class have?

A

abstract, non-abstract, static

43
Q

Can you have an abstract method in a concrete class?

A

no

44
Q

In which package does a class without a package declaration belong?

A

The default package.

45
Q

What are the default modifiers for an interface?

A

abstract

46
Q

What is the default access control for an interface?

A

default

47
Q

public abstract interface Rollable; public interface Rollable What’s the difference?

A

Nothing

48
Q

What are the default modifiers for an interface method?

A

public abstract

49
Q

What is the default access control for an interface method?

A

public

50
Q

What are the possible access controls for an interface method?

A

public default

51
Q

What are the implicit modifiers for a constant in an interface?

A

public static final

52
Q

interface Foo { int BAR=42; } class Dummy implements Foo { } How can you reference BAR in Dummy?

A

BAR

53
Q

What is the access control for default interface methods?

A

public

54
Q

Can a default interface method be final?

A

no

55
Q

What’s the access control for static interface methods?

A

public

56
Q

Can a static interface method be final?

A

no

57
Q

Can you declare a static interface method without a method body?

A

no

58
Q

Can you invoke a static interface method without the method’s type?

A

no

59
Q

What are members?

A

methods and instance variables

60
Q

Which access control levels can a member have?

A

all 4

61
Q

Which meanings does ‘default’ have?

A

The ‘default’ access control level. A default interface method.

62
Q

What does the reference this refer to?

A

The currently executing object. The object running the code where you see the this reference.

63
Q

Can you override a private method?

A

no

64
Q

Can a protected member be accessed outside the package?

A

Yes, in the subclasses

65
Q

What can a subclass outside the package do with a protected member?

A

It can see it only through inheritance

66
Q

Can access modifiers be applied to local variables?

A

no

67
Q

Which modifiers can be applied to local variables?

A

only final

68
Q

Method arguments are esentially the same as …

A

local variables

69
Q

What is an abstract method?

A

A method that has been declared but not implemented.

70
Q

Who has to implement an abstract method?

A

The first concrete superclass of the abstract class.

71
Q

What is the opposite of an abstract class?

A

concrete

72
Q

Which access modifier can’t be used with final?

A

private

73
Q

What is an overloaded method?

A

a method using the same identifier but different arguments

74
Q

What does the synchronized keyword mean?

A

A method can be accessed only by one thread at a time. The keyword can be applied only to methods.

75
Q

Which access control level can be matched with synchronized?

A

all

76
Q

Where can you apply the native modifier?

A

only for methods

77
Q

How many var-arg parameters can you have in a method?

A

only 1. This must be in the last position of the parameter list

78
Q

What happens if you make a new object?

A

At lest one constructor is invoked. The instance variables are initialized.s

79
Q

What are the differences between constructors and methods?

A

No return value. Can not be overridden. No static, related to overriding: final, abstract

80
Q

What types of variables are there in Java?

A

primitive (at the end of the day always a numeric value) reference variables

81
Q

What are the primitive types in Java?

A

char boolean integer types in order: byte, short, int, long float, double

82
Q

What does it mean that a numeric type is signed?

A

Its value can be positive or negative.

83
Q

Can an instance variable be marked static?

A

No. In that case it would become static.

84
Q

Which modifiers can you use for instance variables?

A

access level; final transient

85
Q

volatile

A

A modifier. It can be applied only to variables.

86
Q

transient

A

A modifier used only for instance variables. transient instance variables are ignored at serialization.