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.
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 :
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 :
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 :
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 :
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 :
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 :
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 :
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 ?
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 :
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 :
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 :