Tutorials

Java Basic Interview Question


Java Interview Question Set2


 

Q1: What is difference between Java and C++?

Java

C++

At compile time java code is converted to bytecode for jvm

At compile time C++ code is converted into machine level language

Java is a platform independent language

C++ is platform dependent language

Java class doesn’t support multiple inheritance

C++ class supports multiple inheritance

Java doesn’t support operator overloading

C++ support operator overloading

Java doesn’t support goto statement

C++ support goto statement

Java doesn’t support structure and union

C++ support structure and union both

Java supports call by value only

C++ supports both call by value and call by reference

Java doesn’t openly support pointer

C++ openly support pointer

Java doesn’t support scope resolution operator (::)

C++ support scope resolution operator (::)

 


Q2: Why java is secure as programming language?

Java security mainly comes in following ways:

1. At first security is provided by JVM(Java Virtual Machine) by checking the .class files for any malicious virus or threats that is presented to it before executing those files. So bytecode verification by JVM adds to security.

 

2. Memory security is provided by the Memory Management architecture of java. (Read more)

Here garbage collector starts its task of collecting the garbage objects as soon as it senses that out of memory condition is about to reach or even before it.

 

Programmer don't need to take any headache of releasing the memory space manually as is in other languages. Here JVM controls the garbage collector and it does this task for you. Manually programmer can also give instruction to garbage collector to run but then in that case also JVM has full decision control of whether to run it or not.(Read more)

 

3. Java Package concept provides security from namespace collision in java.

 

4. Access modifier like public, private, protected and default defines the level to which a class/method/variable can be exposed. So depending upon the level of exposure needed these access modifiers can be used.

In this way we can secure the data from unintended user who is in no way concerned with it thus protecting it from getting misused.

 

5. Immutability of String adds to security as well. Because of immutable nature String can be used to store password/username, database connection(& other details), key in HashMap without worrying much about String getting tampered/or modified by unauthorized/malicious user.

 

Above answer is picked up from my blog : Java Radar


 

Q3: What is the difference between JDK, JRE and JVM?

We have already provided detailed answer in our java tutorial here: click to read

 

 


Q4: What is the difference between path and classpath in java?

We have already provided detailed answer in our java tutorial here: click to read

 

Q5: What is bytecode in java?

Bytecode is a specialized set of instructions that is read, verified and understood by JVM or Java Virtual Machine.

When a java source code is compiled then it is converted into bytecode which could be executed on same system or ported to other system having JVM and executed.

Bytecode and JVM together helps in making java platform independent.

 



Please Share this page
Views : 160
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!