Java Questions

Q:

How to identify a given positive decimal number as even/odd without using % or / operator ?

Answer

You may be very good at coding,but if you questioning how on earth you could solve this problem.Then here is a solution. If you remember the good old days of our primary school then the solution is easy,"division is a matter of iterative subtraction".


public class TestEvenOdd {
public static void main(String arg[ ]){
int num=6;
int result=num;
while(result>=2){
result=result-2;
}
if(result==1){
System.out.println("The number is odd");
}else{
System.out.print("The number is even");
}
}
}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

3 5048
Q:

Which among the following is a scope resolution operator?

A) : B) ::
C) :? D) None
 
Answer & Explanation Answer: B) ::

Explanation:

:: is the scope resolution operator

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Software Architect

0 4985
Q:

X implements Y extends Z

A) X can be class Y,Z are interfaces B) X is an interface Y,Z are classes
C) X,Y are classes Z is an interface D) Complilation error
 
Answer & Explanation Answer: D) Complilation error

Explanation:

It is a compilation error it should be X extends Y implements Z

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: IT Trainer

3 4806
Q:

What is dynamic method dispatch?

Answer

Dynamic method dispatch which is also known as runtime polymorphism is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 4776
Q:

Does not overriding hashcode() method has any performance implication ?

Answer

A poor Hashcode() function will result in frequent collision in HashMap which eventually increase time for adding an object into Hash Map.

Report Error

View answer Workspace Report Error Discuss

Subject: Java
Job Role: Analyst , IT Trainer

2 4425
Q:

Why interface data is public?

Answer

to access non-public data outside class getter methods be defined but we cannot define a  method inside interface we can declared a method inside interface.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 4311
Q:

How can you make sure your dependencies are safe ?

Answer

When writing Node.js applications, ending up with hundreds or even thousands of dependencies can easily happen.
For example, if you depend on Express, you depend on 27 other modules directly, and of course on those dependencies' as well, so manually checking all of them is not an option!


The only option is to automate the update / security audit of your dependencies. For that there are free and paid options:


1. npm outdated
2. Trace by RisingStack
3. NSP
4. GreenKeeper
5. Snyk

Report Error

View answer Workspace Report Error Discuss

1 4296
Q:

Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent  Postfix notations.

A) AC + B * DE - FG +^- B) AB + C * DE - FG + ^-
C) AC + B* DE - FG -+ ^ D) AB + C * DE - FG -+ ^
 
Answer & Explanation Answer: B) AB + C * DE - FG + ^-

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Java

4 4107