Java Flashcards
Which of the following are valid Java types?
short
int
byte
double
short, int, double
Which of the following are valid Java assignments?
1) boolean success = “Yes”;
2) char oneLetter = ‘a’;
3) String welcomeMessage = “Hello Stranger”;
4) float discount = 1.5;
2, 3
Which of the following Java constructs could (sensibly) be used to store 5 different string values?
1) String[] strings = new String[5];
2) Set<String> strings = new HashSet<String>();</String></String>
3) Integer string = new Integer(5);
4) List<String> strings = new LinkedList<String>();</String></String>
1, 4
Which of the following is true for a Java class?
1) May contain attributes and methods
2) Can be abstract or concrete
3) Can inherit from multiple other classes
4) Can be instantiated, which creates an object
1, 2, 4
Which of the following is true for SVN?
1) Is a distributed version control system
2) Supports only one user per server
3) Can be used via command line or through other tools
4) Is the only version control system in existence
1, 3
Which of the following are valid primitive Java types?
int
single
double
large
int, double
Which of the following are valid kinds of Java statements (covered in the lecture)?
1) If Statement: if (…) { … }
2) During Statement: during ( … ) { … }
3) Repeat-Until Statement: repeat { … } until ( … )
4) For Statement: for (… ; … ; …) { … }
1, 4
Write a for statement. Loop in range(10)
for (int i = 0; i < 10; i++) {
System.out.println(i);
}
Which of the following is true for a Java class?
1) Can contain constructors, attributes and methods
2) Must be declared static to work properly
3) Within the class, this refers (among others) to the current instance of the class
4) Can extend multiple other classes
1, 3
Which of the following is true for overloading in Java?
1) Replaces a method of a base class with a new implementation
2) Must use the Java keyword overload
3) Overloading method must define different parameters from overloaded method(s)
4) Is not supported in Java but only in languages such as C++
3
Which of the following is true for inheritance in Java?
1) Is possible only for abstract classes
2) When a class A inherits from a class B then B is called the superclass of A
3) Causes that the inheriting class has access to all attributes and methods of the superclass
4) Objects of inheriting class may be used wherever objects of the superclass are demanded
2, 3, 4
Which of the following is true for SVN?
1) Is the abbreviation for Subversion
2) Is a distributed version control system
3) Can check-out parts of projects (e.g., individual directories)
4) Is not used anymore
1, 2, 3
Which of the following is true for Git?
1) Is a distributed version control system
2) Has good support for non-linear workflows (branching and merging)
3) Can be used solely via command line
4) Has a local and a remote repository
All
Mention the primitive Java types
Boolean:
boolean
Character:
char
Integer:
byte, short, int, long
Floating-point
float (remember f after number: 1.3f). double
Primitive types have no ….?
Methods and attributes
Non-primitive java types
Enums:
enum – user defined enumeration
Arrays:
int[] – multiple values (fixed number) of same type
Collections:
List<?> – multiple values (dynamic number) of same type
Map<?,?> – dictionary
Classes:
Person – User-defined types with attributes and methods
How do you initialise an array of size 5 with integers?
Empty:
int[] myIntArray = new int[5];
With values:
int[] myIntArray = {1, 2, 3, 4, 5};
How do you initialise an arrayList of size 5 with integers?
Write an if-else statement checking if i = 3 is above 5
int i = 3;
if (i > 5) {
System.out.println(“yes above 5”);
}
else{
System.out.println(“no, below 5”);
}