Java is Object Oriented Programming :
Objects are the units of the program.
Object = data + code
Data access within the object only.
Objects:
It is the instance of a class. When an object is created using new memory is allocated to it.
Encapsulation:
It is the mechanism that binds code and data together and keeps it safe from outside interference. Class will have total control of what it stores.
Inheritance:
It is the process by which one object acquires the properties of another object. Interface can be implemented by multiple class files.
Polymorphism:
If we have the same function in the base class and extended class, we would display the function from the extended class. We can access the base class function by using “super.function”.
Primitive Data Types:
Byte, short, int, long, float, double, Boolean, char
Access Modifiers
Default – Can be accessed within the folder only.
Public – Can be accessed any were.
Private – Can be accessed only inside the class.
Protected – Can be accessed within the folder and subclasses outside the folder.
Constructor VS Method
Constructor will be automatically called when we call the object, whereas a method should be called explicitly.
Uses of Bin and Lib folders in JDK
Bin contains JAVAC (Compiler), AWT tool, applet viewer etc., whereas Lib contains API and other packages.
final, finalize () and finally
A final class cannot be overridden or extended to subclasses.
Finalize function will be called just before destruction of a class.
Finally is used in exception handling where it will be executed whether or not exception occurs.
Garbage Collection
We can call garbage collection explicitly by using “System.GC()”.
Transient VS Volatile
Transient variables can be in a class but do not participate in persistence whereas Volatile variable can change its value unexpectedly by other processes.
Overloading VS Overriding
In Overloading we have two functions with the same name but different parameters whereas in Overriding we have sub-class function replace the super-class function of the same name.
Inner Class VS Anonymous Class
Inner class is defined inside a class whereas Anonymous class is declared without a name and instantiated and declared in the same class and cannot have explicit constructors. And is described here,
new interface-or-class-name() { class-body }
runnable r = new runnable()
{
public void run()
{
//code for the run method goes here
}
};
Integer VS Int
“Int” is a primitive data type for calculations whereas “Integer” is from “Java.lang” package and used in methods.
Abstract Class VS Interface
- Any variable declaration. - Only Public static final variables and public methods allowed.
- Related 1 class only implement abstract. – Unrelated classes can implement an interface.
Inner thread communication functions
Wait(), notify(), notifyAll()
Applet lifecycle
Init() -> Start() -> paint() -> stop() -> destroy()
AWT VS SWT VS Swing VS GWT
AWT, SWT and Swing are Graphical UI tool kits for java. GWT JavaScript based UI application development and maintenance tool.
Vector VS Hash table VS Linked list VS Enumeration
Vector is a collection of objects. Hash table stores index and objects using hash function. Linked list involves sequential storing and retrieval of data. Enumeration stores and gives one element at a time.
Set VS List
Set stores in unordered way and cannot have duplicates and it’s the opposite for Lists.
Types of statements in JDBC
createStatement()
preparedStatement()
CallableStatement()
Servlet Lifecycle
Init() -> service() -> destroy()
Cookie VS Session Tracking
Cookie is storing the state information of a user session by using a file in client side whereas tracking is done in server side.