Thursday, April 18, 2019 admin Comments(0)

5) Difference between method overloading and method overriding in java? . .. 9. 6) Difference between . Core java Interview questions on Coding Standards. ) List out benefits of object oriented programming language?. Dear readers, these Java Interview Questions have been designed especially to the subject and later they continue based on further discussion and what you answer − What are the supported platforms by Java Programming Language?. Contains Important Java Interview Questions with Answers and Java FAQs helpful for clearing any Java Job Java Language Interview Question and Answers.

Language:English, Spanish, Indonesian
Published (Last):22.05.2015
ePub File Size:21.57 MB
PDF File Size:17.55 MB
Distribution:Free* [*Register to download]
Uploaded by: HERIBERTO

Java Interview Questions And Answers Pdf Yes, We can execute A native method is a method that is applied in a language other than Java. Java Interview Questions Why is Java called the Platform Independent Programming Language? .. Both implementations share some common. Get Interview Questions and answers on JAVA for freshers with pdf, learn Answer- The features of this programming language are as follows-.

Compile time polymorphism is method overloading whereas Runtime time polymorphism is done using inheritance and interface. So this brings us to the end of the Java interview questions blog. These set of Java Interview Questions will definitely help you ace your job interview. Good luck with your interview! Java Interview Questions and Answers Edureka. It is the return type of the method. Void defines the method which will not return any value.

When the constructor of a class is invoked? Ans: The constructor of a class is invoked every time an object is created with new keyword. For example, in the following class two objects are created using new keyword and hence, constructor is invoked two times. Can a class have multiple constructors? Ans: Yes, a class can have multiple constructors with different parameters.

2018 Latest 60 Java Interview Questions And Answers Pdf

Which constructor gets used for object creation depends on the arguments passed while creating the objects. Can we override static methods of a class?

Ans: We cannot override static methods. Static methods belong to a class and not to individual objects and are resolved at the time of compilation not at runtime. Even if we try to override static method,we will not get an complitaion error,nor the impact of overriding when running the code. In the below example, what will be the output? Is String a data type in java? Ans: String is not a primitive data type in java. When a string is created in java, it's actually an object of Java.

String class that gets created. After creation of this string object, all built-in methods of String class can be used on the string object. In the below example, how many String Objects are created? String class are created. Why Strings in Java are called as Immutable? Ans: In java, string objects are called immutable as once value has been assigned to a string, it can't be changed and if changed, a new object is created. In below example, reference str refers to a string object having value "Value one".

What's the difference between an array and Vector? Ans: An array groups data of same primitive type and is static in nature while vectors are dynamic in nature and can hold data of different data types. What is multi-threading? Ans: Multi threading is a programming concept to run multiple tasks in a concurrent manner within a single program. Threads share same process stack and running in parallel. It helps in performance improvement of any program.

Why Runnable Interface is used in Java? Ans: Runnable interface is used in java for implementing multi threaded applications. Runnable interface is implemented by a class to support multi threading.

What are the two ways of implementing multi-threading in Java?

Questions java language pdf interview and answers

Ans: Multi threaded applications can be developed in Java by using any of the following two methodologies: 1. By using Java. Runnable Interface. Classes implement this interface to enable multi threading. There is a Run method in this interface which is implemented.

Language questions answers interview pdf and java

By writing a class that extend Java. Thread class. When a lot of changes are required in data, which one should be a preference to be used? String or StringBuffer? Ans: Since StringBuffers are dynamic in nature and we can change the values of StringBuffer objects unlike String which is immutable, it's always a good choice to use StringBuffer when data is being changed too much.

If we use String in such a case, for every data change a new String object will be created which will be an extra overhead. What's the purpose of using Break in each case of Switch Statement? Ans: Break is used after each case except the last one in a switch so that code breaks after the valid case and doesn't flow in the proceeding cases too. If break isn't used after each case, all cases after the valid case also get executed resulting in wrong results. How garbage collection is done in Java?

Ans: In java, when an object is not referenced any more, garbage collection takes place and the object is destroyed automatically. For automatic garbage collection java calls either System. How we can execute any code even before main method? Ans: If we want to execute any statements before even creation of objects at load time of class, we can use a static block of code in the class. Any statements inside this static block of code will get executed once at the time of loading the class even before creation of objects in the main method.

Can a class be a super class and a sub-class at the same time? Ans: If there is a hierarchy of inheritance used, a class can be a super class for another class and a sub-class for another one at the same time.

Language interview answers java pdf and questions

In the example below, continent class is sub-class of world class and it's super class of country class. How objects of a class are created if no constructor is defined in the class? Ans: Even if no explicit constructor is defined in a java class, objects get created successfully as a default constructor is implicitly used for object creation. This constructor has no parameters.

In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously? Ans: In multi-threading, access to the resources which are shared among multiple threads can be controlled by using the concept of synchronization.

Using synchronized keyword, we can ensure that only one thread can use shared resource at a time and others can get control of the resource only once it has become free from the other one using it.

Can we call the constructor of a class more than once for an object? Ans: Constructor is called automatically when we create an object using new keyword.

Objects stored in the heap are globally accessible. Memory management is based on generation associated to each object. Lifetime Exists until the end of execution of the thread. Heap memory lives from the start till the end of application execution. Usage Stack memory only contains local primitive and reference variables to objects in heap space. In case you are facing any challenges with these java interview questions, please comment on your problems in the section below.

An interface cannot provide any code at all,just the signature. In case of abstract class, a class may extend only one abstract class. A Class may implement several interfaces.

An abstract class can have non-abstract methods. All methods of an Interface are abstract. An abstract class can have instance variables. An Interface cannot have instance variables An abstract class can have any visibility: 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? 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. 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.

100+ Java Interview Questions You Must Prepare In 2019

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.

2018 Latest 60 Java Interview Questions And Answers Pdf

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.

Interview Questions on JAVA with answers and pdf for freshers

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: If multiple threads tries to access a method where method can manipulate the state of object , in such scenario we can declare a method as synchronized.

Finally block is used for cleaning up of resources such as closing connections, sockets etc. If there is exception thrown in try block finally block executes immediately after catch block. If an exception is thrown,finally block will be executed even if the no catch block handles the exception.