Basics Flashcards
What is Java?
Java is a high level, object oriented programming language. Java is considered highly robust, secure, simple, and high performing
- What is the JRE?
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?
- A POJO is a Plain Old Java Object, it is a java object that does not have any special restrictions and is used for increasing readability and reusability in a program
- A Bean is a special POJO with restrictions such as private fields that require getters and setters
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