Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Newest | ||||
Very frequently asked in HCL Tech ( Based of 4 inputs ) | ||||
| ||||
Ans. Using String method - new StringBuffer(str).reverse().toString(); Iterative - public static String getReverseString(String str){ StringBuffer strBuffer = new StringBuffer(str.length); for(int counter=str.length -1 ; counter>=0;counter--){ strBuffer.append(str.charAt(counter)); } return strBuffer; } Recursive - public static String getReverseString(String str){ if(str.length <= 1){ return str; } return (getReverseString(str.subString(1)) + str.charAt(0); } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string   reverse   stringbuffer   string class   code Asked in 6 Companies   frequent | ||||
| ||||
Ans. new operator is used to statically create an instance of object. newInstance() is used to create an object dynamically ( like if the class name needs to be picked from configuration file ). If you know what class needs to be initialized , new is the optimized way of instantiating Class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   object instantiation   object creation   class.forname   newinstance   new operator   difference between   advanced intermediate | ||||
| ||||
Ans. 1. Entity classes should have default constructor. 2. Entity classes should be declared non final. 3. All elements to be persisted should be declared private and should have public getters and setters in the Java Bean style. 4. All classes should have an ID that maps to Primary Key for the table. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   entity classes hibernate | ||||
| ||||
Ans. Abstraction is provided in Java by following ways - Coding to the ( Interfaces / Abstract Classes ) or contracts By Encapsulating details within classes and exposing the minimal Door ( few public methods ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops concepts   abstraction   interfaces   abstract class   encapsulation  object oriented programming (oops)  oops concepts Asked in 3 Companies basic   frequent | ||||
Ans. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  oops   java   static   nested classes   static nested classes | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. A trigger is a special kind of stored procedure that automatically gets executed upon an event in the database server. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  database   trigger Asked in 10 Companies basic   frequent | ||||
| ||||
Ans. When a Table Join itself , it's a Self Join. For example - we like to know the pair of department names where first dept has lesser employees than the later. Select D1.name , D2.name from Dept D1, Dept D2 where D1.employee_count < D2.employee_count | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  sql  joins  self join  self-join  Pair of employee names with first having lesser salary than later  Pair of department names where first dept has lesser employees than the later Asked in 26 Companies basic   frequent | ||||
| ||||
Ans. System is a class within java.lang package that contains several useful class fields and methods. It cannot be instantiated and hence can use only statically.even in this case this has been used statically i.e with class name itself and without creating an instance. out is the static reference of Printstream declared as following in the System Class - public final static PrintStream out = null; println is the method of PrintStream class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  System class  Streams  Input Output  println Asked in 1 Companies basic   frequent | ||||
| ||||
Ans. Yes, we can do that. Compiler wont complain. But using object reference we can only access methods which have been defined for object class i.e clone(), equals(), hashCode(), toString() etc. We cannot access methods defined in String class or in any class in hierarchy between String and Object. For example - we cannot do obj.append("abc") as it will now give compile time error. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  object initialization  object declaration   runtime polymorphism  object oriented programming (oops)  oops concepts | ||||
| ||||
Ans. wait and notify are declared final in object class and hence cannot be overridden. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  object class methods  wait  notify | ||||
| ||||
Ans. Though var args are used rarely but they are pretty useful if a method is expected to receive variable number of arguments. For example - it's pretty useful for the main method as the caller has the flexibility to provide arguments in infinite ways.It provides a convenience and flexibility to the caller. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  var args  methods  method declarations  functions | ||||
| ||||
Ans. Abstraction is a process of hiding the implementation details and describing only the functionality to the user. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  bstraction  oops concepts  oops principle Asked in 22 Companies | ||||
| ||||
Ans. No | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  abstract class   multiple inheritance  object oriented programming (oops)  oops concepts Asked in 2 Companies | ||||
| ||||
Ans. Yes, to a certain extent. But the objective for Final class could be beyond just enforcing composition as certain classes might have been created without inheritance or composition in mind. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  final class   composition  object oriented programming (oops)  oops concepts  inheritance  object oriented programming (oops)  oops concepts  composition  object oriented programming (oops)  oops concepts vs inheritance  object oriented programming (oops)  oops concepts expert | ||||
| ||||
Ans. 1. Enforcing composition over inheritance 2. Restricting overriding of certain methods 3. Final methods are faster than regular instance methods 4. Enforcing Immutability | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  final class   reasons for final class   restricting inheritance  object oriented programming (oops)  oops concepts expert | ||||
| ||||
Ans. Base Class is a relative term used to signify the Parent class in Parent - Child or Base - derived relationship. Derived Class is a relative term used to signify the Child class in Parent - Child or Base - derived relationship. Abstract Class is a class that is not allowed to be instantiated and hence can serve only a base class for it's usage. Concrete Class is the class which is supposed to be instantiated and hence provide definition for all implementing interface methods and extending abstract methods. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Base Class   Derived Class   Abstract Class   Concrete Class | ||||
| ||||
Ans. Multiple servlets serving the request in chain. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   web application   servlets Asked in 1 Companies   rare | ||||
Very frequently asked. Usually asked in this format or as difference with interfaces / concrete classes. | ||||
| ||||
Ans. Abstract class is the class that is not supposed to be instantiated. The purpose of the class to only have extension to the derived class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  abstract class Asked in 6 Companies basic   frequent | ||||
| ||||
Ans. They both represent the long primitive type. They are exactly the same. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   data types   long.Class   long.TYPE   advanced expert   rare | ||||
| ||||
Ans. Sometime we just need classes or class objects just to be used as part of a particular class or objects. Making them non nested won't make any difference as far as functionality is concerner but making them Nested provide a level of convenience and protection fro, being used anywhere else. Moreover it helps reducing the Code. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   inner classes   nested class   inner class Asked in 2 Companies | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. loadClass only loads the class but doesn't initialize the object whereas Class.forName initialize the object after loading it. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   class loaders   jvm   advanced | ||||
| ||||
Ans. System.console() returns null if your application is not run in a terminal (though you can handle this in your application)System.console() provides methods for reading password without echoing charactersSystem.out and System.err use the default platform encoding, while the Console class output methods use the console encoding | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   system class   system.out.println   system.console.write   input output   java6 intermediate   rare | ||||
| ||||
Ans. You can put related classes together as a single logical group. Nested classes can access all class members of the enclosing class, which might be useful in certain cases. Nested classes are sometimes useful for specific purposes. For example, anonymous inner classes are useful for writing simpler event-handling code with AWT/Swing. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   nested classes   inner classes   oops   classes | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. The accessibility (public, protected, etc.) of the static nested class is defined by the outer class. A static nested class is not an inner class, it's a top-level nested class. The name of the static nested class is expressed with OuterClassName.NestedClassName syntax. When you define an inner nested class (or interface) inside an interface, the nested class is declared implicitly public and static. Static nested classes can be declared abstract or final. Static nested classes can extend another class or it can be used as a base class. Static nested classes can have static members. Static nested classes can access the members of the outer class (only static members, obviously). The outer class can also access the members (even private members) of the nested class through an object of nested class. If you don't declare an instance of the nested class, the outer class cannot access nested class elements directly. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   nested classes   static nested classes   inner classes | ||||
| ||||
Ans. The accessibility (public, protected, etc.) of the inner class is defined by the outer class. Just like top-level classes, an inner class can extend a class or can implement interfaces. Similarly, an inner class can be extended by other classes, and an inner interface can be implemented or extended by other classes or interfaces. An inner class can be declared final or abstract.Inner classes can have inner classes, but you will have a hard time reading or understanding such complex nesting of classes. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   classes   inner classes Asked in 2 Companies Basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. You can create a non-static local class inside a body of code. Interfaces cannot have local classes, and you cannot create local interfaces. Local classes are accessible only from the body of the code in which the class is defined. The local classes are completely inaccessible outside the body of the code in which the class is defined. You can extend a class or implement interfaces while defining a local class. A local class can access all the variables available in the body of the code in which it is defined. You can pass only final variables to a local inner class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   inner classes   local classes   classes   method local inner classes Asked in 1 Companies | ||||
| ||||
Ans. Anonymous classes are defined in the new expression itself, so you cannot create multiple objects of an anonymous class. You cannot explicitly extend a class or explicitly implement interfaces when defining an anonymous class. An anonymous inner class is always created as part of a statement; don't forget to close the statement after the class definition with a curly brace. This is a rare case in Java, a curly brace followed by a semicolon. Anonymous inner classes have no name, and their type must be either a subclass of the named type or an implementer of the named interface | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   inner classes   anonymous inner classes   classes Asked in 1 Companies | ||||
| ||||
Ans. Yes , using Class.getInstance. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor   default constructor   class.getinstance | ||||
| ||||
Ans. A class is a blue print or Mold using which individual objects are created. A class can contain fields and methods to describe the behavior of an object. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   class   basic interview question Asked in 1 Companies basic   frequent | ||||
| ||||
Ans. The Exception class has two main subclasses : IOException class and RuntimeException Class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   exceptions   exception class   ioexception   runtimeexception | ||||