0% found this document useful (0 votes)
14 views

java basic questions

Uploaded by

sundarmatsa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

java basic questions

Uploaded by

sundarmatsa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Basic Questions

1. What is java?
Answer: Java is high-level, Robust, Object-oriented, secure programming language. It was
developed by James Gosling in the year 1995.
2. What are the key features of java?
Answer:
- Simple.
- Robust.
- Secure.
- Multithreading.
- Object-oriented
- Platform independent
- High performance
3. Why java is platform independent?
Answer: Because the java compiler converts the java programs into a byte code that can be run
on any device which means you can write java programs on one platform and run it on any
platform without making any changes.
4. Explain each keyword in main() method?
Answer:
Class: Class is a keyword that can be used to declare a class in java.
Public: it is an access specifier that represents the visibility that means the main method is
accessible everywhere.
Static: static is a keyword. If you declare a method as static, it is known as static method. We
don’t need to create an object to call static method.
Void: void is return type of the method that means it doesn’t return anything.
Main: main is the name of the method.
String args[]: this is an array of strings passed as command line arguments.
5. What is JVM?
Answer: java virtual machine is a runtime environment that can executes java bytecode.
6. What are the applications of java?
Answer:
- web applications like irctc.in etc.
- mobile applications.
- Desktop applications like media player, antivirus etc.
- Embedded systems.
- Robotics
- Games (Minecraft).
7. What is the difference between JDK and JRE?
Answer:
JDK: Java development kit is a software development kit which is used to develop java
applications and applets including JRE, the compilers and tools like debuggers etc.
jRE: JRE is the implementation of JVM where the java programs are being executed.
8. What is variable? Types and explain its types?
Answer: A variable is a container which holds the value while java program is executed. There
are three types of variables in java:
Local variable: A variable which is declared inside the body of the method is called local variable.
You can use only within the method.
Instance variable: A variable which is declared inside the class but outside the body of the
method is called instance variable.
Static variable: A variable which is declared as static is called static variable.
9. What is datatype in java & what are the datatypes are supported by java?
Answer: Datatype in java is a classification that specifies what type of data a variable can hold.
There are two types of datatypes: primitive and non-primitive datatypes.
Primitive datatypes (8): boolean, byte, short, int, long, float, double, char
Non-primitives: string, arrays etc.
10. What is autoboxing and Unboxing?
Answer: autoboxing is the automatic conversion made by the compiler between the primitives
and their corresponding object wrapper classes. For example, the compiler converts an int to an
Integer, a double to a Double.
Unboxing is the conversion of the object wrapper classes to their corresponding primitive types.
11. What is pass by reference and pass by value?
Answer:
12. What are operators in java?
Answer: Operators in java is a symbol which can be used to perform operations.
13. What is “null” keyword in java?
Answer: null keyword is used to represents the absence of a value.
14. What is type casting in java?
Answer: type casting is the process of converting one data type to another data type either
implicitly or explicitly.
Implicit type casting: is the conversion of smaller data type to longer data type. Ex, int to long.
Explicit type casting: conversion of larger data type to smaller. Ex, long to int.
15. What is Java keyword?
Answer: java keywords are also known as reserve words that can act as a key to code. Ex,
abstract, final, static etc.
16. What is the “stack” and “heap” in memory management in java?
Answer:
17. What is “constant pool” in java?
Answer: The constant pool is a special area in memory which can be used to store string literals
and constants.
18. What are the differences between C++ and Java?
Answer:
- C++ is a platform dependent, while java is platform independent.
- C++ is mainly used for system applications, while java used for application programming.it is
widely used in windows, web and mobile applications.
- C++ supports multiple inheritance, while java does not support multiple inheritance.
19. What is platform?
Answer: A platform is the hardware or software environment in which a piece of software is
executed. There are two types of platforms, such as hardware-based and software-based. Java
provides software-based platform.
20. What is classloader?
Answer: A classloader is a subsystem in JVM which is used to load the class files.
21. What are the various access specifiers in java?
Answer: The access specifiers are the keywords which are used to define the scope of the
methods, classes, or variables. In java there are four types of access specifiers.
- Public: it can be accessed everywhere. It can be accessed within the package, outside the
package, within the class and outside the class.
- Protected: it can be accessed within the package and outside the package through child
class. If you do not make a child class, it cannot be accessed from outside the package.
- Default: it can be accessed from only within the package. It cannot be accessed outside the
package.
- Private: it can be accessed from within the class and it cannot be accessed outside the class
22. What is the purpose of static methods and variables?
Answer: A methods or variables is defined as static are shared among the all the objects in the
class. The static is the class and not of the object. The static variable is stored in class area, we do
not need to create an object to access such variables.
23. What are the advantages of Packages in Java?
Answer:
- The packages avoid the name clashes.
- Packages provides easier access control.
- It is easier to locate related classes.
24. What is call by value and call by reference?
Answer:
Call by value: is a method of passing arguments to a function where a copy of the actual
parameters. value is passed. Changes made to the parameter inside the function do not affect
the original arguments.
Call by reference: is a method of passing the arguments to a function where a reference of the
actual parameters is passed. Changes made to the parameter inside the function affect the
original arguments.
25. Why java is not pure object oriented?
Answer: Because java supports primitive data types such as byte, Boolean, int, long, double.
26. What happens if the main() method is written without String args[]?
Answer: The program will compile but not run. Because, the JVM will always looks for the main
method with a string type array as a parameter.
27. What is JIT compiler?
Answer: JIT (just-in-time) compiler which is used to improve the performance by compiling
bytecodes into native machine code at runtime.

You might also like