Javatpoint java interview questions pdf

Thursday, June 6, 2019 admin Comments(0)

Download as PDF, TXT or read online from Scribd. Flag for Core Java Interview Questions | OOPs interview questions ‐ javatpoint. Content Menu. Core Java Interview Questions _ OOPs Interview Questions - Javatpoint - Download as PDF File .pdf), Text File .txt) or read online. IQ. Core Java Interview Questions | OOPs interview questions - javatpoint Java . Java 10 Free Java Programing Books for beginners - download, pdf and.

Language: English, Spanish, Indonesian
Country: San Marino
Genre: Personal Growth
Pages: 100
Published (Last): 25.11.2015
ISBN: 813-8-79215-367-3
ePub File Size: 19.87 MB
PDF File Size: 18.71 MB
Distribution: Free* [*Regsitration Required]
Downloads: 37223
Uploaded by: KAZUKO

There is the list of core java interview questions. If there is any core java interview question that has been asked to you, kindly post it in the ask question. Interview Questions for beginners and professionals with a list of top frequently asked interview questions and answers on job, hr, competency, java, database. 3/30/ Core Java Interview Questions | OOPs interview questions javatpoint 1/ Core Java.

No these are correct, please check your code. We can use break with label to terminate the nested loops. Method overloading increases the readability of the program. The continue statement skips the current iteration of a for, while or do-while loop. Can we use String with switch case?

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. 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.

201 Core Java Interview Questions _ OOPs Interview Questions - Javatpoint

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. 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.

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. To reduce the complexity and simplify the language, multiple inheritance is not supported in java. Consider a scenario where A, B, and C are three classes. The C class inherits A and B classes. If A and B classes have the same method and you call it from child class object, there will be ambiguity to call the method of A or B class.

Since the compile-time errors are better than runtime errors, Java renders compile-time error if you inherit 2 classes. So whether you have the same method or different, there will be a compile time error. Aggregation can be defined as the relationship between two classes where the aggregate class contains a reference to the class it owns.

Aggregation is best described as a has-a relationship. For example, The aggregate class Employee having various fields such as age, name, and salary also contains an object of Address class having various fields such as Address-Line 1, City, State, and pin-code. In other words, we can say that Employee class has an object of Address class. Holding the reference of a class within some other class is known as composition. When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition.

In other words, we can say that composition is the particular case of aggregation which represents a stronger relationship between two objects. A class contains students. A student cannot exist without a class. There exists composition between class and students. Aggregation represents the weak relationship whereas composition represents the strong relationship.

For example, the bike has an indicator aggregation , but the bike has an engine composition. The pointer is a variable that refers to the memory address.

They are not used in Java because they are unsafe unsecured and complex to understand. The super keyword in Java is a reference variable that is used to refer to the immediate parent class object. Whenever you create the instance of the subclass, an instance of the parent class is created implicitly which is referred by super reference variable. The super is called in the class constructor implicitly by the compiler if there is no super or this.

The super is implicitly invoked by the compiler if no super or this is included explicitly within the derived class constructor. Therefore, in this case, The Person class constructor is called first and then the Employee class constructor is called. The object cloning is used to create the exact copy of an object.

The clone method of the Object class is used to clone an object. The java. Cloneable interface must be implemented by the class whose object clone we want to create. Method overloading is the polymorphism technique which allows us to create multiple methods with the same name but different signature.

We can achieve method overloading in two ways. Method overloading increases the readability of the program. Method overloading is performed to figure out the program quickly. In Java, method overloading is not possible by changing the return type of the program due to avoid the ambiguity. No, We cannot overload the methods by just applying the static keyword to them number of parameters and types are the same.

By Type promotion is method overloading, we mean that one data type can be promoted to another implicitly if no exact matching is found. As displayed in the above diagram, the byte can be promoted to short, int, long, float or double. The short datatype can be promoted to int, long, float or double.

The char datatype can be promoted to int, long, float or double and so on. There are two methods defined with the same name, i. The first method accepts the integer and long type whereas the second method accepts long and the integer type. Inner classes are associated with the object of the class and they can access all the variables and methods of the outer class. We can have local inner class or anonymous inner class inside a class.

For more details read java inner class. A local inner class without name is known as anonymous inner class. An anonymous class is defined and instantiated in a single statement. Anonymous inner class always extend a class or implement an interface.

Since an anonymous class has no name, it is not possible to define a constructor for an anonymous class. Anonymous inner classes are accessible only at the point where it is defined. Java Classloader is the program that loads byte code program into memory when we want to access any class. We can create our own classloader by extending ClassLoader class and overriding loadClass String name method.

Learn more at java classloader. Java ternary operator is the only conditional operator that takes three operands. We can use ternary operator if-else conditions or even switch conditions using nested ternary operators. An example can be found at java ternary operator.

We can use super keyword to invoke superclass constructor in child class constructor but in this case, it should be the first statement in the constructor method. We can use break statement to terminate for, while, or do-while loop. We can use break statement in switch statement to exit the switch case. You can see the example of break statement at java break. We can use break with label to terminate the nested loops. The continue statement skips the current iteration of a for, while or do-while loop.

We can use the continue statement with the label to skip the current iteration of the outermost loop. No argument constructor of a class is known as default constructor.

Yes, we can have try-finally statement and hence avoiding catch block. Garbage Collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects.

In Java, process of deallocating memory is handled automatically by the garbage collector. We can run the garbage collector with code Runtime. We can convert a Java object to an Stream that is called Serialization. Once an object is converted to Stream, it can be saved to file or send over the network or used in socket connections. The object should implement Serializable interface and we can use java.

ObjectOutputStream to write object to file or to any OutputStream object. Read more at Java Serialization. The process of converting stream data created through serialization to Object is called deserialization. Read more at Java Deserialization.

We can run a jar file using java command but it requires Main-Class entry in jar manifest file. Main-Class is the entry point of the jar and used by java command to execute the class. Learn more at java jar file. Java System Class is one of the core classes. One of the easiest way to log information for debugging is System. Some of the utility methods of System class are for array copy, get the current time, reading environment variables.

Read more at Java System Class. We can use instanceof keyword to check if an object belongs to a class or not. Sample usage is:. Since str is of type String at runtime, first if statement evaluates to the true and second one to false. One of the Java 7 feature was improvement of switch case of allow Strings. So if you are using Java 7 or higher version, you can use String in switch-case statements. Read more at Java switch-case String example.

This is a very confusing question, we know that object variables contain the reference to the Objects in heap space. When we invoke any method, a copy of these variables is passed and gets stored in the stack memory of the method.

For a detailed explanation with a sample program, read Java Heap vs Stack Memory. The task of java compiler is to convert java program into bytecode, we have javac executable for that.

Note that Object class has toString method.

Interview pdf questions java javatpoint

Well this is a strange situation. The reason for this is the java compiler code optimization. When the java code is compiled to produced byte code, it figures out that foo is a static method and should be called using class. So it changes the method call obj. If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Facebook or Twitter.

I would love to hear your thoughts and opinions on my articles directly. Recently I started creating video tutorials too, so do check out my videos on YouTube.

I am so greatfull that you have shared all questions and answers. It helped me a lot. Thank u so much Sir. In answer 30 you say: Hey today morning I appeared for an aptitude test. Trust me I found most of the questions on your site. I wish I had seen this site 1 day before. But by chance I happened to Practically implemented it the nigh before. This dichotomy got me to thinking! Or that I need to revise something to use it.

It is this progress that feeds back into what I learned previously, informs my earlier knowledge and enhances my revision of the core ideas when I need to reutilise them again.

This is the secret to keeping knowledge truly vital alive and in use. The same old ideas acquire a new context! This is the true test of ability. Cannot thank you enough. I would say to add more and more questions and answers here. Always stay motivated to write posts to assist people like us. It is very useful… very nice questions thanks for sharing with us.. In this you will get latest java Interview Questions ……and many more contents to come.

Is the statement correct on question 27? Java 8 has enabled method implementation for interface using default keyword. And I think Diamond problem can happen if a given interface extends two interfaces which have the same default methods. Thanks for pointing it out, the answer had to be updated for Java 8 changes. Great stuff, just great! Many important questions are covered here.

Very impressed with your core Java interview questions and answers post with concise to the point answers.

Very handy to brush up. Keep up the good work. I have a doubt on question 5. JVM is an abstract thing which would have no physical existence. In fact JVM does not have any knowledge of Java language per se, All it understands is the byte code of.

Hi Pankaj Thank you for your great site and wonderful explanation. I am a newbie and benefited a lot from your site. I have real difficulty understanding the last question. I am able to use static object methods in my own programs and no exception returned.

I even copy paste your program to my own IDE and saw the error but after changing the method name ,the error disappeared.. I really need any help here. I have updated the explanation of questions. Note that toString method is present in Object class and hence the error. Since you changed the name of method, this conflict is not there and no error.

For second part, explanation is very clear. Because of compiler optimization of byte code, we are not getting exception since it changes from object to Class reference while calling static method.

Thanks Pankaj for your explanation , now it is more clear. You might want to add the the fact at the fact that static methods can not be overridden but can be hidden and the reason for that. I truly appreciate your efforts in writing the answers.

Please look into Question Provided link is not working. Very helpful to get all concept brushed up on a single page. Last one question was mind-blowing! This is very very helpful post for people like me for preparing interview. Also, very good and descriptive answer for all questions. Hi Pankaj, In one of my recent interview I got a question how java is able to identify errors while compilation with mentioning line numbers of error. My answer was Java compiler is capable of finding such errors while compiling.

But still interviewer is not convenient. Can you help me to answer this in better way and let me know how compiler internally works to identify syntax or semantics errors? Tell me the difference between encapsulation and abstraction , where those concepts are implemented. If key then my next question is then what is exact difference between keyword and operator and when we can say this is an operator or this is a keyword?

Questions pdf java interview javatpoint

Minor correction to Garbage Collector performs automatic memory management. See Java Memory Management specification for details.

I would be great to add also the new features of java 7, even if is not the latest version it was some relevant adds compared with java 6. But all these three are banned sites in offices. We would be very great full, if you somehow find a solution for this problem.

Close your browser, clear your browser cache and start again. You will have access to all questions. Much Appreciated … great set of questions..

Top 75 Java Interview Questions You Must Prepare In 2019

Executing the code which you have written dint throw any error. Instead of toString i was using someother method name. Thanks for the good article. I m really happy by seeing this site just by refering this site we can glance up with java concepts for interview.

Since int is primitive data type, the value is used for comparison and hence TRUE in last two statements. Really impressive.. Java Tricky Programming Questions — comments. Please go through questions 18,19,20 from https: I think this is a basic interview questions which you have listed above but I hope these all have to be in different way for experienced guys. I give you one example over here so that you can assume my thought as mentioned below. For more exception related interview questions, please read https: Hi Pankaj, Hats off….

Its a very nice material which helps a lot. I am unable to see answers from 15th to 52nd question. Could you please help me on that. It works on Google Chrome, Firefox, Safari and all the leading browsers. I have tested it myself. Very hrlpful site.

This is site is best place to prepare interviews without opening any book. You can try to post all like J2ee, Framework, Database also.. It was great useful for us…. In question no 48 u specified that …System class is final and static ……. Is it System class static?

Great article! Very good selection of questions and short and clear answers. Loved it! Thanks for sharing!!! Aggregation is an association in which one class belongs to a collection. This is a part of a whole relationship where a part can exist without a whole. Aggregation has a weaker relationship. Composition is an association in which one class belongs to a collection.

This is a part of a whole relationship where a part cannot exist without a whole. If a whole is deleted then all parts are deleted.

So composition has a stronger relationship. Thanks for Posting these questions. They are really helpful. Just a very little correction in Ans We can use super keyword to invoke super class constructor in child class constructor but in this case it should be the FILE statement in the constructor method. Will you please let me know the difference between portability and platform independency because in portability we can also run the same source code on different OS.

We can run a C program on window, linux and DOS. I believe in inheritance you can use access modifier to restrict subclass from using its respective methods. Your email address will not be published. Leave this field empty. I would love to connect with you personally. You are here: I recently published the core java quiz of 21 questions. It has been taken by more than people with an average score of You should take that and try to get your name into the leaderboard.

Core Java Quiz. Previous Struts2 Interview Questions and Answers. Comments I am so greatfull that you have shared all questions and answers.

This is amazing work.

Interview Questions and Answers - javatpoint

Very nice collection on Java interview questions and answers. Amazing questions and very good explanation, appreciate the effort you have put for this. Just understanding them and memorising them over and over makes you just a circus performer. For instanceof operator both the operands must have some relation. Very concise answers to the point. Thank you for helping us to understand java… Helps a lot.

I l most shocked by the last two responses keep on regards. Hello Pankaj, Nice article to revise core java. Please add questions about java collection package also. Thank you,. This article really helped me to revise concepts in core Java. Highly appreciated.

It really helped in the Java interview! Pankaj, Very impressed with your core Java interview questions and answers post with concise to the point answers. It is very helpful for me to crack the core java interviews. Hi, I have a doubt on question 5. Please suggest what you think on this?

Thank You Pankaj for sharing this with us. It is very helpful for core java interview. Hi Sam, I have updated the explanation of questions. Hi Pankaj, I truly appreciate your efforts in writing the answers. Thanks for pointing it out, I have corrected the link. Pankaj, Can you answer or someone my question? Web services are also covered in detail, please check below link.

You have to use subclass of the Abstract class that implements all the abstract methods. We can initiate the object for the Abstract class but we can run the class with main method. Thanks for the article. Hi , Thanks a lot.. Dear Sir, Hands off to you. This is really helpful for any java professionals.

Thank you for all the time dedicated to your site. Same problem here too……….