Interview Questions and Answers for 'Cla' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

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.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q101. What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?Core Java
Ans. The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented

  Sample Code for InputStream

  Sample Code for OutputStream

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   file io   streams   reader class   writer class   inputstream   outputstream   stream  file handling


 Q102. What environment variables do I need to set on my machine in order to be able to run Java programs?
Ans. CLASSPATH and PATH are the two variables.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   classpath   path   environment variables   jvm


 Q103. Which String class methods are used to make string upper case or lower case?Core Java
Ans. toUpperCase and toLowerCase

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string class   string


 Q104. How to convert String to byte array and vice versa?Core Java
Ans. We can use String getBytes() method to convert String to byte array and we can use String constructor new String(byte[] arr) to convert byte array to String.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string class   string


 Q105. What will be the output of the following code ?

String s1 = "Buggy Bread";
String s2 = "Buggy Bread";
if(s1 == s2)
   System.out.println("equal 1");
String n1 = new String("Buggy Bread");
String n2 = new String("Buggy Bread");
if(n1 == n2)
   System.out.println("equal 2");
Core Java
Ans. equal 1

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string class   string   string pool   code   coding      basic        frequent


 Q106. Difference between PATH and CLASSPATH ?Operating System
Ans. PATH is the variable that holds the directories for the OS to look for executables. CLASSPATH is the variable that holds the directories for JVM to look for .class files ( Byte Code ).

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   path   classpath   byte code   jvm   basic interview question     Asked in 3 Companies      intermediate        rare


 Q107. what will be the output ?

class Animal {
public void eat() throws Exception {
}
}

class Dog2 extends Animal {
public void eat(){}
public static void main(){
Animal an = new Dog2();
an.eat();
}
}
Core Java
Ans. Compile Time Error: Unhandled exception type Exception

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   code   coding   overridding   late binding   exception handling   abstract class   abstract methods


 Q108. Does SQL allow null values ? Can we use it within Where clause ?
Ans. Yes , we can have null values for columns in SQL. Null value represent that the columns value is unknown or haven't been filled. Yes, We can use it within where clause to get the rows with null values.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     sql   sql null values   sql where clause   databases


 Q109. Will this code Work ? If not , Why ?

java.util.Calendar c = new java.util.Calendar();
Core Java
Ans. No. It gives the error "Cannot Instantiate the type Calendar". Calendar is an abstract class and hence Calendar object should be instantiated using Calendar.getInstance().

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   date   calendar   abstract class   yes-no


 Q110. Is java.util.Date an abstract Class ? Is java.util.Calendar an abstract Class ?Core Java
Ans. Date is not a abstract class whereas Calendar is.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   date   calendar   abstract class


 Q111. Which methods of the Pattern class have equivalent methods in the String class? Core Java
Ans. split() and macthes()

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   io   string class   string   pattern


 Q112. Can we compare Integers by using equals() in Java ?Core Java
Ans. Yes for the Wrapper class Integer but not for the primitive int.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   wrapper classes   equals


 Q113. Difference between Assert and Verify ?Testing
Ans. Assert works only if assertions ( -ea ) are enabled which is not required for Verify.Assert throws an exception and hence doesn't continue with the test if assert evaluates to false whereas it's not so with Verify.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     assert   junit   mockito   verify   testing   unit testing     Asked in 5 Companies


 Q114. Can we declare Entity class as final ?Hibernate
Ans. Yes but as Hibernate creates the Proxy Classes inherited from the Entity Classes to communicate with Database for lazy initialization. Declaring entity classes as final will prohibit communication with database lazily and hence will be a performance hit.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   proxy objects   proxy classes   entity hibernate


 Q115. What is the difference between int[] x; and int x[]; ?Core Java
Ans. No Difference. Both are the acceptable ways to declare an array.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   array   arrays   array declaration   difference between     Asked in 3 Companies      basic


 Q116. What is the difference between namenode and datanode in Hadoop? BigData
Ans. NameNode stores MetaData (No of Blocks, On Which Rack which DataNode is stored etc) whereas the DataNode stores the actual Data.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hadoop   at&t     Asked in 2 Companies


 Q117. How do you define a class of constants in Java?
Ans. Make the class as final.
Disable the object construction by making constructor private.
Keep only Static Final Variables declared and Defined at the same time.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java constants   constant class   java


 Q118. What will the following code do ?

String dateStr = "2011 11 19";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormat.parse(dateStr);
System.out.println(date);

Ans. It will throw the ParseException as the date format doesn't abide with the format of the specified date.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     date   utility classes   dateformat   exception   parseexception


 Q119. Shouldn't we make a class with all static members is its just expected to be executed as a standalone program with just one thread. Moreover Lets assume that there is no runtime Polymorphism required and there is no need for serialization ?Design
Ans. Still No in case we are making use of inheritance. we may have problem wherein we have program flow moving across common inherited method and specific methods of the derived class. call made to another static method in the parent class will only access the static class of the Parent class irrespective of the call from any of the derived class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static class   static vs singleton   inheritance


 Q120. Is this valid in Java ?

Long x = new Long ("42");
Core Java
Ans. Yes. Long wrapper class has overloaded constructor which takes String as input and then translate it to the long value and stored it as long.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   wrapper classes   long wrapper class   long


 Q121. What is classpath in a project?Core Java
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


 Q122. What is the difference between public class and class ?Core Java
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


 Q123. Will this code compile ?

public class BuggyBread1{
abstract public void test();
}
Core Java
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


 Q124. Will this Code compile ?

abstract public class BuggyBread1{
abstract public void test(){};
}
Core Java
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


 Q125. Name few classes that extends Number Class ?
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


 Q126. Name few classes that extend Thread class ?Core Java
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


 Q127. Name few classes that extends Collections class ?
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


 Q128. In which cases isn't instanceof operator a bad practice?Core Java
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


 Q129. Do you see Class as a Data Type or Data Structure ?
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


 Q130. Can we have multiple classes in single file ?
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


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: