Programming





Interview Question and Answers Part 3

Interview Question and Answers Part 3


by Administrator | 31-Mar-2020
Java

Tags:  Interview  Question And Answer  Difference

Share: 


  1. What is the difference between & and && or | and ||?

In the Bitwise operator, if the first operator evaluates to true in OR (|) and False in AND (&) then the second expression will also be evaluated. But, in Logical Operator, if the first operand evaluates to true in OR (|) and False in AND (&) then the second expression will not be evaluated.

  1. What is the difference between the >> and >>> operators?

The >> operator is also called Arithmetic Shift Right which carries a signed bit when shifting right. The >>> operator is also called a logical shift right which does not carry any signed bit.

  1. Can shift operators be applied to float types?

No, shift operators can be applied only to integer or long types

  1. What happens to the bits that fall off after shifting?

They are discarded.

  1. What values of the bits are shifted in after the shift?

In case of signed left shift >> the new bits are set to zero. But in case of signed right shift << it takes the value of most significant bit before the shift that is if the most significant bit before shift is 0 it will introduce 0, else if it is 1, it will introduce 1.

  1. What are operators and what are the various types of operators available in Java?

Operators are special symbols used in expressions. The following are the types of operators:

  • Arithmetic operators
  • Assignment operators
  • Increment & Decrement operators
  • Logical operators
  • Bitwise operators
  • Comparison/Relational operators
  • Conditional operators

 

  1. Can you write an if statement without else statement?

Yes

  1. Can you write else statement without if statement?

No

  1. What restrictions are placed on the values of each case of a switch statement?

During compilation, the values of each case of a switch statement must evaluate to a value that is an integer or compatible with an integer value.

  1. Can a for statement loop indefinitely?

Yes, for statement can loop indefinitely. Here’s the code: for(;;) ;

  1. What is the difference between a break statement and a continue statement?

A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.

  1. What is the difference between a do and a while loop?

A while loop checks at the beginning of a loop to see whether the next loop iteration should occur. A do-while statement checks at the end of a loop to see whether the next iteration of a loop should occur. A do loop will always execute at least once.

  1. What is meant by variable?

Variables are locations in memory that can hold values. Before assigning any value to a variable, it must be declared.

  1. What are the kinds of variables in Java? What are their uses?

Java has three kinds of variables namely:

Instance Variable: Local variables are used inside blocks as counters or in methods as temporary variables and are used to store information needed by a single method.

Local Variable: Instance variables are used to define attributes or the state of a particular object and are used to store information needed by multiple methods in the objects.

Class Variable: Class variables are global to a class and to all the instances of the class and are useful for communicating between different objects of all the same class or keeping track of global states.

  1. What is literal? How many types of literals are there?

A literal represents a value of a certain type. There are different types of literals namely number literals, character literals, boolean literals, string literals, etc.

  1. What is an array?

An array is an object that stores a list of homogeneous datatype elements.

  1. How do you declare an array?

Array variable indicates the type of object that the array holds. Ex:

int intArr[];

String stringArr[];

  1. Which of the following declares an array of string objects?
  2. String[ ] s;
  3. String [ ]s:
  4. String[ s];
  5. String s[ ];

a, b and d are the correct way of declaring an array.

  1. What is a static variable?

Static variables are shared by all instances of a class.

  1. What is final variable?

Final variable’s value cannot be changed. It becomes a constant.


Comments:


There are no comments.

Enter a new Comment:










Copyright Šprgrmmng. All rights reserved.