What is Java?
Java is a high level, object oriented programming language. Java is considered highly robust, secure, simple, and high performing
The JRE is the Java Runtime Environment, which is part of the JDK and is responsible for running a java program. It contains the class libraries and other resources a specific java program needs to run. Contains the JVM and is inside the JDK
What is the JDK?
The Java Development Kit, it contains the compiler and developer tools needed to develop a java application. Contains the JRE and JVM
What is the JVM?
JVM stands for JVM, it is designed to execute the bytecode in .clss files which runs the java application. Lives inside the JDE and JDK
What is the difference between an object and a class?
An object is an instance of a java class, it has its own identity, behavior, and state whereas a class is a user designed blueprint by which an object is created. It has a set of properties or methods that define its specifications
What is the root class from which every class extends?
The object class is the root of the class hierarchy
What are the primitive data types in Java?
boolean, char, double, float, long, int, short, byte
Where are Strings stored?
String is a class and strings are treated as objects, so they’re located in the heap. Specifically in the String Constant Pool
Explain Stack vs Heap
Stack is used to store method invocations and local variables, works based on Last in First Out; Heap is where all objects are stored, created on startup
Are variable references stored on the stack or heap? What about the objects they refer to?
Variable references can be stored in the stack, all java objects are stored within the heap
What is a stack frame and when are they created?
A stack frame contains the state of one java method invocation. When a function is called, a stack frame is created in the stack segment
What are annotations?
They are used to provide supplementary information about a program, they do not change the actions of a program, but they help associate metadata to the program elements (@Override)
What is a POJO vs a Bean?
Can you force garbage collection in Java? When is an object eligible for garbage collection?
By either setting a variable to null, redirecting a variable’s reference, or calling the finalize() method in the object class.
- Objects that no longer have a variable reference are eligible for garbage collection
Why are strings immutable in java? How would you make your own object immutable?
Strings are immutable because string objects are cached in the string pool and since all the strings in the pool are shared between multiple clients, there is a risk that a change would effect other clients
- In order to make an object immutable, you would need to add the final keyword to ensure there are no changes
What is the difference between String, StringBuilder, and StringBuffer?
What are the different available scopes in Java?
What are some access modifiers in Java? Explain them
What are the non-access modifiers in Java?
What is the difference between static and final variables?
Static is used to define that a class member can be used independently of any other object in the class
Final is used to declare that the class member cannot be overridden
What are the default values for all data types in Java?
char - \u000 or null double - 0.0d float - 0.0f long - 0 int - 0 short - 0 byte - 0 boolean - false
What is a wrapper class? List them
The wrapper class in java provides the mechanism to convert primitive data types to objects and vice versa
Boolean, Character, Byte, Short, Integer, Long, Float, Double
What is Autoboxing/Unboxing?
Autoboxing is the automatic conversion of primitive data types into its corresponding object wrapper class, whereas Unboxing is the reverse
Is Java pass-by-value or pass-by-reference?
Java is pass-by-value; confusingly, a reference in java is a reference to a value, so all arguments are passed by value