Flashcards in Java 2 Deck (13)
What is the difference between static and final variables?
Static variable is a global variable shared by all the instances of objects and it has only single copy. A final variable is a constant variable and it cannot be changed.
What are the implicit modifiers required for interface variables?
public static final
What are transient variables?
Transient variables are those variables which cannot be serialized.
What are access modifiers?
public – can be accessed from any package.
private – only members of the same class can access.
protected – can be accessed by classes inside the package and subclasses anywhere.
default - no access by classes or subclasses outside the package
What is a wrapper class?
Wrapper class is a wrapper around a primitive data type. It represents primitive data types in their corresponding class instances e.g. a boolean data type can be represented as a Boolean class instance. All of the primitive wrapper classes in Java are immutable i.e. once assigned a value to a wrapper class instance cannot be changed further.
What is Reflection API?
The first component of the Reflection API is the mechanism used to fetch information about a class. This mechanism is built into the class named Class. The special class Class is the universal type for the meta information that describes objects within the Java system. Class loaders in the Java system return objects of type Class. Up until now the three most interesting methods in this class were:
forName, which would load a class of a given name, using the current class loader
getName, which would return the name of the class as a String object,which was useful for identifying object references by their class name
newInstance, which would invoke the null constructor on the class (if it exists) and return you an object instance of that class of object
To these three useful methods the Reflection API adds some additional methods to class Class. These are as follows:
getConstructor, getConstructors, getDeclaredConstructor
getMethod, getMethods, getDeclaredMethods
getField, getFields, getDeclaredFields
Is Java pass by value or pass by reference?
Java is strictly pass by value.
What is encapsulation?
Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.
In what ways can you create a thread?
By extending the Thread Class or by implementing the Runnable Interface. You must call Thread's start() method to start it as a new thread of execution.
What is the difference between "==" and equals()?
"==" - tests to see if two reference variables refer to the exact same instance of an object.
equals() - tests to see if the two objects being compared to each other are equivalent, but they need not be the exact same instance of the same object.
What is polymorphism?
Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class. An object can also be referenced by its supertype "parent" class, for example ParentClass obj = new SubClass( );
What is inheritance?
A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).