Java - Interview Questions and Answers for 'Operators' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Operators' - 22 question(s) found - Order By Newest

Frequently asked in Infosys and HCL Technologies ( Based on 2 feedback )
 Q1. What are different ways of object creation in Java ?Core Java
Admin
info@buggybread.com
Ans. Using new operator - new xyzClass()

Using factory methods - xyzFactory.getInstance( )

Using newInstance( ) method - (Class.forName(xyzClass))emp.newInstance( )

By cloning an already available object - (xyzClass)obj1.clone( )

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

   Like      Discuss      Correct / Improve     java   oops   object creation   new operator   class.forname   cloning   ebay     Intelligrape  Infosys  Polaris  British Telecom (BT)  Vyom Labs  Deutsche Bank  HCL Technologies      expert


 Q2. What is the difference between the following two code lines ?

1. new OuterClass().new InnerClass();

2. new OuterClass.InnerClass();
Core Java2016-06-30 14:45:37

Ans. In first case we are trying to initialize Inner class object using the instance of Outer Class whereas in second case we are trying to initialize the Inner class object directly using the Outer class name.

In second case , Inner class is "static inner class" as we cannot access "non static inner class" using Classname alone.

In first case, the inner class could be either "static inner class" or "non static inner class".

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

   Like      Discuss      Correct / Improve     inner classes  inner class   static inner class   new operator


 Q3. According to Java Operator precedence, which operator is considered to be with highest precedence?Core Java
Admin
info@buggybread.com
Ans. Postfix operators i.e () [] . is at the highest precedence.

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

   Like      Discuss      Correct / Improve     java   operators   operator precedence     Palpap Ichinichi  Veritas


 Q4. Difference between new operator and Class.forName().newInstance() ?
Admin
info@buggybread.com
Ans. new operator is used to statically create an instance of object. newInstance() is used to create an object dynamically ( like if the class name needs to be picked from configuration file ). If you know what class needs to be initialized , new is the optimized way of instantiating Class.

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

   Like      Discuss      Correct / Improve     java   oops   object instantiation   object creation   class.forname   newinstance   new operator   difference between   advanced      intermediate


Usually asked in relation to casting and ClassCastException.
 Q5. What is instanceOf operator ? Explain it's use ?Core Java2017-06-12 07:58:22

Ans. The operator instanceOf is used to verify if the specified object is the instance of specified class or interface.

Syntax if(x instanceOf ABC)

where x is an object reference and ABC could be a class name or interface name. The above statement will be true if x holds an object that is an instance of ABC or any of the child class of ABC or if x holds an object that implements ABC.

instanceOf operator is used to verify in case of downcasting. For ex -

DerivedClass extends BaseClass

x is the reference of BaseClass but holds DerivedClass object ( Polymorphism )

There is an operation that is defined in Derived Class, let's say derivedClassMethod()

We cannot call derivedClassMethod() directly using x as x is reference of BaseClass and not DerivedClass and hence can only access methods that are defined in BaseClass and overridden in derived class.

Though we can cast it to DerivedClass as following
((DerivedClass)x).derivedClassMethod();

But it may throw ClassCastException in case x doesn't hold an instance of DerivedClass at that point.

So before casting it to DerivedClass we may like to make sure that it is an instance of DerivedClass and hence won't throw ClassCastException.

So we make a check for it

if(x instanceOf DerivedClass) {
((DerivedClass)x).derivedClassMethod();
}

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

   Like      Discuss      Correct / Improve     instanceOf  instanceOf operator  Why we need instanceOf operator  use of instanceOf operator     Trimax IT Infrastructure & Services   ultramain      Intermediate        frequent


 Q6. Difference between Class#getInstance() and new operator ?
Admin
info@buggybread.com
Ans. Class.getInstance doesn't call the constructor whereas if we create an object using new operator , we need to have a matching constructor or copiler should provide a default constructor.

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

   Like      Discuss      Correct / Improve     java   constructor   object creation   default constructor   getinstance   new operator


 Q7. What is the difference between >> and >>>?
Admin
info@buggybread.com
Ans. Both bitwise right shift operator ( >> ) and bitwise zero fill right shift operator ( >>> ) are used to shift the bits towards right. The difference is that >> will protect the sign bit whereas the >>> operator will not protect the sign bit. It always fills 0 in the sign bit.

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

   Like      Discuss      Correct / Improve     java   operators   bitwise operators   binary shift   right shift


 Q8. Which Java operator is right associative?Core Java
Admin
info@buggybread.com
Ans. The = operator is right associative.

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

   Like      Discuss      Correct / Improve     java   operators   = operator


 Q9. Difference between prefix and postfix increment operator ?
Admin
info@buggybread.com
Ans. Prefix operator performs the increment and then assignment whereas its inverse for postfix operator.

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

   Like      Discuss      Correct / Improve     prefix increment operator   postfix increment operator   operators   java      basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Write code to check if an integer is odd or even using ternary operator

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=963

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

   Like      Discuss      Correct / Improve     ternary operator  code  coding


Rarely asked as it was introduced with Java 8.
 Q11. What is the use of :: operator wef from Java 8 ?Core Java2016-07-25 13:27:57

Ans. We can refer to a function using this operator like System.out.println(intList.stream().reduce(Math::max).get());

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

   Like      Discuss      Correct / Improve     :: operator   lambda expression  java 8


 Q12. What is the difference between = and == in Java ?Core Java2016-09-02 08:12:45

Ans. = is the assignment operator that assigns the result of the expression on the right to the variable on the left, whereas

== is the operator to check object equality to see if the reference on left and right are pointing to the same object. For primitive types, its used to check if both variables holds the same value.

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

   Like      Discuss      Correct / Improve     =  ==  assignment operator  object equality  difference between      Basic


 Q13. Which operators in Java have highest precedence ?Core Java2017-01-07 17:00:43

Ans. Braces, i.e () and [] have the highest precedence

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

   Like      Discuss      Correct / Improve     java operators


 Q14. Explain dot(.) operator ?Core Java2017-01-19 13:53:35

Ans. Its used to access the object properties using the object reference or class properties using the Class Name. Moreover its used to access the classes and Interfaces of a package.

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

   Like      Discuss      Correct / Improve     operators


 Q15. What are the different operators in Java ?Core Java2017-01-28 15:15:36

Ans. && - AND
|| - OR
! - LOGICAL NOT

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

   Like      Discuss      Correct / Improve     operators      Basic


 Q16. What is the difference between && and & in Java ?Core Java2017-02-03 08:30:47

 This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     operators  logical vs bitwise operator


 Q17. What is the precedence of operators in Java ?Core Java2017-03-01 09:42:52

Ans. http://introcs.cs.princeton.edu/java/11precedence/

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

   Like      Discuss      Correct / Improve     operators  operator precedence      basic


 Q18. Which of the following is valid greater than and equal to operator in Java ?

>=
=>
Core Java2017-05-20 16:23:47

Ans. >=

=> will result in error.

=> somewhat looks like lambda operator "->"

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

   Like      Discuss      Correct / Improve     operators  >= operator  greater than and equal to operator  comparison operators


 Q19. What is a ternary operator ?Database2017-06-18 16:46:34

Ans. Ternary operator , also called conditional operator is used to decide which value to assign to a variable based on a Boolean value evaluation. It is used as

condition ? value1 : value2

For example

int y = (x > 0) ? x:0; // assign x if it's greater than 0, else assign 0

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

   Like      Discuss      Correct / Improve     operator  ternary operator      Basic



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. Why doesn't java support operator overloading ?Core Java2017-06-23 08:15:18

 This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     operator overloading


 Q21. Which of the following is true for == operator ?Core Java
a. For primitives, == checks if the variables on left and right have same data type
b. For primitives, == checks if the variables on left and right have same value
c. For Objects, == checks if the references on left and right have same data type
d. For Objects, == checks if the references on left and right have same value

Ans.b. For primitives, == checks if the variables on left and right have same value

 Q22. Which of the following is equivalent to following logic ?

Not X && Not Y
Core Java
a. x || Y
b. Not(X || Y)
c. Not(X && Y)
d. Not X && Y

Ans.b. Not(X || Y)



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

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:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: