JAVA Interview questions and answers in short.

0

 

Top 25 JAVA Interview questions and answers in short.


 

  • 1.    What are the differences between C++ and java?
  • 2.   Four pillars of java?
  • 3.   What is abstraction?
  • 4.   How we can achieve multiple inheritance in java.
  • 5.   What is method overloading in java?
  • 6.   What is method overriding in java?
  • 7.   What is interface?
  • 8.   What is mean by polymorphism?
  • 9.   What is inheritance and its types in java?
  • 10. What is collection in java?
  • 11.  Why we use collection in java?
  • 12.  What is static in java?
  • 13.   What is thread?
  • 14.   How many ways we can create thread in java?
  • 15.   What is multithreading in java?
  • 16.   Difference between multithreading and multitasking?
  • 17.    List the features of the Java Programming language?
  • 18.   What is object-oriented paradigm?
  • 19.  What is an Object?
  • 20.  What is the constructor?
  • 21.   How many types of constructors are used in Java?
  • 22.   What is the purpose of a default constructor?
  • 23.   Can we override the static methods?
  • 24.    This keyword uses?
  • 25.    What is interface in java?
  • 26. what is exception in java?
  • 27.What is exception handling?
  • 28.types of exception in java?
  • 28.what is  palindrome string?
  • what is mean by encapsulation?
  • what is an ArrayList list in java?
  • purpose of encapsulation in java?
  • what is collection frame work in java?

ANSWERS-


Q. What are the differences between C++ and java?

         C++ is only a compiled language while Java is both compiled and interpreted. C++ is platform dependent and Java is platform independent language.

 

Q. Four Pillars of java?

  1.Inheritance.

  2.Polymorphism.

  3.Abstraction.  4.Encapsulation

1.Inheritance :  is a concept that acquires the properties from one class to other classes.

2. Polymorphism :  is a "many forms", and it occurs when we have many classes that are related to each other by inheritance. Further it’s divided into two Types Compile-time polymorphism and Runtime polymorphism.

3.Abstraction : it is the process of hiding complex parts and showing only essential details. There are two ways to achieve abstraction in java 1.by using interface  2. By using Abstract class.

      4.Encapsulation : is the process of wrapping data and methods into a single unit. the purpose of encapsulation is to hide the data.

    


 Q. What is abstraction?

             It is the process of hiding complex parts and showing only essential details. There are two ways to achieve abstraction in java 1.by using interface and 2. By using Abstract class.

 


Q. How can we achieve multiple inheritance in java.

               In Java we can achieve multiple inheritance by using interfaces.

 


 Q. What is method overloading in java?

           In class If we have two or more than two same name methods but different in the parameter list is called method Overloading.

 


Q. What is method overriding in java?

        method overriding occurs when a subclass (child class) has the same method as the parent class. In other words, method overriding occurs when a subclass provides a particular implementation of a method declared by one of its parent classes.

 


   Q. What is the interface?

        Interface is the same as class, it is the blueprint of class. It is a collection of abstract methods. We cannot instantiate an interface.

The purpose of the interface is to achieve abstraction 100%.

 


Q. What is inheritance and its types in java?

 is a concept that acquires the properties from one class to other classes.

1.Single inheritance

2.Multilevel inheritance

3.Hierarchical inheritance

4.Hybrid inheritance




Q.  What is a collection in java?

            A Collection represents a single unit of objects, i.e., a group.

A collection framework

 is The Collection framework represents a unified architecture for storing and manipulating a group of objects.

 


Q. Use of collection in java?

 one-stop solutions for all the data manipulation jobs such as storing data, searching, sorting, insertion, deletion, and updating of data.

 


Q. What is static in java?

            Static Keyword is used in Memory management and whenever we don’t want to create an Object for our class then we use a static keyword.

 It can be used with variables, methods, blocks and nested classes.

 


 Q. What is thread?

            Typically, we can define threads as a sub-process lightweight with the smallest unit of processes and also has separate paths of execution.

 


Q. How many ways can we create threads in java?

There are two ways to create thread in java

1.    extends Thread class.

2.    implement Runnable interface.

 


 Q. What is multithreading in java?

       a process of executing two or more threads simultaneously for maximum utilization of the CPU.




Q. Difference between multithreading and multitasking?

 Multitasking requires the CPU to move between various programs so that it looks like multiple processes are running concurrently. On the other hand, in multithreading, the CPU must switch between various threads to make it appear like all threads are working concurrently.

 


Q. List the features of the Java Programming language?

1.    Simple

2.    Object-Oriented

3.    Portable

4.    Platform independent

5.    Secured

6.    Robust

7.    Architecture neutral

8.    Interpreted

9.    High Performance

10.   Multithreaded

11.    Distributed

12.    Dynamic



Q. What is object-oriented programming?

Object-oriented programming (OOP) is a programming paradigm based upon objects (having both data and methods) that aims to incorporate the advantages of modularity and reusability. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs. 

Follows Bottom–up approach in program design.

 


 Q. What is an object?

    An object is called an instance of a class. 

Examples

1.your cycle

2.your watch

3.mobile

So on……



Q. What is the constructor?

  Constructor is a Special type of method in Java. Constructor is called automatically when an object of the class is created. The main purpose of the constructor is to initialize objects.

 


Q.  How many types of constructors are used in Java?

 There are two types of constructors in java

1.  Default constructor (no-argument constructor).

2.  Parameterized constructor.

 




Q.  What is the purpose of a default constructor?

  Whenever we don’t create any constructor for class the compiler automatically adds default constructor for initializing the attributes of the object with their default values.

 

 

Q. Can we override the static methods?

           The answer is No. We can't override static methods.

   



Q. What is an exception in java?

 Exception is an event, Which occurs at time of execution  of a program which disturbs the normal flow of the program is called an exception.




Q. What is exception handling in java?

       Exception handling is the mechanism through which we handle runtime errors for smooth execution of the program.






Q. Types of exceptions in java?

            There are two types of exception in java 

               1.Checked exception

                2. Unchecked exception




 Q. What is the use of this keyword in java?

  • invoke current class constructor

  • invoke current class method

  • Return the current class object



   Q. What is an array?

       array is an Object in java which contains elements of a similar data  type the elements are stored in a contiguous memory location.



 Q. Types of arrays in java?

  1.Single dimensional array

   2.Multi - dimensional array




 Q. What is JDBC

            JDBC stands for java database connectivity. It is the API to connect and execute queries with the database.




Q. Steps to java database connectivity?

1.Register the driver class

2.Create the connection Object

3.Create the statement Object

4.Execute the query

5.Close the Connection




 Q. Why is String immutable in java?

 For the security purpose String is immutable in java because First thing is String class is final in java and second String Objects are cached  in String constant pool which makes String Immutable.

java provides two other classes to String Buffer and String Builder class which is mutable to represent sequences of characters. They provide methods to do  manipulation with strings.




Q. What is the interface in java?

 Interface is the same as the class. It has static constants variables and abstract methods that don't contain body.by using interface we can achieve Multiple inheritance property.




Q. What is Encapsulation in java?

is a process of wrapping code and data together into a single unit, for example, a capsule which is mixed with several medicines.

provides you the control over the data.

It is a way to achieve  data hiding  in java.

Encapsulate class is easy to test.




Q. What is an ArrayList list in java?

ArrayList in Java is a class that implements the List interface and allows dynamic resizing of arrays. It is part of the Java Collections Framework and provides an efficient way to store and manipulate data in a list format. The ArrayList class is similar to an array but has additional methods to insert, remove, and search for elements. It also automatically resizes itself as elements are added or removed, making it more flexible than a traditional array. ArrayLists can store any type of object and are commonly used in Java programming for tasks that require dynamic data storage and manipulation.




Q. The purpose of encapsulation in java?

  1. Encapsulation allows the programmer to hide the internal details of an object and

  2. expose only the necessary features to the outside world.

  3. Encapsulation provides a mechanism to control the access to data stored

  4. within an object, preventing unwanted modifications or manipulations.

  5. Encapsulation helps in creating reusable code by preventing accidental

  6. modification of the internal state of an object.

  7. Encapsulation improves the security of the code by preventing external

  8. access to private or sensitive data.

  9. Encapsulation promotes modular programming by enabling a separation of

  10. interface and implementation details.

  11. Encapsulation allows for the implementation of data abstraction, which means

  12. that a class can define the essential characteristics of an object without

  13. revealing the implementation details.

  14. Encapsulation enables the implementation of the principle of information hiding,

  15. which means that the internal details of an object can be hidden from the outside

  16. world.

  17. Encapsulation makes it easier to maintain and modify code by encapsulating the

  18. implementation details of an object within a class.

  19. Encapsulation enhances the reliability of the code by preventing direct access

  20. to the internal state of an object and reducing the risk of unintended side effects.

  21. Encapsulation is a core principle of object-oriented programming and is essential

  22. for creating robust, reusable, and maintainable code.




Q. What is the collection framework in java?


      The Collection framework in Java is a set of classes and interfaces that provides a unified and efficient way to store and manipulate groups of objects. It includes data structures such as lists, sets, maps, and queues, as well as algorithms for sorting, searching, and manipulating collections.






JAVA PROGRAMS

Basic String Program

Q.  String concatenation Simple Program



 Q. What is a palindrome string ?

            A string is said to be a palindrome if and only if the reverse of the string is exactly equal to the original string.


       

Q.  program to Check if the given string is palindrome or not.



Q. program to Reverse a string







 


Post a Comment

0Comments
Post a Comment (0)