Java Flashcards
Understanding the Java Programming Language
What is Java?
Java is an Object Oriented Program known for it’s “run once, write anywhere” because of the JVM. Garbage Collection, Secure, Simpler, Portable.
What is JRE
Java Runtime Environment - This contains the libraries that for the applications
What is JDK
Java Development Kit - This contains the compiler and is where applications are developed turns the code to bytecode
What is JVM
Java Virtual Machine - runs the bytecode on for the specific platform.
What’s the difference between an object and a class
An object is an instantiation of the class. Class is a blueprint for an object.
What is the root class from which every class extends?
Object: some of the methods for the object class are equals, getClass, hashCode, toString, thread stuff.
Where are Strings stored?
Primarily the String Pool.
Are variable references stored on the stack or heap? What about the objects they
refer to?
Stack and the object is in the heap.
What are annotations?
Annotations are a type of metadata that signal to the compiler information about the program
Java has a few built-in annotations you should be familiar with:
@Override - declares the method must override an inherited method (otherwise, a compilation error occurs)
@Deprecated - marks a method as obsolete (compilation warning if used anywhere)
@SuppressWarnings - instructs compiler to suppress compilation warnings
@FunctionalInterface - designates an interface to be a functional interface (covered in another module)
What is a POJO vs a bean?
Plain Old Java Object, has no special restrictions outside those enforced by Java.
A bean is a type of POJO which is Serialized, has private fields with getters, setters, or both, a
no-arg constructor, and fields which are only accessible by the constructor or getters/setters.
Can you force garbage collection in Java? When is an object eligible for GC?
No, when there are no reference variables pointing to that object.
Why are strings immutable in java?
To save space in the heap.
How would you make your own objects immutable?
The use of final and getters and setters. Private would be used in this case.
What are the different variable scopes in Java?
Class, or static, scope
Instance, or object, scope
Method scope
Block scope
Class, or static, scope?
Class scoped variables reside on the class definition itself. This means that when objects update a class-scoped variable, the change is reflected across all instances of the class. Class scope is declared with the static keyword. Methods can also be declared as class scope. However, static methods cannot invoke instance methods or variables (think about it: which specific object would they reference?). Static methods and variables should be referenced through the class directly, not through an object. For example: MyClass.myStaticMethod() or MyClass.myStaticVariable.