1) What is
java?
2) Why is Java a platform independent
language?
Ans: Java
language was developed in such a way that it does not depend on any hardware or
software due to the fact that the compiler compiles the code and then converts
it to platform-independent byte code which can be run on multiple systems.
The only condition to run that byte code is for the
machine to have a runtime environment (JRE) installed in it.
3) What is api in java?
Ans: Java application programming interface (API) is a
list of all classes that are part of the Java development kit (JDK). It
includes all Java packages, classes, and interfaces, along with their methods,
fields, and constructors. These pre-written classes provide a tremendous amount
of functionality to a programmer.
4) How to initialize array in
java?
Ans: "int[]
arr = new int[5]; // integer array of size 5 you can
also change data type
String[] cars =
{""Volvo"", ""BMW"",
""Ford"", ""Mazda""};"
5) How to take input from user
in java?
Ans: "import
java.util.Scanner;
Scanner console = new Scanner(System.in);
int num = console.nextInt();
console.nextLine() // to take in the enter
after the nextInt()
String str = console.nextLine();"
6) What is static in java?
Ans: In Java, a static member is a member of a class
that isn’t associated with an instance of a class. Instead, the member belongs
to the class itself. As a result, you can access the static member without
first creating a class instance.
7) What is package in java?
8) How to sort an array in
java?
Ans: "import
java. util. Arrays;
Arrays.
sort(array);"
9) What is an abstract class in
java?
10) What are the
various access specifiers for Java classes?
Ans: In Java,
access specifiers are the keywords used before a class name which defines the
access scope. The types of access specifiers for classes are:
1. Public : Class,Method,Field is accessible from anywhere.
2. Protected:Method,Field can be accessed from the same class to which
they belong or from the sub-classes,and from the class of same package,but not
from outside.
3. Default: Method,Field,class can be accessed only from the same
package and not from outside of it’s native package.
4. Private: Method,Field can be accessed from the same class to which
they belong.
11) What’s the purpose of Static
methods and static variables?
Ans: When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects.
12) What is data encapsulation and
what’s its significance?
13) What is a singleton class? Give a
practical example of its usage.
14) How to enable java in
chrome?
Ans:
·
In the Java Control
Panel, click the Security tab
·
Select the option
Enable Java content in the browser
·
Click Apply and
then OK to confirm the changes
·
Restart the browser
to enable the changes
15) What is string in java?
Ans: String is a sequence of characters, for e.g.
“Hello” is a string of 5 characters. In java, string is an immutable object
which means it is constant and cannot be changed once it has been created.
16) What is exception in java?
17) Can you tell the difference
between equals() method and equality operator (==) in Java?
|
== |
This
is a method defined in the Object class. |
It
is a binary operator in Java. |
This
method is used for checking the equality of contents between two objects as
per the specified business logic. |
This
operator is used for comparing addresses (or references), i.e checks if both
the objects are pointing to the same memory location. |
19) Can main() method in Java can
return any data?
20) What are Java Packages? What’s
the significance of packages?
21) Can we declare a class as
Abstract without having any abstract method?
Criteria |
JDK |
JRE |
JVM |
Abbreviation |
Java
Development Kit |
Java
Runtime Environment |
Java
Virtual Machine |
Definition |
JDK
is a complete software development kit for developing Java applications. It
comprises JRE, JavaDoc, compiler, debuggers, etc. |
JRE
is a software package providing Java class libraries, JVM and all the
required components to run the Java applications. |
JVM
is a platform-dependent, abstract machine comprising of 3 specifications -
document describing the JVM implementation requirements, computer program
meeting the JVM requirements and instance object for executing the Java byte
code and provide the runtime environment for execution. |
Main
Purpose |
JDK
is mainly used for code development and execution. |
JRE
is mainly used for environment creation to execute the code. |
JVM
provides specifications for all the implementations to JRE. |
Tools
provided |
JDK
provides tools like compiler, debuggers, etc for code development |
JRE
provides libraries and classes required by JVM to run the program. |
JVM
does not include any tools, but instead, it provides the specification for
implementation. |
Summary |
JDK
= (JRE) + Development tools |
JRE
= (JVM) + Libraries to execute the application |
JVM
= Runtime environment to execute Java byte code. |
23) Can we declare the main method of
our class as private?
24) How can we pass argument to a
function by reference instead of pass by value?
25) How an object is serialized in
java?
26) When we should use serialization?
27) Who invented java?
Ans: Java was originally developed by James Gosling at
Sun Microsystems (which has since been acquired by Oracle) and released in 1995
as a core component of Sun Microsystems’ Java platform.
28) How to execute a java
program?
30) What is enum in java?
Ans: An enum is a special “class” that represents a
group of constants (unchangeable variables, like final variables). To create an
enum, use the enum keyword (instead of class or interface), and separate the
constants with a comma.
31) How to uninstall java?
·
Click Start
·
Select Settings
·
Select System
·
Select Apps &
features
·
Select the program
to uninstall and then click its Uninstall button
·
Respond to the
prompts to complete the uninstall
0 Comments