UNIT -1
QUE 1- DIFFERENCE BETWEEN OOP AND POP
POP
Procedural-Oriented Programming.
POP follows top-down approach.
A program is divided into functions.
OOP concepts are not supported.
No access modifiers are supported.
Example-C, Pascal
OOP
Object-Oriented Programming.
OOP follows bottom-up approach.
A program is divided to objects and class.
OOPs concepts are supported.
Access control is supported
Example-C++, Java
QUE 2- EXPLAIN OOPS CONCEPTS
Object
In real word “any things” its call object like pen,chair,table [Link] programming term we can say that object is instance
Class
Class is collection of object. A class can also be defined as ablueprint from which you can create an individual object.
Inheritance
In inheritance one object access all the properties of a parent object, It provides code reusability and runtime polymor
Abstraction
Abstraction provides only necessary information to user hideinternal details.
Ex. person call to another person they can communicate but do not know internal process.
Encapsulation
Wrapping of code and data into one single unit that’s known as encapsulation.
Polymorphism
In simple word poly means one morphism means multiple so we can say one thing used for multiple purpose for ex sh
QUE 3- JAVA PROGRAM STRUCTURE
Documentation Section
Package Statement
Import Statements
Interface Statements
Class Definitions
main method class
{
main method definition
}
DOCUMENTATION SECTION: It is also known as comment section used to giving the details about the program, det
PACKAGE STATEMENT: This section is used to declares a package and informs the compiler that the classes define
Example: package student;
IMPORT STATEMENT: Using import statement, we can access to classes that part of other named packages.
Example: import student. test;
INTERFACE STATEMENT: An interface is like a class but includes group of methods declaration.
CLASS DEFINITION: Java program may contain multiple class definition.
MAIN METHOD: It is a starting point of program. every programexecution always starts with main method. There mus
COMPILING AND RUNNING A SIMPLE JAVA PROGRAM
public class Example
{
Public static void main (String args[])
{
[Link]("Hello World");
}
}
Write the Program code in notepad and save the file as [Link]
Open Command Prompt.
Change the directory, where [Link] file is [Link] javac command to compile the file
Enter “javac [Link]” command
Use java command to Run the file
QUE 4- LIST OUT ALL OPERATORS AND EXPLAIN ANY ONE IN DETAILS
Operator is symbol used to perform specific [Link] of operators
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Bitwise operators
Increment Decrement operators.
Arithmetic Operators
Arithmetic operators are used to perform common mathematicaloperations.
Operator | Name | Description
+ | Addition | Adds together twovalues.
- | Subtraction | Subtract one value fromanother.
* | Multiplication | Multiple two values.
/ | Division | Divide one value by another and return quotient.
% | Modulo division | Divide one value by another and return reminder.
Example
public class Example
{
public static void main (String args[]){int a=20;
int b=10;
[Link]("Add="+a+b);
[Link]("Sub="+a-b);
[Link]("Mul="+a*b);
[Link]("Div="+a/b);
[Link]("Mod="+a%b);
}}
Output
Add=30 Sub=10 Mul=200
Div=2
Mod=0
QUE 5-EXPLAIN GARBAGE COLLECTION WITH EXAMPLE
Garbage means unreferenced objects.
Garbage collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to de
Advantage
It makes java memory efficient.
It is autmatically done.
gc() method
The gc() method is used to invoke the garbage collector to performcleanup processing. The gc() is found in System an
Syntax
public static void gc() { }
Example
public class TestGarbage1{
public void finalize(){[Link]("garbage collected");}
public static void main(String args[]){
TestGarbage1 s1=new TestGarbage1();
TestGarbage1 s2=new TestGarbage1();
s1=null;
s2=null;
[Link]();
}
}
Output
garbage collectedgarbage collected
QUE 6-EXPLAIN if..else Statement WITH EXAMPLE
if else statement works whether expression true or false. if conditionis true if block statement will be execute if conditio
if(condition){
// block of code to be executed if the condition is true
}
else
{
// block of code to be executed if the condition is false
}
Example
int a=20;
if(a<18){
[Link]("Good day.");
}else{
[Link]("Good evening.");
}
Output
Good evening
QUE 7-EXPLAIN FOR LOOP WITH EXAMPLE
When you know in advance how many times you want to execute loop through a block of code, use the for loop instea
Syntax
for(statement 1; statement 2; statement 3) {
// code block to be executed
Statement 1 is executed (one time) before the execution of thecode block.
Statement 2 defines the condition for executing the code block.
Statement 3 is executed (every time) after the code block has beenexecuted.
Example
for(int i=0;i<5;i++){
[Link](i);
QUE 8- GIVE DIFFERENCE BETWEEN STRING AND STRING BUFFER
String
String is an immutable class and its object can’t be modified after it is created
Methods are not synchronized
It is fast
If a String is created using constructor or method then those strings will be stored in Heap
Memory as well as String Constant Pool
StringBuffer
String buffer is mutable classes which can be used to do operation on string object
All methods are synchronized in this class.
Multiple thread can’t access at the same time therefore it is slow
Heap Space
QUE 9- EXPLAIN ACCESS CONTROL/MODIFIERS
Access control is the process of controlling visibility of a variableor Method.
There are four levels of visibility:
1. Public: - public members can be accessed by any other codefrom anywhere.
2. Private: - Private members can only be accessed by other members of its class.
3. Protected: - protected members can only be accessed by classes that are subclass of the class directly. Protecteda
4. Default (or Package): - When a member does not have an explicit access specification, it is visible to subclasses as
QUE 11-WHAT IS CONSTRUCTOR LIST OUT TYPES OF CONSTRUCTOR EXPLAIN DEFAULT CONSTRUCTOR
What is constructor?
Constructor is special member function of class used to initializeobject of class.
TYPES OF CONSTRUCTORS
Default Constructor
Parameterized Constructor
Copy Constructor
DEFAULT CONSTRUCTOR
Constructor don not have argument that’s known as defaultconstructor.
Example
Class A
{
A()
{
[Link]("hii I am from class A");
}
Public static void main(String args[])
{
A ob=new A();
}
}
Output
Hii I am from class A