Professional Documents
Culture Documents
JAVA Brief
JAVA Brief
1.What is OOP?
2.What is a class?
3.What is an object?
4.What is Method?
Group of statements that perform some operation on some data and may or may not
return a result.
6.What is IDE?
Integrated Development Environment that combines basic tools developers need to write
and test software (editor, compiler, interpreter ,debugger can accessed through single
GUI)
7.What is JVM?
Java Virtual Machine that enables a computer to run java programs as well as programs
written in other languages that are also compiled to java bytecode.
1|Page
10. JDK (Java Development Kit) and JRE(Java Runtime Environment) explain?
JRE is a software layer that runs on top of a computer’s OS system software and provides
the class libraries and other resources.
2|Page
1.0 JAVA Programming
System.out.println(n);
}
13.If-else Statement
…
if(Boolean-expression)//>,<,==,!=
{
Statement-1;//when condition pass
}else{
Statement-2;//when first condition fails
}
…
3|Page
14.Nested-if Statements
if –else in another if-else
…
if(Boolean-Expression1){
if(Boolean-Expression2){
Statement-1;
}else{
Statement-2;
}
}else{
Statement-3
}
…
15.If-Else-If Statements
…
if(Boolean-Expression1){
Statement1;
} else if(Boolean-Expression2){
Statement2;
} else if(Boolean-Expression3){
Statement3;
}else{
Statement4;
}
…
4|Page
16.Switch Statements
…
switch(switch-expression){
case casevalue_1:
statement1;
break;
case casevalue_2:
statement2;
break;
case casevalue_n:
statement n;
break;
default:
statement;
}
…
17.While Statement
…
while(condition)
{
Statements;
increment++/decrement--;
}
…
18.Do-While Statement
…
do
{
Statements;
increment++/decrement--;
}
while(condition);
…
5|Page
19.For Statement
…
for(initialization; loop condition; increment++/decrement--)
{
statement-1;
statement-2;
…
statement-n;
}
…
20.Nested Loops
…
for(initialization; loop condition; increment++/decrement--)
{
for(initialization; loop condition; increment++/decrement--)
{
statement-1;
statement-2;
…
statement-n;
}
statements;
}
…
1.1 Objects-Classes
Class NameOfClass{
}
6|Page
23.Explain Access Modifies.
Public- Accessible from all classes.
Private-Accessible only within it’s own class.
Protected- Accessible to class within same package & for sub classes via inheritance.
Default- Accessible only to the class within package.
24.What are the field declaration components?
Access modifiers
Field Data type
The field name
25.Method define Format.
<Access Specifier><Return Type><Method Name>(<input parameters>){
}
public static void main(string[]args){
}
26.What are the characteristics of constructor?
Same name of the class.
No return type, not even void.
Can have any number of arguments.
Can have member initialization lists in order to initialize member data.
27.What are local variables?
Local variables are declared in methods, constructors or blocks. They are created when
the method constructor is entered and the variable will be destroyed once it exits the
method, constructor or block.
28.What are the characteristics of using this keyword?
To invoke current class method
To invoke current class constructor
To pass argument in the method
To pass argument in the constructor call
To return current class instance
If local and instance variables are different it is not required to use this keyword
7|Page
29.Give example for static method using,
public class methUse{
public static void firstMeth(){
System.out.println(“Hello”);
}
public static void main(String args[]){
firstMeth();
}
}
30.Give example for non-static method using,
public class methUse{
public void firstMeth(){
System.out.println(“Hello”);
}
public static void main(String args[]){
methUse obj=new methUse();
obj.firstMeth();
}
}
8|Page
31.Give example for multiple class using.
public class phone{
public void sendMessage(){
System.out.println(“Hello”);
}
}
public class mobile{
public static void main(String args[]){
phone obj=new phone();
obj. sendMessage();
}
}
*if use notepad should create two java files in same folder.
*net beans; new project>source packages>new package>two java classes
class Employee{
int empId;
String name;
class EmpThis{
public static void main(String args[]){
Employee e1=new Employee(2586,”Nisal”);
e1.Display();
}
}
9|Page
1.2 Encapsulaton
encap.setName(“David”);
encap.setAge(22);
10 | P a g e
1.3 Inheritance
35.What is inheritance?
Enables to reuse the functionalities and capabilities of the existing class by extending a
new class from the existing class and adding new features to it.
36.What are sub and super classes?
Sub class- the class that inherits the data members and methods from another class.
Super class-The class from which the subclass inherits.
37.Give example for use of super keyword.
*super keyword is used to invoke the constructor of super class
public class Car{
private String color;
private int noSeats;
public Car(String color,int noSeats){
this.color=color;
this.noSeats=noSeats;
}
}
public class Premio extends Car{
private String model;
public Premio(String color,int noDeats,String model){
super(color,noSeats);
this.model=model;
}
}
11 | P a g e
38.Give example for inheritance(implement super & sub classes).
class Calculator{
int z;
public void addition(int x,int y){
z=x+y;
System.out.println(z);
}
public void subtraction(int x,int y){
z=x-y;
System.out.println(z);
}
}
public class MyCalculator extends Calculator{
public void multiplication(int x,int y){
z=x*y;
System.out.println(z);
}
public static void main(String args[]){
int a=20,b=20;
MyCalculator my1=new MyCalculator();
my1.addition(a,b); //40
my1.subtraction(a,b); //0
my1.multiplication(a,b); //400
}
}
12 | P a g e
1.4 Polymorphism
39.What is polymorphism?
Programming language’s ability to process objects differently depending on their data
type or class, ability to redefine methods for derived classes.
40.What are the polymorphism types?
static/compile-time
dynamic
41.What is method overloading?
Implements multiple methods within the same class that use the same name but
different set of parameters.
42.Describe method overloading criteria with examples.
different number of parameters
13 | P a g e
43.What is method signature?
Ability to write methods that have the same name but accept different parameters.
Compiler can separate the difference through this.
44.What is the different of dynamic polymorphism?
In this compiler doesn’t allow to determine the executed method. It happens in run-
time.
45.Give example for dynamic polymorphism.
class Calculator{
int z;
public void addition(int x,int y){
z=x+y;
System.out.println(“super”+z);
}
public void subtraction(int x,int y){
z=x-y;
System.out.println(“super”+z);
}
}
public class MyCalculator extends Calculator{
public void multiplication(int x,int y){
z=x*y;
System.out.println(“sub”+z);
}
15 | P a g e
53.What is an exception?
An event, which occurs during execution of the program, that disrupts the normal flow
of the program instructions.
54.Give example for exception handling.
int a=10;
int b=0;
try{
int div =a/b;
System.out.println(div);
}catch(ArithmaticException e){
System.out.println(“cannot devided by 0”);
}catch(Exception e){
System.out.println(“some other error occured”);
}finally{
System.out.println(“Good bye”);//always executed
}
ArithmaticException
RuntimeException
IOException
FileNotFoundException
StringIndexOutOfBoundsException
57.What is debugging?
17 | P a g e