• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Interview Questions Answers

Question - 41 : - What can go wrong if you replace &emp;&emp; with &emp; in the following code: String a=null; if (a!=null && a.length()>10) {...}

Answer - 41 : - A single ampersand here would lead to a NullPointerException.

Question - 42 : - An application needs to load a library before it starts to run, how to code?

Answer - 42 : - One option is to use a static block to load a library before anything is called. For example, class Test { static { System.loadLibrary("path-to-library-file"); } .... } When you call new Test(), the static block will be called first before any initialization happens. Note that the static block position may matter.

Question - 43 : - What is the difference between a MenuItem and a CheckboxMenuItem?

Answer - 43 : - The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked.

Question - 44 : - What is the difference between static and non-static variables?

Answer - 44 : - A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

Question - 45 : - What is the range of the short type?

Answer - 45 : - The range of the short type is -(2^15) to 2^15 - 1.

Question - 46 : - What value does readLine() return when it has reached the end of a file?

Answer - 46 : - The readLine() method returns null when it has reached the end of a file.

Question - 47 : - How do you know if an explicit object casting is needed?

Answer - 47 : - If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example: Object a; Customer b; b = (Customer) a; When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.

Question - 48 : - What are wrapped classes?

Answer - 48 : - Wrapped classes are classes that allow primitive types to be accessed as objects.

Question - 49 : - How are the elements of a GridBagLayout organized?

Answer - 49 : - The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.

Question - 50 : - What interface must an object implement before it can be written to a stream as an object?

Answer - 50 : - An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

Computer Contributors

Rajeev Katiyar
Yes Baroda

Share your email for latest updates


Our partners