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 | ||||
| ||||
Ans. ClassPath is the path where Java looks for class files to resolve the dependencies. For example - If you are using a class "xyz" in your code and have specified the respective import, Where should Java look for the definition of xyz. Java determines using the class path settings. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   classpath   classpath settings Asked in 2 Companies | ||||
| ||||
Ans. Class without any access specifier has the default scope i.e it can be accessed by any class within same package. Class declared public can be accessed from anywhere. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   access specifier   access modifiers   public class   class | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. No. It will give the compilation error saying "The abstract method test in type BuggyBread1 can only be defined by an abstract class". We need to declare the class abstract for it to have any abstract method. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   abstract class   abstract methods   java compilation error | ||||
| ||||
Ans. No. This will give a compilation error saying "Abstract methods do not specify a body". | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   abstract classes   abstract methods   java compilation error   java coding   java code   coding   yes-no | ||||
| ||||
Ans. http://www.buggybread.com/2015/02/java-util-classes-that-inherit-number.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   data types   number class | ||||
| ||||
Ans. http://www.buggybread.com/2015/02/java-threads-classes-that-inherit.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multithreading   thread class Asked in 1 Companies | ||||
| ||||
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-inherit.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   collections class | ||||
| ||||
Ans. To avoid ClassCastException. Though the following code will compile fine but will result in ClassCastException during runtime. Fruit fruit = new Apple(); Banana banana = Banana(fruit); // ClassCastException This code will not give compile time error as Banana and Fruit are related as Banana either extends or implement Fruit, So downcasting is acceptable. With this code we assume that the Fruit handler will have the Apple object at that point, violating which the code will throw the exception. This exception can be avoided by following code. Fruit fruit = new Apple(); if(fruit instanceOf Banana){ Banana banana = Banana(fruit); // ClassCastException } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   instanceof   classcastexception   runtime exceptions  instanceOf operator | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Class can be better seen as Data Type. This could be implemented as a Data Structure too in some cases. One thing worth understanding here is that Data type and Data structure are conceptual things. Class could be implementation of either of these. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   class   data type   data structure | ||||
| ||||
Ans. Yes, but there can be only 1 public class in a single file. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   classes | ||||
| ||||
Ans. Method Nested Static Inner Class | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   classes   inner classes | ||||
Try 1 Question(s) Test | ||||
Ans. Singleton class instance is initiated using new keyword whereas static class instance is created using static method. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   singleton   design pattern   static class | ||||
Ans. Runtime Polymorphism | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  static class   static vs singleton   java   oops   objects  Runtime Polymorphism | ||||
Must know at all levels. Among Top 10 frequently asked questions in Java. Very frequently asked to fresh graduates or less experienced professionals. | ||||
| ||||
Ans. Its a facility for code reuse and independent extension wherein a derived class inherits the properties of parent class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts  oops concepts  java concepts  code reuse  code re-use   classes  derived classes Asked in 14 Companies basic   frequent | ||||
| ||||
Ans. A Java bean is a class which abides by following conventions: Core of the object is member elements and not operations ( methods ) Member Elements can be accessed by getters (and setters if those properties are not read-only). serializable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java bean   javabean   pojo   classes basic   frequent | ||||
| ||||
Ans. As Class B has been declared abstract , we can either implement any of these methods and just declare rest of them abstract. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  interfaces  abstract classes  code  coding | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Yes, a lock can be acquired on the class. Class level lock is applicable on the whole class and hence on all objects of the class whereas the object level lock is applicable on the respective object. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  synchronization  class level lock  object level lock | ||||
| ||||
Ans. This class is used to provide access to the Java runtime system | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  runtime class  jre  java runtime | ||||
| ||||
Ans. It should either implement the abstract methods or re-declare them abstract. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  abstract class Asked in 2 Companies Basic   Frequent | ||||
| ||||
Ans. Combiners are used to increase the efficiency of a Map Reduce program. They are used to aggregate intermediate map output locally on individual mapper outputs. Combiners can help you reduce the amount of data that needs to be transferred across to the reducers. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Hadoop Systems  BigData   hadoop combiners Asked in 1 Companies | ||||
| ||||
Ans. It stores the string as a character array with 2 bytes for each character. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  String  String Class | ||||
| ||||
Ans. No, It requires creation of atleast one Class. Creating an object of that class is not compulsory as we can write all our logic within main method which is static. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java program without creating any class | ||||
| ||||
Ans. It is a class level variable that is shared among the objects of that class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  static   static variables   class level variables Asked in 1 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. No, If both Parent and Derived are outer classes. public class Vehicle { private static String manufacturingDate = "2016"; } public class Car extends Vehicle{ public static void main(String args[]){ System.out.println(manufacturingDate); // error - The field Vehicle.manufacturingDate is not visible } } Yes, If derived is the inner class of Parent. public class Vehicle { private static String manufacturingDate = "2016"; static public class Car extends Vehicle{ public static void main(String args[]){ System.out.println(manufacturingDate); // no problem } } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  private members   private methods   private variables   inheritance  object oriented programming (oops)  oops concepts   members visibility   inner classes  nexted classes basic   frequent | ||||
| ||||
Ans. Classpath is the parameter for JVM to look for java classes ( .class files ) that are to be looad by class loader | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  classpath Asked in 1 Companies basic | ||||
| ||||
Ans. public class BuggyBread { | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  builder pattern  builder class | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Yes , we have been using this plugin with our projects and its purpose is to warn and stop the Build if there are duplicates of the same package and class are being carried either directly or through transitive dependencies. the duplicate could be coming through different types of dependencies or through different versions of the same dependency. Its purpose is to make sure that there is only one copy thats being used at compile time and runtime and hence shouldnt later result in runtime problems. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  maven   ban duplicate classes enforcer plugin | ||||
| ||||
Ans. The simplest way is to ignore them if Maven enforcer plugin is complaining about it but it may lead to runtime problems later. We can do the dependency:tree to see from where these duplicate ones are coming and hence can exclude the duplicate one. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  maven   ban duplicate classes enforcer plugin | ||||
| ||||
Ans. Yes, we can define an inner class within interface.Inside the interface, the inner class is implicitly public static. So the following is legit in Java public interface BuggyBreadInterface { void doSomething(); public class BuggyBreadClass implements BuggyBreadInterface{ void doSomething(){ System.out.println("Do something"); } } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  inner classes  inner class in interface  nested classes | ||||
| ||||
Ans. println prints an additional end of line whereas printf doesnt. | ||||
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  printf | ||||