JAVA Milestone
How would we represent a logical AND?
&&
What is a Java Subclass?
A Java subclass is a class which inherits a method(s) by extending the superclass.
With respect to Java, what does it mean for an object to be immutable?
Cannot change the value of the object in memory
Objects are made from?
Class constructors
What is autoboxing
Converting a primitive value (an int, for example) into an object of the corresponding wrapper class (Integer).
What is unboxing
Converting an object of a wrapper type (Integer) to its corresponding primitive (int) value.
Explain declaration, instantiation, and initialization
Declaration: Associates a variable name with a datatype. int Boolean fileExist = false; Instantiation: A new object is created using the "new" keyword. [Animal animal = new Animal();] Initialization: Occurs when the new operator is followed by a constructor which sets default values on the object. [Animal animal = new Animal("Cat");]
What is encapsulation?
Encapsulation means that fields/members can only be accessed from their owning class or by adding public methods to the class called getters and setters.
T or F: Methods can only be called from an instance of the class
False
T or F: Primitives can be set to null
False
T or F: The following are immutable: String, BigInteger, ArrayList, BigDecimal
False
T or F: We can use breaks inside of a stand-alone "if" block
False
What is a JVM
JVM: is Oracle's Java Virtual Machine The JVM is a program whose purpose is to execute other programs.
What is Java
Java is an object-oriented programming language developed by Sun Microsystems. Modeled after C++, the Java language was designed to be small, simple, and portable across platforms and operating systems, both at the source and at the binary level.
Objects can be as large as _________?
Java's heap size
What is method overloading?
Method overloading is having multiple methods with the same signature but different number and/or type of parameters.
All objects extends what superclass
Object (java.lang.Object)
What is the difference between Java Objects and Java Classes?
Objects: Objects have states and behaviors. Classes: A class is a template/blueprint that describes the behaviors/state that the objet of its type supports.
What three accessibility modifiers are available for a Java class?
Public, Abstract, Final
What is the main difference between stack and heap memory?
Stack memory is used to store local variables and function call while heap is used to store objects in Java. Threads in Java have their own stack (managed by -Xss).
How do we perform a simple String concatenation (without using an object)?
String c = a + b;
What two classes can be used to construct?
StringBuilder, StringBuffer
What is the difference between StringBuilder and StringBuffer?
StringBuilder: Faster and not synchronized. StringBuffer: Slower but thread safe (synchronized)
If we create new Bean foo, add a constructor, some field, and getters/setters and instantiate two instances of the bean and add them to an ArrayList. What happens when we sort the list with Collections.sort(<list>)?
The code will not compile since the bean does not implement comparable/operator.
What happens when we execute a "continue" command while in a loop?
The current iteration stops processes and program control resumes on the current for loop.
T or F: Primitives can be converted to objects
True
T or F: When we break on the inside of a nested for loop, only the inside for loop stops processing?
True
What are the components of a method?
a. Modifiers, return type, method name, parameters, exceptions, body
What is Java heap?
a. The heap is the runtime data area from which memory for all class instances and arrays is allocated. b. The heap is created on virtual machine start-up. c. Heap storage for objects is reclaimed by an automatic storage management system (known as the collector); objects are never explicitly deallocated.
What are the two functions of the JVM
a. To allow Java programs to run on any device or operating system (known as the "Write once, run anywhere" principle). b. To manage and optimize program memory
A method or field with this access specifier can be accessed.
a. from the same class b. from the class of the same package (not external packages{world}) c. from sub-class (public, private, protected, or default)
What are the 8 primitives used in Java
byte, short, int, long, float, double, boolean, char
How would we declare a class serializable?
public class foo implements Serializable(){}
What is used to create an entry point into a class that enables execution?
public static void main(String[] args){}
How do we calculate mod in Java?
x % y
How would we represent a logical OR?
||