Java interview Questions
package com.xyz.client ;
import java.io.File;
import java.net.URL;
Q) What is the Java Virtual Machine (JVM)?
A) JVM is a program which executes certain other programs, namely those containing Java bytecode instructions. JVMs are most often implemented to run on an existing operating system, but can also be implemented to run directly on hardware. A JVM provides a run-time environment in which Java bytecode can be executed, enabling features such as automated exception handling, which provides root-cause debugging information for every exception. A JVM is distributed along with Java Class Library, a set of standard class libraries (in Java bytecode) that implement the Java Application programming interface (API). These libraries, bundled together with the JVM, form theJava Runtime Environment (JRE).
Q) What are the usages of Java packages?
A) It helps resolve naming conflicts when different packages have classes with the same names. This also helps you organize files within your project. For example: java.io package do something related to I/O and java.net package do something to do with network and so on. If we tend to put all .java files into a single package, as the project gets bigger, then it would become a nightmare to manage all your files.
You can create a package as follows with package keyword, which is the first keyword in any Java program followed by import statements. The java.lang package is imported implicitly by default and all the other packages must be explicitly imported.
You can create a package as follows with package keyword, which is the first keyword in any Java program followed by import statements. The java.lang package is imported implicitly by default and all the other packages must be explicitly imported.
package com.xyz.client ;
import java.io.File;
import java.net.URL;
Q. What happens if you do not provide a constructor?
A)Java does not actually require an explicit constructor in the class description. If you do not include a constructor, the Java compiler will create a default constructor in the byte code with an empty argument. This default constructor is equivalent to the explicit “Pet(){}”. If a class includes one or more explicit constructors like “public Pet(int id)” or “Pet(){}” etc, the java compiler does not create the default constructor “Pet(){}”.
Q. Can you call one constructor from another?
A) Yes, by using this() syntax. E.g.
public Pet(int id)
{
this.id = id; // “this” means this object
this.id = id; // “this” means this object
}
public Pet (int id, String type)
{
this(id); // calls constructor public Pet(int id)
this(id); // calls constructor public Pet(int id)
this.type = type; // ”this” means this object
}
Q : What are the advantages of Object Oriented Programming Languages (OOPL)?
A)The Object Oriented Programming Languages directly represent the real life objects like Car, Jeep, Account,
Customer etc. The features of the OO programming languages like polymorphism, inheritance and encapsulation
make it powerful.
Customer etc. The features of the OO programming languages like polymorphism, inheritance and encapsulation
make it powerful.
Q) What is difference in final, finalize and finally keyword in Java?
A) final and finally are keyword, while finalize is method. final keyword is very useful for creating immutable class in Java by making a class final, we prevent it from being extended, similarly by making a method final, we prevent it from being overridden,. finalize() method is called by garbage collector, before that object is collected, but this is not guaranteed by Java specification. finally keyword is the only one which is related to error and exception handling and you should always have finally block in production code for closing connection and resources.
Q) What is difference betwwen object oriented programming and object based programming?
A) Object-oriented programming language supports all the features of OOPs and Object-based programming language doesn't support all the features of OOPs like Polymorphism and Inheritance.
- example: javascript as object based and java as object oriented
Q) Why JavaScript isn't an object-oriented programming (scripting) language?
A)Because it has no feature that fits the requirements of the definition of object-oriented programming:
var constructor = function() { };
constructor.prototype.text = "hello world";
alert(new constructor().text); // This alerts hello world
Q) what is a transient variable?
A) transient variable is a variable that cannot be serialized
Q) which containers use a border Layout as their default layout?
A) window, Frame and Dialog classes use a BorderLayout as their default layout.
Q) How are Observer and Observable used?
A) If a class which extends java.util.Observable that class Objects maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The java.util.Observer interface is implemented by objects that observe Observable objects.
Q) What is synchronization and why is it important?
A) Synchronization is the process to control the access of multiple threads to shared resources. We will use 'synchornized' keyword to perform synchronization. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.
Q) Is null a keyword?
A)No, null is not a keyword, it is a value.
Q) Is sizeof a keyword?
A) sizeof is an operator, it is not a keyword.
Q) What is the Locale class?
A) The java.util.Locale class is used to represent a particular geographic, political, or cultural region.
Q) Can a double value be cast to a byte?
A) Yes, a double value can be cast to a byte.
Q) Can an unreachable object become reachable again?
A) Yes, an unreachable object may become reachable again. This can happen when the object's finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects.
Q) why do you create interfaces, and when MUST you use one.?
A) You would create interfaces when you have two or more functionalities talking to each other. Doing it this way help you in creating a protocol between the parties involved.
Q) what are the main features of java?
A) The main features of java are
Platform Independent
Object oriented
Robust and secure
Type safe
High Performance.
Compiled and Interpreted
Object oriented
Robust and secure
Type safe
High Performance.
Compiled and Interpreted
Q) What is the Java API?
A) The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.
Q) What is the Java Virtual Machine (JVM)?
A) The Java Virtual Machine is software that can be ported onto various hardware-based platforms.
No comments:
Post a Comment