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

java. 2

The document provides an overview of Object-Oriented Programming (OOP) concepts in Java, including key principles such as inheritance, polymorphism, abstraction, and encapsulation. It explains the significance of encapsulation, the types of polymorphism (compile-time and run-time), and the differences between abstract classes and interfaces. Additionally, it covers exception handling, variables, literals, and the main method in Java, emphasizing the structure and behavior of Java programs.

Uploaded by

Chinmayee Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

java. 2

The document provides an overview of Object-Oriented Programming (OOP) concepts in Java, including key principles such as inheritance, polymorphism, abstraction, and encapsulation. It explains the significance of encapsulation, the types of polymorphism (compile-time and run-time), and the differences between abstract classes and interfaces. Additionally, it covers exception handling, variables, literals, and the main method in Java, emphasizing the structure and behavior of Java programs.

Uploaded by

Chinmayee Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

"Java-

4;?, Java4Quicklearning
Q. What do you understand by OOPs in java?
OOPs is abbreviated as Object Oriented Programming
system in which programs are considered as a collection
of objects. Each objectis nothing but an instanceof a
class.
• OOPs has four pillars -
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
Q. Why do we use object-oriented programming?
• OOPs make the development and maintenance of
projects easier.
• OOPs provide the feature of data hiding that is good for
security concern. '"'
• We can provide the solution to real-world problems if we
are using object-oriented programming.

«
•~J
-=- icklearning
Java

,.

fl Original sound
Java
Vo ~ r.;-:;,
34
10:26AM .11 WiFi ':" ~•

"~ Java4Quicklearning
Java
Q. What is encapsulation in java?
Encapsulation in Java is a process of grouping data
members and corresponding methods into a single unit.

I°"
E t'\C:.°'-pS.c..c ti C>t'\
IN - CAP.SULE - a-.t,o"'

En

._~ ,
--=- ·cklearning
Javd

Rem1

ai 1ew e

fl Original sound

,_ 6 (±) 0
-

Home Shorts Subscript ions You


J ava4Q uIcklea rn in g
Java-
Q. What is encapsulation in java?
Encapsulation in Java is a process of grouping data
members and corresponding methods into a single unit.

e~c.~psul~tio""
IN - CAf=>.SULE - CAt,ot'\

Encapsulation _is us~d to bindtC:he fields and methods


together. It ~a1nly aims at bundling and hiding th d t
and controlling a e a a

·ckLearning

. (
10:28 AM ... ~~F, ~ QD,

f- Q :

,i f Java4Quicklearning
Java
Q. What is polymorphism injava?
Polymorphism in Java is a concept by which we can
perform a single action in different ways. Polymorphism is
derived from 2 Greek words: poly and morphs.
The word "poly" means many and "morphs" means forms .
So polymorphism means many forms.

'Types of Polymorphism

complle time
polymorphism
run-time
polymorphism m
I
(static or early binding) (dynamic or late blndln~b

·cklearning
{

~ org

riginal sound

Shorts
"!J: Java4Quicklearning
Java-
Q. What do you understand by Compile-time Polymorphism?
Compile-time polymorphism, also known as static
polymorphism, is a type of polymorphism that occurs
during the compilation process. It can be achieved by
Method Overloading.

Q. What is Method Overloading?


When there are multiple functions with the same name
but different parameters then these functions are said to
be overloaded. Functions can be overloaded by change in
the number of arguments or/and a change in the type of
arguments.

lfil1l1!.l:-

lmliitb
~
Java-
Java4Quicklearning
Q. What do you understand by run-time
Polymorphism?
Dynamic polymorphism is another name for
runtime polymorphism.
In Java, method overriding is a technique for
implementing runtime polymorphism. It is also
sometimes known as Dynamic method dispatch.
Q. What is Method Overriding?
Method Overriding is a procedure in which the
compiler can allow a child class to implement a
specific method already provided in the parent
class. ,,

«
:_~ I
)dVd

mmm~
Original sound

Home Shorts
earning
QuickL
Java4
_J_{avka- Jav a ? m en ta tion
strac tion in g th e imple r. It
t is Ab o f hid in the us e
Q. Wha rocess
is a p ality to
ction
io n f u n
c t
Abstra d showing o nly
ing things.
tails a n xity o f view
de c ompl e
s the
reduce
ction
Abstra

e
Interfacction
bstra
100% a

bstract class
A abstrac
tion
0%
0 to 10

~ ,~
CR ERab ra
va l
<..j;
Java
~ Java4Quicklearning
Q. What is Abstract class in Java?
A class which is declared as abstract is known as an abstract
class.
Example - abstract class Java4Quicklearning {
//Non-abstract method
public void show() {
System.out . println("Hello World");
}

II Abstract method
abstract int getAdmissionFee();
}
Points to Remember
• An abstract class must be declared with an abstract keyword.
• It can have abstract and non-abstract methods. q,
• It can have constructors and static methods also.
• It can have flna

lm:ill~

(!)

«
•= )
..::::::.. earning
Java

' (
"~ ~ J a v a 4 Q u ic k le a r n in g
J ava
Q. What is the super keywor
d in Java?
pe r ke yw ord is us ed to invo ke the
The su
n m etho d, w hich ov er rides one o f its
overridde
superclass methods .
overridden
This keyword allows to access
et ho ds an d also to ac cess hi dden members
m
o f the superclass.
fo rw ar ds a ca ll fr om a co nstructor, to a
It also
constructor in t

ll

,r-1,:.

d
•~ J

'= -=
}dV d
~-=- :,- J a v a 4 Q u ., c k le a r n in g
--
Java
ist in Java?
Q . W h at is th e arrayl im plementation of the
is a re si za bl e ar ra y
A n A rr a yl is t in Ja va rt o f th e Ja va C ollections Framework.
is pa
Li st in te rf ac e, w hi ch
S yn ta x -
r> lis t = ne w A rr ay lis t< ln te ge r> ();
A rr ay lis t< ln te ge
ca n dy na m ic al ly gr ow and shrink in size.
is t
U nl ik e ar ra ys , A rr a yl ip ul at e th e si ze o f th e array th at is
to m an
It pr ov id es m et ho ds
or e th e lis t.
us ed in te rn al ly to st
E xa m pf e - th e en d o f lis t
ad d( 21 ); // ap pe nd to
ad d( 74 ); .
ad d( 92 ); fr om th e sp ec ifi c index
e( 2) ; // re m ov e
re m ov
<4~Java4Quicklearning
Java-
Q. What is the difference between an abstract class
and an interface?
• An abstract class can have both abstract and
non-abstract methods, while an interface can only
have abstract methods.
• Abstract class doesn't support multiple inheritance
but Interface supports multiple inheritance.
• The abstract keyword is used to declare abstract
class, while interface declare with the keyword
interface.
• An abstract class can be extended using keywor J 1

"extends" while An interface can be implemente<...


using keyword "implements". ~.{i'l

'

Subscribe & Follow Us


« Java4Quicklearn1.n
<~

Ja va
g
Q. Wh at is the significance of th e
sta tic ke yw or d in
Java?
• The static keyword in Java is used
fo r me mo ry
management mainly.
• We can apply sta tic keyword wi th
variables,
methods, blocks and nested cla ss
es .
• These members are as so cia ted
wi th the cla ss
rather than wi th instances of the cla
ss .
Example -

st at ic ke yw or d us ag e
1. sta tic variables
static mt cou nt;
2. sta tic me tho ds
c;.t::itir vni rl fnn (\ n

~
._,
..:;;,...
)dVd

Su bsc rib e & Fo llo w Us

a 0
facebook
Threads

se t 1s soun

Hom e Shorts
.4~Java4Quicklearning
Java
Q. What are Literals in Java?
Literals have a consta nt value and a fixed data type
and are often known as consta nts in Java. Literals
are assigned to a variable to provide a value to the
variable.
Example -

Int num = 30

Data Type Variable Literals

Types Of Literals

Integer literals -> 10, 5, -8 etc ...


1)1-·in~<:.
Floatin g-poin t literals -> 1.2, 0.25, -1 .999, etc...

Boolean literals -> true, false

Chara cter literals -> 'a', 'A', 'N', 'q', etc ...

String literals -> "hi", "hello", "What 's up?"


.:iir.]{:.
~
._, S~J b::::ri=:-,r~ & Follow Us
..=...
Java

a YouTube
(@
q~
0
facebook

.
[¢] C)
Threads Ttltgtlffl "~
~~

- ., :..,
~ -- -
•• t-:
:..

fl Original sound
"Java-
{i;! Java4Quicklearning
Q. What is exception handling in java?
An exception is an event that occurs during the
execution of a program. Exceptions can be of any
type - Runtime exception, Error exceptions.
Due to this interrupts the normal flow of program
and rest of the code will not executed, to avoid this
unexpected interruption, these exceptions are
adequately handled through exception handling
mechanism like try, catch and throw keywords.
Example-
public class ExcepDemo {

public static void main(String[) args) {


I I TODO Auto-generated method stub
int i=S;
int j=O; The division statement is
try { ,,_,, executed within try block

System.out.println(ilj);
}
IAs the program throws
ArithmeticException, that
catch(ArithmeticException ae) {
mentioned inside catch
block
System.out.println("wrong
input");

System.out.println("statement after division");

s~ib:: ::rfhr! & Fo llow Us


fdVd

D (@) 6 ~ 0 ~
YouTube q~ facebook Threads Ttl,gram

"'~
.......
0 ' ·-
-
:
- ,... - - ~ -~J w

fl Original sound
<-c.d;_ Java4Quicklearnin1
Ja va
Q. What is variables injava?
A Variable is a name given to a m
em or y location. 11
is used to store a value th at m ay
vary. Ja va is a
sta tic all y typed language, and he
nce, all th e
variables are declared be fo re use.
Example - ~

~ 0
0

int age= 21 ;

B
Types of Va ria ble s in Java

Local
[ ] Class

:
:,
'd Sab·.::.:r L~C.- & Fo llo w Us ~It ]{:.

=
1.1Tube
1~
®] 0
facebook
[€]
Threads
0 l.f] \1R~11'1:.P
~~ Java4Qu1. cklearning
'" '
< __ P a rt - # 1
Java return type String class
access modifier

! !
lic static void main ( String args[] )
pub
t i i
method name array ofstring objects
keyword

e o f th e main() m ethod in Java?


Q. W h a t is th e purpos t o f an executable
is th e e n tr y p o in
T h e M a in m e th o d p ro g ra m c o ntrol starts and
re th e
p ro g ra m ; it is w h e
ends.

rn ty p e o f th e main() method?
Q. W h a t is th e re tu m e th o d in ja va is void'! '
th e m a in
T h e re tu rn ty p e o f in m e th o d d oesn't return any
e m a
T h is m e a n s th a t th th e void keyword .
is d e c la re d w it h
v a lu e . It
m.·m:<~
() m e th o d dec lared static?
Q. W h y is th e main ca lle d w it h o u t creating an
th o d to b e
It a ll o w s th e m e ic h it is defined .
c la s s in w h
in s ta n c e o f th e

Us
s ~t b·.::: r i ':,c• & Fo llo w
Ir
Javd

0 ~ ,_
C ) ~

a YouTul>e 1~
@J focebook

.-
"'~
Th rea ds

«)
- '"= ""

fl O ri gi na l so un d
Java Part - #2
access modifier return type String class

l
public static void main ( String args[] )
t
keyword
t
method name
t
array of string objects

Q. Can we use a different name for the main() method,


like start()?
No, because JVM call the method with the name
main() only.
Q. Does the order of public and static declaration
matter in main() method? ,. ,l

No, the order of the public and static modifiers in {he


main() method declaration doesn't matter. Both
public static and static public are valid and
interchangeable.
public static void main(String[] args) t/
static public void main(String[] args) t/
Q. Can we declare the mai,n() method as final?

'
A k le a r n in g
"J"a=va: J a v a 4 Q u ic Pa rt -# 3
access modifier retu rn type String class

J ! !
args[] )
public static void main ( String
t i t
keyword method name array orstring objects

n w e ru n a Ja va pr og ra m without the main()


Q. Ca
method?
d ne w er ve rs io ns do n' t allow this because
Java 7 an
M ch ec ks th e pr es en ce of the main method
JV
ass.
be fo re initializing the cl
main() method?
Q. Can you overload the
•) :•

ca n ov er lo ad th e m ai n() method. we can


Yes, w e
e m or e th an on e pu bl ic static void main()
w rit
e arguments .
m et ho d by changing th ,1~ "'•=
E xa m pl e - ng [] args) - Call by }v~
ic vo id m ai n( S tri
pu bl ic st at
String name)
pu bl ic st at ic void main(
in t num)
pu bl ic st at ic void m ai n(
ai n( ) m et hod? .
ov er rid e th e m
Q. Can you
nn ot ov er rid e m ai n m et ho d because a static
w e ca
ridden.
m et ho d ca nn ot be over

s~tb·.::~r i':.,c· & Fo llow Us


'' l
@) 0 ~ (,_> ~
D YouTube 1~
facebook Threads
'-';l':1i,(

: . j,
~

fl Original sound
Vo ~ '321
10:37AM .11 I WiFi ~ ~•

--~ Java4Quicklearning
Java
Q. What is Spring Framework?

fill

(I

klearning

01... J~
Remix
w java #SP-ring
ramewolil< ijavaAguicklearning

fl Original sound

Home Shorts Subscriptions


"'~ ? Java4Quicklearning
Java
Q. What is Spring Framework?
It is a open source designed to simplify the
development of Java based applications.
Spring handles the infrastructure so you can
focus on your application code.
Q. What are the main features of spring
framework?
• It is an open source & lightweight.
• Easy to develop and test.
• Dependency injection.
• It supports integrating with other
frameworks.
• Minimal Configuration is required.
• Large Community Support.
• Developed loosely coupled applica

SubscrihP & Follow Us

DYouTube
0
facebook
~ ()
Threads TolOfl"'m

fl Original sound
"4~Java4Quicklearning
Java
Q. What is the difference between equals() and
equalslgnoreCase() method of String in java?
The equals() method compares two strings, and returns
true if the strings are equal, and false if not. it is a case
sensitive.
Example - String str1 = "Java4Quicklearning";
String str2 = "java4quicklearning";
boolean check= str1 .equals(str2);
Output : false
While The equalslgnoreCase() method compares two
strings, ignoring lower case and upper case differences.

Example - String str1 = "Java4Quicklearning";


String str2 = "java4quicklearning";
I"
This method returns true if the strings are equal, and false
if not.
1.i
1

boolean check= str1 .equalslgnoreCase(str2);


Output : true

(1)

1cklearning
~
Java
Java4Quicklearning
Core Java Interview Question
Q. What is Lamda Expression in Java?
Lambda expressions are the method without name
that is called Anonymous method.
Lambda expression is a function that can be passed
around and referenced as an object.

Lambda Syntax
• No arguments: () - > System.out.println("Hello")

• One argument: s -> System.out.println(s)

• Two arguments: (X, y) - > X + y

• With explicit argument types:


(Integer x, Integer y) -> x + y
( x, y) -> {
System .out.println( x) ;
• Multiple statements:
System. out. println( y); l•Ji:.-3n~<:..
return ( x + y) ;
}

Subscribe & Follow Us

a 0 ~
°! hrt:a:13
CD ii
,..._, WhatsApp

fl Original sound

Home Shorts
10:39 AM" • ,I I VWoF_
I I
~
• U
'3211
L..::?=...J

,4 Java4Quicklearning
Java
Q. Explain default method of interface in java.
Java 8 introduced the concept of default
methods.
Default methods are methods that can have a
body so implementing class no need to
implement.
Default methods in interfaces is to provide
additional functionality to a given type without
breaking down the implementing classes.
Example -
public interface Vehicle { 1..k
void cleanVehicle():
default void startVehicle(){
System.out.println("vehicle is startit 'L }
}

.:iit:1( :.
._~ ,
---
)dVd
Subscribe & Follow Us

a (®) 0 ~ C) 11
·,cu-:-. t. 1Jt~11'.!fl!'.U fo!:~~, ·:-.v~
·-- WhatsApp

Ja Original sound

Home Shorts
{I
< ?
Jav a
Ja va 4Q uic kle arn ing
Q. Wha t are wrap per classes in java?
• The wrapper class in Java provides the
mec han ism to convert primitive into object
and obje ct into primitive.

• This conversation of data is also knows as


auto boxi ng and unboxing .

• The eigh t classes of the java .lang package


are know n as wrapper classes in Java.

• The list of eigh t wrapper classes are giverr ·


belo w :

Primitiv1 Oita Wr1pp1r Class


-
l )J..•W~<:.
Typ1
char Character
Byte
byte
-
short Short
long Integer '
float Ffoat
Double
double
Boolean
-
boolean
.:iit:1 11':.

)dVd Subsc rit>t & Follo w Us

a "(ouTuhe
0 Ttloptom

fl Original sound

You might also like