Core Java Interview Questions – Set 18

How is rounding performed under integer division

The fractional part of the result is truncated. This is known as rounding toward zero.

Why are the methods of the Math class static

So they can be invoked as if they are a mathematical code library.

When are automatic variable initialized

Automatic variable have to be initialized explicitly

What is the preferred size of a component?

The preferred size of a component is the minimum component size that will allow the component to display normally.

How are the elements of a GridBagLayout organized?

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

The elements of a GridBagLayout are of equal size and are laid out using the squares of a grid.

How does bitwise (~) operator work

Ans: It converts all the 1 bits in a binary value to 0s and all the 0 bits to 1s, e.g

11110000 coverts to 00001111

What is the purpose of the File class

The File class is used to create objects that provide access to the files and directories of a local file system

Can static method use non static features of there class

No they are not allowed to use non static features of the class, they can only call

static methods and can use static data

What is a void return type

A void return type indicates that a method does not return a value.

What is the difference between the prefix and postfix forms of the ++ operatoR

The prefix form performs the increment operation and returns the value of the increment operation.

The postfix form returns the current value all of the expression and then performs the increment operation on that value.