Q. What is Java?
A. Java is "Object oriented" programing language using which you can develop applications.
Q. What type of program we can build using Java?
A. 1. We can create website like facebook and gmail.com
2. We can create standalone application. Ex. note, microsoft word, paint
3. We can create E-commerce application like flipkart, amazon, paytm
4. We can create banking application
5. We can create mobile application
Q. What is platform?
A. Platform = OS+CPU
Q. What is JVM, JRE, JIT and JDK?
A. Java Virtual Machine (JVM) is an abstract computing machine. JVM becomes an instance of JRE at runtime of a Java program. It is widely known as a runtime interpreter.
Java Runtime Environment (JRE) along with various development tools like Java libraries, Java source compilers, Java debuggers, bundling and deployment tools.
Just In Time compiler (JIT) is runs after the program has started executing, on the fly. It has access to runtime information and makes optimizations of the code for better performance.
Java Development Kit (JDK), contains JRE along with various development tools like Java libraries, Java source compilers, Java debuggers, bundling and deployment tools.
Q. What is Java compiler?
A. In java compiler, its provide two types of code in a file, language and byte code.
Ex.
add r1 r2 r3
------------
010101010101
Q. What is JVM?
A. In which complete language and byte code in a single byte code format which is executed by processor.
Q. Which one is faster, static method or instance method?
A. Static methods are faster than instance methods, because they don't use virtual pointer concept internally.
Q. Which of the below is not a proper naming convention in java?
A. Method & class name should start with capital letter. and every word also should start with capital letters.
Q. How many times a static variable will be initialized? Assuming that we are initializing that variable out side the constructor.
A. Static variable will be created and initialized only once that is at program loading time.
Q. How many public classes are allowed in a java file?
A. You can have more than one public outer class in a java file.
Q. Explain public static void main(String args[]).
A. public static void main(String args[])
public, is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class.
static, It is a keyword in java which identifies it is class based i.e it can be accessed without creating the instance of a Class.
void, It is the return type of the method. Void defines the method which will not return any value.
main, It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs.
String args[], It is the parameter passed to the main method.
See full: Core Java Interview Questions
Q. What are the core concepts of OOPS?
A. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts.
Core OOPS concepts are following
1) Class: A class is a blueprint or prototype that defines the variables and the methods (functions) common to all objects of a certain kind.
2) Object: Objects have states and behaviors. An object can be defined as an instance of a class or object is a specimen of a class.
3) Inheritance: Inheritance is a mechanism wherein a new class is derived from an existing class. classes may inherit or acquire the properties and methods of other classes.
4) Polymorphism: Polymorphism refers to the ability of a variable, object or function to take on multiple forms.
5) Abstraction: An abstraction is an act of representing essential features without including background details.
6) Encapsulation: Encapsulation is an OOP technique of wrapping the data and code.
7) Association: Association is a relationship between two objects. It defines the diversity between objects.
8) Aggregation: In this technique, all objects have their separate lifecycle.
9) Composition: A composition is a specialized form of Aggregation. It is also called "death" relationship. Child objects do not have their life-cycle so when parent object deletes all child object will also delete automatically.
Q. What is WeakHashMap?
A. WeakHashMap is an implementation of the Map interface that stores only weak references to its keys.
Storing only weak references allows a key-value pair to be garbage-collected when its key is no longer referenced outside of the WeakHashMap.
Q. Why does HashSet implementation in Sun Java use HashMap as its backing?
A. In order to reduce Duplication of code and made it Memory Efficient ,HashSet implements HashMap as its backing.
Q. What interfaces are implemented by the HashSet Class ? Which is the superclass of HashSet Class?
A. HashSet Class implements three interfaces that is Serializable ,Cloneable and Set interfaces.
AbstractSet is the superclass of HashSet Class .
See full: Core Java Interview Questions
Q. Differences between synchronized and volatile keyword in Java?
A. Differences between synchronized and volatile keyword:
1. Synchronizes the whole of thread memory with "main" memory whereas volatile only synchronizes the value of one variable between thread memory and "main" memory.
2. Volatile is a field modifier, while synchronized modifies code blocks and methods.
3. Volatile in java is a keyword which is used in variable declaration only and cannot be used with method.
4. Volatile variables read values from main memory and not from cached data so volatile variables are not cached whereas variables defined inside synchronized block are cached.
5. Volatile variables are lock free which means that it does require any lock on variable or object whereas synchronized requires lock on method or block.
6. Volatile variable can be null whereas we will get NullPointerException in case we use null object.
7. Using synchronization thread can be blocked when waiting for other thread to release lock but not in the case of volatile keyword.
Q. How to use volatile with variable?
A. volatile Boolean flag;
Q. How to use Synchronized method and Synchronized block?
A.
synchronized void executeMethod()
{
//write code inside synchronized method
}
Synchronized block:
void executeMethod()
{
synchronized (this)
{
//write code inside synchronized block
}
}
Q. What is significance of using Volatile keyword?
A. Using volatile is yet another way (like synchronized, atomic wrapper) of making class thread safe.
Q. What is Thread safe?
A. Thread safe means that a method or class instance can be used by multiple threads at the same time without any problem.
Q. Can you again start Thread?
A. No. After starting a thread, it can never be started again. If you does so, an IllegalThreadStateException is thrown.
Q. Enum V/s Switch?
A. An enum is a (typically small) set of specific values. A switch is a method of controlling program flow to execute certain code based on a particular value.
Enum's are type-safe can be used in switch cases.
Q. enum V/s Enum?
A.
An enum type, also called enumeration type, is a type whose fields consist of a fixed set of constants. The purpose of using enum type is to enforce type safety.
Whereas java.lang.Enum is an abstract class, it is the common base class of all Java language enumeration types. The definition of Enum is:
Q. Enum V/s Inheritance?
A. Enum can not extend any class in java, the reason is by default, Enum extends abstract base class java.lang.Enum. Since java does not support multiple inheritance for classes, Enum can not extend another class.
Q. Enum V/s Constructore?
A. enum is a keyword. Enum constructors are always private or default.
Q. Enum V/s Enumeration?
A. Enumeration is legacy Iterator and Enum is a data type.
See full: Core Java Interview Questions
A. Java is "Object oriented" programing language using which you can develop applications.
Q. What type of program we can build using Java?
A. 1. We can create website like facebook and gmail.com
2. We can create standalone application. Ex. note, microsoft word, paint
3. We can create E-commerce application like flipkart, amazon, paytm
4. We can create banking application
5. We can create mobile application
Q. What is platform?
A. Platform = OS+CPU
Q. What is JVM, JRE, JIT and JDK?
A. Java Virtual Machine (JVM) is an abstract computing machine. JVM becomes an instance of JRE at runtime of a Java program. It is widely known as a runtime interpreter.
Java Runtime Environment (JRE) along with various development tools like Java libraries, Java source compilers, Java debuggers, bundling and deployment tools.
Just In Time compiler (JIT) is runs after the program has started executing, on the fly. It has access to runtime information and makes optimizations of the code for better performance.
Java Development Kit (JDK), contains JRE along with various development tools like Java libraries, Java source compilers, Java debuggers, bundling and deployment tools.
Q. What is Java compiler?
A. In java compiler, its provide two types of code in a file, language and byte code.
Ex.
add r1 r2 r3
------------
010101010101
Q. What is JVM?
A. In which complete language and byte code in a single byte code format which is executed by processor.
Q. Which one is faster, static method or instance method?
A. Static methods are faster than instance methods, because they don't use virtual pointer concept internally.
Q. Which of the below is not a proper naming convention in java?
A. Method & class name should start with capital letter. and every word also should start with capital letters.
Q. How many times a static variable will be initialized? Assuming that we are initializing that variable out side the constructor.
A. Static variable will be created and initialized only once that is at program loading time.
Q. How many public classes are allowed in a java file?
A. You can have more than one public outer class in a java file.
Q. Explain public static void main(String args[]).
A. public static void main(String args[])
public, is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class.
static, It is a keyword in java which identifies it is class based i.e it can be accessed without creating the instance of a Class.
void, It is the return type of the method. Void defines the method which will not return any value.
main, It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs.
String args[], It is the parameter passed to the main method.
See full: Core Java Interview Questions
Q. What are the core concepts of OOPS?
A. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts.
Core OOPS concepts are following
1) Class: A class is a blueprint or prototype that defines the variables and the methods (functions) common to all objects of a certain kind.
2) Object: Objects have states and behaviors. An object can be defined as an instance of a class or object is a specimen of a class.
3) Inheritance: Inheritance is a mechanism wherein a new class is derived from an existing class. classes may inherit or acquire the properties and methods of other classes.
4) Polymorphism: Polymorphism refers to the ability of a variable, object or function to take on multiple forms.
5) Abstraction: An abstraction is an act of representing essential features without including background details.
6) Encapsulation: Encapsulation is an OOP technique of wrapping the data and code.
7) Association: Association is a relationship between two objects. It defines the diversity between objects.
8) Aggregation: In this technique, all objects have their separate lifecycle.
9) Composition: A composition is a specialized form of Aggregation. It is also called "death" relationship. Child objects do not have their life-cycle so when parent object deletes all child object will also delete automatically.
Q. What is WeakHashMap?
A. WeakHashMap is an implementation of the Map interface that stores only weak references to its keys.
Storing only weak references allows a key-value pair to be garbage-collected when its key is no longer referenced outside of the WeakHashMap.
Q. Why does HashSet implementation in Sun Java use HashMap as its backing?
A. In order to reduce Duplication of code and made it Memory Efficient ,HashSet implements HashMap as its backing.
Q. What interfaces are implemented by the HashSet Class ? Which is the superclass of HashSet Class?
A. HashSet Class implements three interfaces that is Serializable ,Cloneable and Set interfaces.
AbstractSet is the superclass of HashSet Class .
See full: Core Java Interview Questions
Q. Differences between synchronized and volatile keyword in Java?
A. Differences between synchronized and volatile keyword:
1. Synchronizes the whole of thread memory with "main" memory whereas volatile only synchronizes the value of one variable between thread memory and "main" memory.
2. Volatile is a field modifier, while synchronized modifies code blocks and methods.
3. Volatile in java is a keyword which is used in variable declaration only and cannot be used with method.
4. Volatile variables read values from main memory and not from cached data so volatile variables are not cached whereas variables defined inside synchronized block are cached.
5. Volatile variables are lock free which means that it does require any lock on variable or object whereas synchronized requires lock on method or block.
6. Volatile variable can be null whereas we will get NullPointerException in case we use null object.
7. Using synchronization thread can be blocked when waiting for other thread to release lock but not in the case of volatile keyword.
Q. How to use volatile with variable?
A. volatile Boolean flag;
Q. How to use Synchronized method and Synchronized block?
A.
synchronized void executeMethod()
{
//write code inside synchronized method
}
Synchronized block:
void executeMethod()
{
synchronized (this)
{
//write code inside synchronized block
}
}
Q. What is significance of using Volatile keyword?
A. Using volatile is yet another way (like synchronized, atomic wrapper) of making class thread safe.
Q. What is Thread safe?
A. Thread safe means that a method or class instance can be used by multiple threads at the same time without any problem.
Q. Can you again start Thread?
A. No. After starting a thread, it can never be started again. If you does so, an IllegalThreadStateException is thrown.
Q. Enum V/s Switch?
A. An enum is a (typically small) set of specific values. A switch is a method of controlling program flow to execute certain code based on a particular value.
Enum's are type-safe can be used in switch cases.
Q. enum V/s Enum?
A.
An enum type, also called enumeration type, is a type whose fields consist of a fixed set of constants. The purpose of using enum type is to enforce type safety.
Whereas java.lang.Enum is an abstract class, it is the common base class of all Java language enumeration types. The definition of Enum is:
Q. Enum V/s Inheritance?
A. Enum can not extend any class in java, the reason is by default, Enum extends abstract base class java.lang.Enum. Since java does not support multiple inheritance for classes, Enum can not extend another class.
Q. Enum V/s Constructore?
A. enum is a keyword. Enum constructors are always private or default.
Q. Enum V/s Enumeration?
A. Enumeration is legacy Iterator and Enum is a data type.
See full: Core Java Interview Questions
No comments:
Post a Comment