Java Interview Questions And Answers Pdf Yes, We can execute any code, even before the main method. We are using a static block. Dear readers, these Java Interview Questions have been designed especially to get you the subject and later they continue based on further discussion and what you answer − If you are fresher then interviewer does not expect you. Basic Java Interview Questions and Answers for Freshers or Experienced Pdf. This interview section questions contains a brief introduction to the Java.

Java Interview Questions And Answers For Freshers Pdf

Language:English, Dutch, French
Country:Sri Lanka
Published (Last):05.09.2016
ePub File Size:19.73 MB
PDF File Size:9.31 MB
Distribution:Free* [*Registration needed]
Uploaded by: ELDA

Java Interview Questions i. Java Interview Questions .. Both implementations share some common characteristics, but they differ in the following features. Get Interview Questions and answers on JAVA for freshers with pdf, learn OOPS Concepts, Features, diagrammatic representation, Packages. Moreover, many interview questions have different solutions. This book evaluates A typical interview process can be divided into two phases: popular programming languages (C, C++, C#, and Java) are discussed in Chapter 2. The most.

So that equal priority threads have a chance to run. It is a static method. Yield method moves the thread back to the Runnable state only, and not the thread to sleep , wait or block.

Ans: wait method is used to make the thread to wait in the waiting pool. When a wait method is executed during a thread execution then immediately the thread gives up the lock on the object and goes to the waiting pool.

You might also like: PDF VIEWER FOR NOKIA X2

Wait method tells the thread to wait for a given amount of time. Then the thread will wake up after notify or notify all method is called. Wait and the other above-mentioned methods do not give the lock on the object immediately until the currently executing thread completes the synchronized code. It is mostly used in synchronization. Ans: Given below are few differences between notify method and notifyAll method notify notifyAll This method is used to send a signal to wake up a single thread in the waiting pool.

This method sends the signal to wake up all the threads in a waiting spool. Q 44 How to stop a thread in java? Explain about sleep method in a thread?

Ans: We can stop a thread by using the following thread methods. Sleeping Blocked Sleep: Sleep method is used to sleep the currently executing thread for the given amount of time.

Once the thread is wake up it can move to the runnable state.

So sleep method is used to delay the execution for some period. Example: Thread. Sleep So it delays the thread to sleep 2 milliseconds. Ans: If we need our class to extend some other classes other than the thread then we can go with the runnable interface because in java we can extend only one class. If we are not going to extend any class then we can extend the thread class. Q 46 Difference between start and run method of thread class.

Ans: Start method creates new thread and the code inside the run method is executed in the new thread. If we directly called the run method then a new thread is not created and the currently executing thread will continue to execute the run method. Q 47 What is Multi-threading? Ans: Multiple threads are executed simultaneously.

Each thread starts their own stack based on the flow or priority of the threads. Now JVM switches to the new thread and the main thread are back to the runnable state. The two stacks look as shown below. Now, the user thread executed the code inside the run method. Once the run method has completed, then JVM switches back to the main thread and the User thread has completed the task and the stack was disappeared.

JVM switches between each thread until both the threads are completed. This is called Multi-threading. Q 48 Explain thread life cycle in Java. Yes, a for statement can loop indefinitely. For example, consider the following: Constants in java are created using static and final keywords. What is synchronization and why is it important? The term synchronization is the ability to control the access of multiple threads to shared resources.

This often leads to major errors. Java Development Kit Full Form: To execute the java programs It provides all the tools, executables and binaries required to compile, debug and execute a Java Program The execution part is handled by JVM to provide machine independence.

Java support primitive types such as int, byte, short, long etc that why it is not said to be pure object oriented language.

Java, J2EE & SOA Certification Training

Java traning. Java provides three access controlssuch as public, private and protected access modifier. Yes, we can overload the main methodwith syntax as public static void main String args[]. It contains the executable body that can be applied to the specific object of the class.

Method includes method name, parameters or arguments and return type and a body of executable code. Separate with commas when we have multiple arguments.

This raises compile time error if we try to handle checked exceptions when there is no possibility of causing exception. Finally block will not be executed whenever jvm shutdowns.

If we use system.

Java Interview Questions and Answers PDF eBook Free Download (+ Questions, 60 Pages)

Main method is starting point of execution for all java applications. Every Java application must have atleast one main method. A constructor is a special method used to initialize objects in java. As and when an object is created it is initialized automatically with the help of constructor in java. We have two types of constructors Default Constructor Parameterized Constructor. In Java, there is no way to find out the actual size of an object on the heap.

There are two ways to do synchronization in java: Java automatic type conversion is done if the following conditions are met: Int can be assigned directly to long.

Automatic type conversion takes place if int is assigned to long because long is larger datatype than int. Widening Conversion comes under Automatic type conversion. We can handle exceptions in either of the two ways: Employee employee; In the above example employee object is not instantiate so it is pointed no where.

We can have comments before the package statement.

When we declare variables variables are created in stack. So when the variable is out of scope those variables get garbage collected. When do we use synchronized blocks and advantages of using synchronized blocks? If very few lines of code requires synchronization then it is recommended to use synchronized blocks.

The main advantage of synchronized blocks over synchronized methods is it reduces the waiting time of threads and improves performance of the system. What is the difference between access specifiers and access modifiers in java?

Latest 60 Java Interview Questions And Answers Pdf

But there is no such divison of access specifiers and access modifiers in java. In Java we have access modifiers and non access modifiers. Access Modifiers: We can use only two access modifiers for class public and default. A class with public modifier can be visible 1 In the same class 2 In the same package subclass 3 In the same package nonsubclass 4 In the different package subclass 5 In the different package non subclass. A class with default modifier can be accesed 1 In the same class 2 In the same package subclass 3 In the same package nonsubclass 4 In the different package subclass 5 In the different package non subclass.

Sometimes we may come across a situation where we cannot provide implementation to all the methods in a class. We want to leave the implementation to a class that extends it. In such case we declare a class as abstract. To make a class abstract we use key word abstract. Any class that contains one or more abstract methods is declared as abstract.

Java Questions

We get the following error. For example if we take a vehicle class we cannot provide implementation to it because there may be two wheelers , four wheelers etc. At that moment we make vehicle class abstract. All the common features of vehicles are declared as abstract methods in vehicle class. Any class which extends vehicle will provide its method implementation.

The important features of abstract classes are: Though we cannot instantiate abstract classes we can create object references. Through superclass references we can point to subclass. But when we cannot instantiate class there is no use in creating a constructor for abstract class. Abstract method is declared with keyword abstract and semicolon in place of method body. Java Exception Handling Interview questions. NumberFormatException 3 Invalid casting of class Class cast Exception 4 Trying to create object for interface or abstract class Instantiation Exception.

In java exception is an object. Exceptions are created when an abnormal situations are arised in our program. Exceptions can be created by JVM or by our application code.

All Exception classes are defined in java. In otherwords we can say Exception as run time error. Error is the subclass of Throwable class in java. When errors are caused by our program we call that as Exception, but some times exceptions are caused due to some environment issues such as running out of memory. Exceptions which cannot be recovered are called as errors in java.

Out of memory issues.

It is recommended to handle exceptions with specific Exception instead of handling with Exception root class. If a method throws an exception and it is not handled immediately, then that exception is propagated or thrown to the caller of that method.

This propogation continues till it finds an appropriate exception handler ,if it finds handler it would be handled otherwise program terminates Abruptly. We can create threads in java by any of the two ways: This is first and foremost way to create threads. By implementing runnable interface and implementing run method we can create new thread.

Method signature:Exceptions which cannot be recovered are called as errors in java. If we directly called the run method then a new thread is not created and the currently executing thread will continue to execute the run method. Im subscribing for the book.. What's the base class in Java from which all classes are derived? Large amount of data can be sent because data is sent in body.

A package statement must appear as the first line in a source code file eliminating blank lines and comments. Ans: We can stop a thread by using the following thread methods. Ans: In multi-threading, access to the resources which are shared among multiple threads can be controlled by using the concept of synchronization. Ans: String is not a primitive data type in java.

DESPINA from Santa Clarita
See my other posts. I have a variety of hobbies, like f1 powerboat world championship. I enjoy sharing PDF docs dearly .