Exam Flashcards
(188 cards)
How many public classes in a .java file, and what are conditions on it and the file name.
1, and name must match with file name
When can compilation of Java code be omitted
When entire program is in one file
What is the output from compiling a java type definition?
Each type definition in a .java file is compiled to its own .class file whether public or not
What are the conditions for single file program
- All definitions in one file,
- First class much define main method
- No compiled .class file for contents
- Can’t access other compiled classes
Statement, Expression which returns a value?
Expression
What are all the syntax’s for comments
// Text
/* Text */
“””Text”””
What is the order of primitive widening conversions? How does char fit into this?
byte, short, int, long, float, double
char can be widened to int but not byte, short
What is the range of byte type
-128, 127
How is long 2L printed
2
How is float 2F printed?
2.0
In operator precedence where does equality come?
After relative >=, but before bitwise and &. Mid table
What is XOR ^ truth table
T^T = F
T^F = T
F^T = T
F^F = F
Name all 9 cases where var type is not permitted
Instance variable
Static variable
Method Parameters
Without initialisation or initialised to null
Compound declaration
Array initialisation like this a = { 1, 2, 3 }
As array element type
No self reference in initialisation
Return type
Give example of compound assignment
String s, t = “def”
(FYI, s is not initialised)
List all the valid array initialisations
int[][] a = new int[10][10]
int[] a [] = new int[3][3]
int a[][] = new int[3][3]
int[] a = new int[]{1,2,3}
int[] a = {1,2,3}
What are the 6 +/- methods on AtomicInteger
.addAndGet
.getAndAdd
.decrementAndGet
.getAndDecrement
.incrementAndGet
.getAndIncrement
What are the characteristics of the Runnable interface and Callable interface
Runnable takes no inputs and doesn’t return anything and throws no Exceptions. Callable takes no inputs but can return a value and can throw Exception
Both can throw unchecked exceptions
Are private static methods allowed in Interfaces?
Yes
What are the integer primitives and is this valid
integerPrimitiveType t = 0;
byte, short, char, int and yes the assignment is valid as they are integer primitives.
What is the result of:
Path p1 = Paths.get(“c:\a\b\c”);
p1.getName(1);
b
Drive letter is not included in path.
What is getRoot(path) on both windows and linux file systems
Windows -> c:\ (drive letter)
Linux -> /
Is this valid
Integer i = 1;
double a = i
Yes
Unboxing followed by widening conversion is allowed
https://docs.oracle.com/javase/specs/jls/se11/html/jls-5.html
Does Object class implement Comparable?
No
Collections.sort(array, null)
Does this compile and if so how does it sort
Yes and natural sorting