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. 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 | ||||
| ||||
Ans. It means that the respective folder is not looked upon by Java to look for java or resource files and hence not being included as part of build.It needs to be added to Java Build Path. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  build path.build class path | ||||
| ||||
Ans. String class is immutable as well as final. Because of these properties , String objects offer many benefits 1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references. Example - String str1 = "String1"; String str2 = "String1"; // It doesnt create a new String and rather reuses the string literal from pool // Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too 2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence its not fit to be cached. 3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  immutable  immutability  immutability  String  string class Asked in 1 Companies | ||||
| ||||
Ans. toString() is an overloaded method of String class that is used to convert many data types to String, Boolean being one of them. toString(Boolean bool) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  String  String class  Boolean Asked in 1 Companies Basic | ||||
| ||||
Ans. Collections in java is a framework of classes that provides an abstracted data structure to store and manipulate the group of objects. Each class is unique in the way it stores , search , sort and modify the elements. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections  collection classes Asked in 1 Companies Basic   frequent | ||||
| ||||
Ans. Abstract classes provide a mechanism of interfacing ( using abstract method ) as well as inheritance ( extending abstract class ). So they should be used in place of interfaces in case there is some code ( methods ) or object body ( member elements ) that can be reused with inheritance. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  abstract classes Asked in 1 Companies | ||||
| ||||
Ans. B ctor B ctor B ctor A ctor A ctor | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   Asked in 1 Companies | ||||
| ||||
Ans. PATH, CLASSPATH and JAVA_HOME | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  environment variables  path  classpath  java_home Asked in 3 Companies basic   frequent | ||||
| ||||
Ans. It depends on the type of inner class To access non static inner class method new OuterClass().new InnerClass().getMethod(); To access static method of static inner class new OuterClass.InnerClass().getMethod(); | ||||
Sample Code for inner class | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  inner classes  nested aclasses Asked in 1 Companies Intermediate   frequent | ||||
| ||||
Ans. Class is a template using which objects are created in memory. It's kind of a mold using which objects with body / state are made. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  class  object  class vs object Asked in 4 Companies basic   frequent | ||||
| ||||
Ans. OuterClass.class AND OuterClass$InnerClass.class | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  class files  compilation  compile  inner classes   nested classes | ||||