Java Interview Questions And Answers Pdf Yes, We can execute any code, even before the main method. We are using a static block. In this guide we will discuss about different types of questions that can be used in a Java interview, in order for the employer to test your skills in Java and. 5) Difference between method overloading and method overriding in java? . .. 9. 6) Difference . Core java Interview questions on Coding Standards.

    Author:JAZMIN DUTTWEILER
    Language:English, Spanish, Japanese
    Country:Kosovo
    Genre:Business & Career
    Pages:498
    Published (Last):12.03.2016
    ISBN:292-2-77113-337-6
    Distribution:Free* [*Sign up for free]
    Uploaded by: JOHNNA

    70875 downloads 159825 Views 28.34MB PDF Size Report


    Java Interview Question With Answer Pdf

    Dear readers, these Java Interview Questions have been designed the subject and later they continue based on further discussion and what you answer −. I was getting a lot of emails and comments to create java interview questions and answers PDF eBook. It was hard and time taking, but finally, it's done. Moreover, many interview questions have different solutions. This book popular programming languages (C, C++, C#, and Java) are discussed in Chapter 2.

    What is the difference between abstract classes and interfaces? What is inheritance in Java? Inheritance in Java is the concept where the properties of one class can be inherited by the other. It helps to reuse the code and establish a relationship between different classes. Inheritance is performed between two types of classes: Parent class Super or Base class Child class Subclass or Derived class A class which inherits the properties is known as Child Class whereas a class whose properties are inherited is known as Parent class. What are the different types of inheritance in Java? Java supports four types of inheritance which are: Single Inheritance: In single inheritance, one class inherits the properties of another i. Multilevel Inheritance: When a class is derived from a class which is also derived from another class, i.

    Java doesn't support multiple inheritance. Because we cannot use different methods in one class it creates an ambiguity. Are constructors inherited? Can a subclass call the parent's class constructor? We cannot inherit a constructor. We create an instance of a subclass using a constructor of one of its superclass.

    Because override the superclass constructor is not our wish so that, we override a superclass constructor, then we destroy the encapsulation abilities of the language. Check the insightful tutorial to learn more about Java Constructors. Define JSON?

    It is an independent and easily parse-able in all programming languages. It is primarily used for Communicating between client — server or server -server communication.

    It is a much lighter and readable alternative to XML. Easy to parse and conversion to objects for information consumption. Name the methods of Object Class? Read this tutorial to learn more about Java Methods.

    Define content negotiation? If we have visited website to searching the information, we will get the information in different languages and in different formats when a client makes an HTTP request to a server, the client can also specify the media types here. The client can specify what it can accept back from the host and on the basis of availability the host will return to the client. This is known as content negotiation because client and server negotiated on the language and format of the content to be shared.

    Will the JVM load the package twice at runtime? A package or class can be inherited multiple times in a program code. JVM and compiler will not create any issue. Moreover JVM automatically loads the class internally once regardless of times it is called in the program.

    Define Abstract class?

    2018 Latest 60 Java Interview Questions And Answers Pdf

    A class which contains the abstract keyword in its declaration is known as abstract class. It can have abstract and non-abstract methods method with body. This class can have public, private, protected or constants and default variables.

    It needs to be extended and its method implemented. It cannot be instantiated. If a class has at least one abstract method, then the class must be declared abstract. Describe the Annotations. Java Annotations is a tag which symbolizes metadata associated with class, interface, methods, fields, etc. Annotations do not directly influence the operations.

    The additional information carried by annotations are utilized by java compiler and JVM. Java doesn't use pointers. Pointers are susceptible and slight carelessness in their use may result in memory problems and hence Java basically manages their use.

    Distinguish between static loading and dynamic class loading? Dynamic class loading — It is a technique for programmatically invoking the functions of a class loader at run time.

    The syntax isClass. Struts 1 actions are a singleton. So all threads operate on the single action object and hence make it thread-unsafe. Struts 2 actions are not a singleton and a new action object copy are created each time a new action request is made and hence it threads safe.

    Define an enumeration? Usually, we called enumeration as an enum. An enumeration is an interface containing methods for accessing the original data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in the collection.

    How can we find the actual size of an object on the heap? What is ternary operator? Ans: Ternary operator , also called conditional operator is used to decide which value to assign to a variable based on a Boolean value evaluation. It's denoted as? In the below example, if rank is 1, status is assigned a value of "Done" else "Pending".

    Ans: Using Math.

    What is default switch case? Give example. Ans: In a switch statement, default case is executed when no other switch condition matches. Default case is an optional case. It can be declared only once all other switch cases have been coded. In the below example, when score is not 1 or 2, default case is used. What's the base class in Java from which all classes are derived? Ans: java.

    Can main method in Java can return any data? Ans: In java, main method can't return any data and hence, it's always declared with a void return type. What are Java Packages? What's the significance of packages? Ans: In Java, package is a collection of classes and interfaces which are bundled together as they are related to each other. Use of packages helps developers to modularize the code and group the code for proper re-use.

    Once code has been packaged in Packages, it can be imported in other classes and used. Can we declare a class as Abstract without having any abstract method? Ans: Yes we can create an abstract class by using abstract keyword before class name even if it doesn't have any abstract method. However, if a class has even one abstract method, it must be declared as abstract otherwise it will give an error.

    What's the difference between an Abstract Class and Interface in Java? Ans: The primary difference between an abstract class and interface is that an interface can only possess declaration of public static methods with no concrete implementation while an abstract class can have members with any access specifiers public, private etc with or without concrete implementation.

    Another key difference in the use of abstract classes and interfaces is that a class which implements an interface must implement all the methods of the interface while a class which inherits from an abstract class doesn't require implementation of all the methods of its super class. A class can implement multiple interfaces but it can extend only one abstract class.

    What are the performance implications of Interfaces over abstract classes? Ans: Interfaces are slower in performance as compared to abstract classes as extra indirections are required for interfaces.

    Another key factor for developers to take into consideration is that any class can extend only one abstract class while a class can implement many interfaces. Use of interfaces also puts an extra burden on the developers as any time an interface is implemented in a class; developer is forced to implement each and every method of interface. Does Importing a package imports its sub-packages as well in Java? Ans: In java, when a package is imported, its sub-packages aren't imported and developer needs to import them separately if required.

    For example, if a developer imports a package university. To load the classes from its sub-package say department , developer has to import it explicitly as follows: Import university. Can we declare the main method of our class as private? Ans: In java, main method must be public static in order to run any application correctly.

    If main method is declared as private, developer won't get any compilation error however, it will not get executed and will give a runtime error.

    How can we pass argument to a function by reference instead of pass by value? Ans: In java, we can pass argument to a function only by value and not by reference.

    How an object is serialized in java? Ans: In java, to convert an object into byte stream by serialization, an interface with the name Serializable is implemented by the class. All objects of a class implementing serializable interface get serialized and their state is saved in byte stream.

    When we should use serialization? Ans: Serialization is used when data needs to be transmitted over the network. Using serialization, object's state is saved and converted into byte stream. The byte stream is transferred over the network and the object is re-created at destination. Ans: Try block needs to be followed by either Catch block or Finally block or both. Any exception thrown from try block needs to be either caught in the catch block or else any specific tasks to be performed before code abortion are put in the Finally block.

    Is there any way to skip Finally block of exception even if some exception occurs in the exception block? Ans: If an exception is raised in Try block, control passes to catch block if it exists otherwise to finally block. Finally block is always executed when an exception occurs and the only way to avoid execution of any statements in Finally block is by aborting the code forcibly by writing following line of code at the end of try block: System.

    2018 Latest 60 Java Interview Questions And Answers Pdf

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

    Answer: The readLine method returns null, 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? Answer: Yes, a for statement can loop indefinitely. For example, consider the following:for ;;. Explain Java Coding standards for Methods? Answer: 1 Method names should start with small letters. Explain Java Coding Standards for Constants?

    Answer: Constants in java are created using static and final keywords.

    + Java Interview Questions Answers for 2 to 7 Year Experienced Programmers

    What is synchronization and why is it important? Answer: The term synchronization is the ability to control the access of multiple threads to shared resources. This often leads to major errors. Explain Java Coding Standards for variables?

    Answer: 1 Variable names should start with small letters. Ex : string,value,empName,empSalary Name three Component subclasses that support painting? Why Java is not pure Object Oriented language? Answer: Java support primitive types such as int, byte, short, long etc that why it is not said to be pure object oriented language. What are access modifiers? Answer: Java provides three access controlssuch as public, private and protected access modifier.

    Can we overload main method? Answer: Yes, we can overload the main methodwith syntax as public static void main String args[].

    Related:


    Copyright © 2019 sturunemcoto.ga.