There are 8 primitive types... name all of them.
____ are objects but not a primitive type.
int, double, short, long, float, byte, boolean, char
Strings
Arrays use .length() to provide the length of the Array.
ArrayLists have a dynamic size. Differing from Arrays, ArrayLists use _____ to return the number of elements in the list
.size()
what is not included in the signature of a method?
what is?
not included: scope, return type, and throws declarations
what is included in a signature: name & parameter(s) size, order, and type
___ are dependent on either implementing the Runnable Interface of extending _____
Threads in Java
what is the maximum number of references each node can have ?
2
what is the range that defines the minimum and maximum decimal value of an unsigned 8-bit binary number? What about 4 - bit?
What is the result of 7 | 35?
0-255
0-15
39
What will be the output of the following Java code?
class array_output
{
public static void main(String args[])
{
int array_variable [] = new int[10];
for (int i = 0; i < 10; ++i)
{
array_variable[i] = i;
System.out.print(array_variable[i] + " ");
i++;
}
}
}
a) 0 2 4 6 8
b) 1 3 5 7 9
c) 0 1 2 3 4 5 6 7 8 9
d) 1 2 3 4 5 6 7 8 9 10
A.
Explanation: When an array is declared using new operator then all of its elements are initialized to 0 automatically. for loop body is executed 5 times as whenever controls comes in the loop i value is incremented twice, first by i++ in body of loop then by ++i in increment condition of for loop.
describe the difference of the modifiers
static vs final
what are the access modifiers?
static: makes method accessible without object declaration (on a class level)
final: makes methods or fields nonmodifiable; cannot change once instantiated
access modifiers: public (any class can access)
protected (only within class, subclasses, or package
private (only within class)
[none]: defaults to package - private
List whether the following are property of AWT or Swing for GUIs
1. components are platform dependent
2. Components are lightweight
3. Doesn't supports pluggable look and feel
4. Follows MVC (Model - View- Controller)
1. AWT
2. Swing
3. AWT
4. Swing
lets say Car.java, Bicycle.java, and Boat.java are all classes that extend the Vehicle object.
If you create an Array that stores {Car, Bicycle, Boat}, what data type would you set the variable to?
_____ racers = {Car, Bicycle, Boat}
Vehicle []
when do you use while() loops vs do-while() loops?
What about for loops vs for-each() loops (enhanced for loops)?
while()
- the while loop executes only if the condition is satisfied upon entry and continues to execute until the condition become false
do-while()
- executes at least one
- condition checked at end of loop
(use when you know condition needs to be executed at least once)
for()
- repeats given number of iterations
- can increment / decrement index variable
for-each()
- iterates over a set of data
- best for handling large data sets with unknown sizes
There are 3 I/O levels:
1. Low-level : raw data (byte - oriented)
2. High-Level: Primitive Types
3. Object- level:
In the Object-level, Serializable is needed / implemented. What does that mean?
Serialization is taking an object and saving it as a byte stream in a file.
can be saved as a .ser
what is the difference between a getter and a setter?
getter is an accessor, setter is a mutator
t.yield() pauses thread execution.
t.sleep() pauses the thread too but for how long?
an amount of milliseconds
can an abstract class be instantiated?
no, but they can have a subclass
7. What will be the output of the following Java code?
class average {
public static void main(String args[])
{
double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
double result;
result = 0;
for (int i = 0; i < 6; ++i)
result = result + num[i];
System.out.print(result/6);
}
}
a) 16.34
b) 16.566666644
c) 16.46666666666667
d) 16.46666666666666
C
Hashmaps / Associative Arrays
Initialization is similar to array list:
HashMap<___, ___> map = new HashMap<>()
What goes inside of the initial <> ?
KeyType, ValueType
you can use
map.put("key", 1); to insert into a map
Inheritance is the concept of having properties in a class that has defined methods.
Although similar, how does this differ from interfaces?
Inheritance consists of a chain of parents that don't require the subclasses to define the methods.
can extend only one class
if extending, first line must be super() (to call superclass constructor)
what is printed out?
public class Recursion{
psvm {
sayHi();
}
public void sayHi() {
System.out.println("Hi");
sayHi()
}
If you want this program to print "Hi" 3 times would would you fix this?
Stack Overflow error
method keeps getting called over and over again by itself, and theres nothing that stops it.
It gets stacks so much that there is not enough memory to hold all of it, so it causes an error
psvm {
sayHi(3);
}
private static void sayHi (int count) {
System.out.println("Hi");
if (count <= 1) {
return;
}
sayHi(count - 1) ;
}
}
this added parameter makes sure there is a condition set to stop the recursive call after the count = 1 starting at 3
what do LIFO and FIFO stand for? Which one represents (Reverse Polish Notation) RPN?
How does RPN function?
LIFO - last in first out
FIFO - first in first out (Queues)
RPN is LIFO (stack)
- processes space - separated numbers & operators using a stack. If you see a number you push it into the stack (push())
String s = "134"
Integer.parseInt(s)
System.out.println(s / 2 * 3)
What is the output that is printed?
201
Parsing the String as an integer and then performing int operations on it.
Match the following.
1. FileOutputStream 2. DataOutputStream
3. getOutputStream 4. printStream
a. writes primitive data types to file b. writes binary data, for writing raw bytes of data to a file,good for images c. converts primitive data (char, int) to text format instead of bytes d. sending data related to network communication from client to server (sockets, URL connection, etc..)
1. b.
2. a.
3. d
4. c
"Hello, World" instanceOf Object
what would this return?
String is a subclass of Object so it would return a boolean true
In order to connect and communicate over network, a Socket object must be created given what two conditions?
IP address and port #
port number is a 16-bit unsigned integer (<65536)
Describe the 3 properties that are followed by Binary Search Trees.
Can leaf nodes be considered its own binary search tree?
1. Key in left child or root smaller than root 2. key in right child of root is larger than root 3. each child is also a binary tree.
A leaf node can be considered a binary tree because it in order to check if it has children, it needs to create an empty array, which is inherently sorted. So it would technically still be a tree, just with no children.