soundofheaven.info Laws CORE JAVA INTERVIEW QUESTION ANSWER PDF

Core java interview question answer pdf

Monday, April 15, 2019 admin Comments(0)

java interview questions and answers PDF, java interview questions PDF eBook Free download, core java interview questions pdf, + questions, 60+ pages. Corejava Interview Questions And Answers in soundofheaven.info for more Corejava Interview Questions And Answers to download in pdf format. We assure that you will get here the 90% frequently asked interview questions and answers. The answers to the core java interview questions are short and to.


Author: SUDIE RUNDALL
Language: English, Spanish, Hindi
Country: Rwanda
Genre: Health & Fitness
Pages: 353
Published (Last): 29.11.2015
ISBN: 238-4-44827-856-3
ePub File Size: 21.50 MB
PDF File Size: 9.56 MB
Distribution: Free* [*Regsitration Required]
Downloads: 31192
Uploaded by: DEVORA

CORE JAVA INTERVIEW. QUESTIONS AND ANSWERS. Table of Contents. 1) what are static blocks and static initalizers in Java?. Dear readers, these Java Interview Questions have been designed especially during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer −. Basic Java Interview Questions and Answers for Freshers or Experienced Pdf. This interview section questions contains a brief introduction to the Java.

Check Demo Sesstion: In Java, the final variable is used to restrict the user from updating it. What is difference between path and classpath variables? Yes, It is possible to use this keyword to refer static members because this is just a reference variable which refers to the current class object. I would love to hear your thoughts and opinions on my articles directly. BeforeClass is run as static initialiser, therefore it will run before the class instance of your test fixture is created. Please send me the interview questions pdf ebook.

The static is the part of the class and not of the object. The static variables are stored in the class area, and we do not need to create the object to access such variables. Therefore, static is used in the case, where we need to define variables or methods which are common to all the objects of the class.

For example, In the class simulating the collection of the students in a college, the name of the college is the common attribute to all the students.

Therefore, the college name will be defined as static. In the first case, 10 and 20 are treated as numbers and added to be Now, their sum 30 is treated as the string and concatenated with the string Javatpoint.

Therefore, the output will be 30Javatpoint. In the second case, the string Javatpoint is concatenated with 10 to be the string Javatpoint10 which will then be concatenated with 20 to be Javatpoint In the first case, The numbers 10 and 20 will be multiplied first and then the result is treated as the string and concatenated with the string Javatpoint to produce the output Javatpoint.

In the second case, The numbers 10 and 20 will be multiplied first to be because the precedence of the multiplication is higher than addition. The result will be treated as the string and concatenated with the string Javatpoint to produce the output as Javatpoint The above code will give the compile-time error because the for loop demands a boolean value in the second part and we are providing an integer value, i. However, they have been categorized in many sections such as constructor interview questions, static interview questions, Inheritance Interview questions, Abstraction interview question, Polymorphism interview questions, etc.

It is a programming paradigm based on objects having data and methods defined in the class to which it belongs. Object-oriented paradigm aims to incorporate the advantages of modularity and reusability.

Pdf core java interview question answer

Objects are the instances of classes which interacts with one another to design applications and programs. There are the following features of the object-oriented paradigm. The Object is the real-time entity having some state and behavior. In Java, Object is an instance of the class having the instance variables as the state of the object and the methods as the behavior of the object. The object of a class can be created by using the new keyword.

There are the following basic differences between the object-oriented language and object-based language. The constructor can be defined as the special type of method that is used to initialize the state of an object. It is invoked when the class is instantiated, and the memory is allocated for the object. Every time, an object is created using the new keyword, the default constructor of the class is called.

The name of the constructor must be similar to the class name. The constructor must not have an explicit return type. The purpose of the default constructor is to assign the default value to the objects. The java compiler creates a default constructor implicitly if there is no constructor in the class. In the above class, you are not creating any constructor, so compiler provides you a default constructor. Here 0 and null values are provided by default constructor.

More Details. Yes, the constructors can be overloaded by changing the number of arguments accepted by the constructor or by changing the data type of the parameters. Consider the following example. In the above program, The constructor Test is overloaded with another constructor. In the first call to the constructor, The constructor with one argument is called, and i will be initialized with the value However, In the second call to the constructor, The constructor with the 2 arguments is called, and i will be initialized with the value There is no copy constructor in java.

In this example, we are going to copy the values of one object into another using java constructor. Here, the data type of the variables a and b, i. The output of the program is 0 because the variable i is initialized to 0 internally. As we know that a default constructor is invoked implicitly if there is no constructor in the class, the variable i is initialized to 0 since there is no constructor in the class.

There is a compiler error in the program because there is a call to the default constructor in the main method which is not present in the class. However, there is only one parameterized constructor in the class Test. Therefore, no default constructor is invoked by the constructor implicitly. The static variable is used to refer to the common property of all objects that is not unique for each object , e. Static variable gets memory only once in the class area at the time of class loading.

Using a static variable makes your program more memory efficient it saves memory. Static variable belongs to the class rather than the object. Because the object is not required to call the static method.

If we make the main method non-static, JVM will have to create its object first and then call main method which will lead to the extra memory allocation.

No, we can't override static methods. Static block is used to initialize the static data member. It is executed before the main method, at the time of classloading. Ans Yes, one of the ways to execute the program without the main method is using static block. As we know that the static context method, block, or variable belongs to the class, not the object. Since Constructors are invoked only when the object is created, there is no sense to make the constructors static.

However, if you try to do so, the compiler will show the compiler error. In Java, if we make the abstract methods static, It will become the part of the class, and we can directly call it which is unnecessary.

Calling an undefined method is completely useless therefore it is not allowed. Yes, we can declare static variables and methods in an abstract method. As we know that there is no requirement to make the object to access the static context, therefore, we can access the static context declared inside the abstract class by using the name of the abstract class.

The this keyword is a reference variable that refers to the current object. There are the various uses of this keyword in Java. It can be used to refer to current class properties such as instance methods, variable, constructors, etc.

It can also be passed as an argument into the methods or constructors.

Answer question java pdf interview core

It can also be returned from the method as the current class instance. No, this cannot be assigned to any value because it always points to the current class object and this is the final reference in Java. However, if we try to do so, the compiler error will be shown. Yes, It is possible to use this keyword to refer static members because this is just a reference variable which refers to the current class object.

240-core-java-interview-questions-and-answers-2.pdf - 240...

However, as we know that, it is unnecessary to access static variables through objects, therefore, it is not the best practice to use this to refer static members. Output 10 55 How can constructor chaining be done using this keyword? Constructor chaining enables us to call one constructor from another constructor of the class with respect to the current class object. We can use this keyword to perform constructor chaining within the same class. Consider the following example which illustrates how can we use this keyword to achieve constructor chaining.

As we know, that this refers to the current class object, therefore, it must be similar to the current class object. However, there can be two main advantages of passing this into a method instead of the current class object. Inheritance is a mechanism by which one object acquires all the properties and behavior of another object of another class.

It is used for Code Reusability and Method Overriding. The idea behind inheritance in Java is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can add new methods and fields in your current class also. Inheritance represents the IS-A relationship which is also known as a parent-child relationship.

In otherwords we can say Exception as run time error.

2018 Latest 60 Java Interview Questions And Answers Pdf

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: 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. From Java 7, we can catch more than one exception with single catch block. This type of handling reduces the code duplication. When we catch more than one exception in single catch block , catch parameter is implicity final. We cannot assign any value to catch parameter.

Skip to content 1. Java Interview Questions And Answers 2.

What is class in Java? What is a JVM? Explain method overloading? Does Java support multiple inheritance? Read Out: Common Interview Mistakes 7. What is a transient variable? A transient variable is a variable that may not be serialized. Is null a keyword? No, the null is not a keyword. Java Interview Questions And Answers 9. These methods have been deprecated in JDK 1.

What is the immediate superclass of the Applet class? The Panel class is the immediate superclass of the Applet class. Can we rethrow the same exception from catch handler? The default value of an String type is null.

Which containers use a Flow Layout as their default layout? Java Interview Questions And Answers Which java. What is the Vector class? What is a native method? What value does read Line return when it has reached the end of a file?

What is clipping? Clipping is the process of confining paint operations to a limited area or shape. Can a for statement loop indefinitely? Explain Java Coding standards for Methods? Explain Java Coding Standards for Constants? Explain Java Coding Standards for variables? Name three Component subclasses that support painting? A final class is a constant value of a final variable.

Extending A final class is not possible ie. A final method cannot be overridden when its class is inherited. Multi-catch block makes the code shorter and cleaner when every catch block has similar code. We can catch multiple exceptions in a single catch block using this feature.

However some of the important features of Java 10 are:. Local-Variable Type Inference Enhance java. Java 10 is mostly a maintenance release, however I really liked the local variable type inference feature. When a class is public, the public class is visible in other packages, the field is visible everywhere. Private variables or methods can be used by an instance of the same class only which declares the variable or method.

A private feature can be accessed by the class that owns the feature. Protected variable is available to all classes in the same package. It is also available to all subclasses of the class that owns the protected feature.

Subclasses that reside in a different package also is provided with the access from the class that owns the protected feature. JVM is responsible for converting byte code into machine readable code. JDK 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. StringBuilder in Java was introduced in Java 5. Enum was introduced in Java 1.

Enum constants are implicitly static and final. Read more in detail at java enum. Java Annotations provide information about the code and they have no direct effect on the code they annotate. Annotations are introduced in Java 5. Annotation is metadata about the program embedded in the program itself.

It can be parsed by the annotation parsing tool or by compiler. We can also specify annotation availability to either compile time only or till runtime also.

Read more at java annotations. Java Reflection API provides ability to inspect and modify the runtime behavior of java application. We can inspect a java class, interface, enum and get their methods and field details. Reflection API is an advanced topic and we should avoid it in normal programming. Reflection API usage can break the design pattern such as Singleton pattern by invoking the private constructor i. They invoke the appropriate methods and instantiate classes through reflection API and use it a lot for other processing.

Method Overloading: In Method Overloading, Methods of the same class shares the same name but each method must have different number of parameters or parameters having different types and order. It is a compile time polymorphism.

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

The methods must have different signature. It may or may not need inheritance in Method Overloading. PATH is an environment variable used by operating system to locate the executables.

Classpath is specific to java and used by java executables to locate class files. We can provide the classpath location while running java application and it can be a directory, ZIP files, JAR files etc. The syntax of main method is public static void main String args[]. The input parameter is an array of String through which we can pass runtime arguments to the java program.

Check this post to learn how to compile and run java program. A static method can access only static variables of class and invoke only static methods of the class. This method is usually overridden to release system resources when object is garbage collected. Abstract classes are used in java to create a class with some default method implementation for subclasses.

An abstract class can have abstract method without body and it can have methods with implementation also. Read important points about abstract classes at java abstract class. The code marker Before is executed before each test, while BeforeClass runs once before the entire test fixture.

Answer interview pdf core java question

If your text class has ten tests, Before code will be executed ten times, but BeforeClass will be executed only once. In general, you would use BeforeClass when numerous tests are required to share the same computationally expensive setup code.

Starting a database connection falls into this category. You are able to move code from BeforeClass into Before, but your test run may be delayed. BeforeClass is run as static initialiser, therefore it will run before the class instance of your test fixture is created.

Core Java Interview Questions | OOPs interview questions - javatpoint

Yes, it is possible to make an array volatile in Java, but only the reference which is pointing to an array, not the whole array. Therefore, if one thread changes the reference variable points to another array, which will provide a volatile guarantee.

If the purpose is to provide memory visibility guarantee for individual indices of the array, volatile is of no practical use for you. Instead, you must rely on an alternative mechanism for thread-safety in that particular case, e.

From the two, which would be easier to write: Both will have the same level of complexity regarding writing the code because synchronisation is independent of the number of threads, although the choice of synchronisation could be subject to the number of threads because this presents more conflict.

Therefore, you would opt for an advanced synchronisation technique, e. A unit tests tests a small isolated piece of code such as a method. An integration test tests how your code plays with other systems, such as a database, a cache or a third-party application.

A functional test is the testing of the complete functionality of an application. This may involve the use of an automated tool to carry out more complex user interactions with your system. Every primitive data type has a class dedicated to it. Refer to the below image which displays different primitive type, wrapper class and constructor argument. Equals method is defined in Object class in Java and used for checking equality of two objects defined by business logic.

For example: 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.