Q. What is Java?
It is a general-purpose computer programming language which is fast, secure, simple, architecturally neutral, reliable, portable, and object-oriented. It is built by Sun Microsystem in 1995 which was initiated by James Gosling.
Q. Write any five features of Java.
Object-oriented
Platform Independence
Robust Secure
Automatic memory management
Platform Independence
Robust Secure
Automatic memory management
Q. Why java is platform independent?
It is because Java byte-code is not associated with any particular hardware platform. It can be executed on any machine with JVM.
Q. What is an Object?
The object is an instance of a class. It is the name of any person, place, thing or entity. It must have an identity, state, and behavior.
Q. What is a class?
It is a blueprint of an object. A class may contain data (variables) and modules (method).
Q. What is OOP’s?
Object-oriented programming (OOP) is a new way of organizing around objects which represent as an instance of a class and it revolves around Abstraction, Encapsulation, Inheritance and Polymorphism.
Q. What is JDK?
It is a collection of various tools that helps in writing and implementing Java program.
Q. What is JVM?
Java Virtual Machine is a piece of software that interprets java bytecode for a particular
platform or we can say a JVM is a program that behaves like a computer.
Q. What is Bytecode?
When the java compiler compiles the java source code, it becomes bytecode. So java bytecode is nothing but java compile code. It is a platform-independent code.
Say Hello.java ร compile ร Hello.class (Byte Code) ร Run in JVM
Q. What is UNICODE?
Unicode is a 2 bytes code international encoding set use to with characters and digit or symbol.
Q. Why Java is ‘Write once and Ran anywhere’?
When java source code compiles it become bytecode and it run everywhere provided JVM is there. That is why it is called ‘Write once and Ran anywhere’.
Q. What is java Tokens?
The smallest individual units in a program are known as tokens.
Q. What are data types?
To identify the type of data involved in an operation is called Data Types. There are two types od data types (primitive or fundamental types) and (non-primitive or reference types)
Q. What are the default values of different primitive types?
byte 0
short 0
int 0
long 0 l
float 0.0 f
double 0.0 d
boolean false
char null
Q. What is the difference between primitive and nonprimitive (reference) data types in Java?
Primitive Data Type: Primitive means “very basic”. Very basic or Fundamental data types available with java is known as Primitive data types. Examples are byte, char, int, long, float, double etc.
NonPrimitve Data Type: Non-primitive data types or reference are those which uses primitive data type as a base like an array, enum, class, etc.
Q. What is wrapper class?
It is a process by which we can convert primitive data types into object types. Every primitive data type has a wrapper class. All the wrapper class is the subclasses of the abstract number class.
Primitive Type
|
Wrapper class
|
boolean
|
Boolean
|
char
|
Character
|
byte
|
Byte
|
short
|
Short
|
int
|
Integer
|
long
|
Long
|
float
|
Float
|
double
|
Double
|
Q. What is typecasting?
The process of converting one type of data type into another type is called type casting.
Q. What is Coercion?
Coercion is a type of conversion where data are promoted. It is also known as type promotion. For example, parsing the Java String "60" to the Integer 60 would be coercion.
Q. Define Abstraction, Encapsulation, Polymorphism, and Inheritance.
Abstraction, Encapsulation, Polymorphism, Inheritance
Abstraction: Abstraction refers to the act of representing essential features without including the background details or explanations.
Polymorphism: It is referred to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles, and triangles. No matter what shape an object is, applying the area method to, it will return the correct results
Encapsulation: The wrapping up of data and methods into a single unit is called Encapsulation.
.Inheritance: It is the process by which objects of one class acquire the properties of objects of anther class. Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of a motorbike. Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chainring, giving them a lower gear ratio.
Q. What are variables? How many types of variables are there in Java?
Variables are places in the memory where we can store data. It has three types. a. A local variable, an Instance variable, and a Class variable.
Local Variable: It is defined within the method and constructor. These variables' visibility remains within the method and constructor.
Instance Variables: Define inside a class. It is available for every instance of the class.
Class variable: when a variable defines with keyword static inside a class is known as the class variable.
All object of the class shares static variables because of only a single copy of these available in the memory.
Q. What is the final variable?
When a variable defines with the final keyword then its value can not be change throughout the whole program.
Example
class Circle{
final int pi=3.14;//final variable cannot be change
double a, r;
void area(){
r = 3.5;
a = r*r*pi;
System.out.println("Area="+a)
}
public static void main(String args[]){
Circle obj=new Circle();
obj.area();
}
}//end of class
Q. Can the‘ main’ method be declared final?
Yes, the main method can declare as final.
public class Example
{
public static final void main(String args[])
{
int a=6;
System.out.print((++a)+(a--));
}
}
Q. What is a static variable?
A static variable is shared by all instances of a class. It is also known as a class variable and it is declared with the keyword ‘static’. Instances (objects) of the same class share a single copy of static variables.
class School
{
int rollno;
String section;
String name;
static String schoolName ="InspireSkills Edu";
// constructor
School(int r, String s, String n){
rollno = r;
section = s;
name = n;
}
void display ()
{
System.out.println(rollno + " " + section + " " + name + " " + schoolName);
}
public static void main(String args[])
{
School ob1 = new School(1, "A", "Mukesh");
School ob2 = new School(2, "B", "Aryan");
ob1.display();
ob2.display();
}
}
Q. What is the static method?
When a method defines with a static keyword before a data type is called a static method.
class Example
{
public static void print()
{
System.out.println(“This is a static method”);
}
}
Q. What is a Garbage collection?
When an object is no longer required, java automatically free the memory space is known as Garbage Collection.
Q. What is the java package?
A java package is a Java language element used to group related classes under a common name. Packages can be nested inside one another. The main package is java in the java language
Q. What is an escape sequence?
The combination of characters is preceded by a code extension. It comes with the backslash (\). For example, \n stands for new line; even though it looks like two characters, Java treats them as one character with an ASCII code of 10. The escape sequence, being a single character, should be put within single quotes.
Escape Sequences
|
|
Escape Sequence
|
Description
|
\t
|
Insert a tab in the text at this point.
|
\b
|
Insert a backspace in the text at this point.
|
\n
|
Insert a new line in the text at this point.
|
\r
|
Insert a carriage return in the text at this point.
|
\f
|
Insert a form feed in the text at this point.
|
\'
|
Insert a single quote character in the text at this point.
|
\"
|
Insert a double quote character in the text at this point.
|
\\
|
Insert a backslash character in the text at this point.
|