java theroy ! easy to learn

Upload: akshay-patel

Post on 05-Apr-2018

240 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Java Theroy ! Easy to Learn

    1/53

    Q. Why is Java often termed as a platform?A n s : P l a t f o r m i s t h e e n v i r o n m e n t i n w h i c h p r o g r a m s

    e x e c u t e . I n s t e a d o f i n t e r a c t i n g w i t h t h e

    O p e r a t i n g S y s t e m d i r e c t l y , J a v a p r o g r a m s r u n s o n a

    v i r t u a l m a c h i n e p r o v i d e d b y J a v a , t h e r e f o r e J a v a i s

    o f t e n r e f e r r e d t o a s a p l a t f o r m a l s o .Q. What is a bytecode?A n s : B y t e c o d e i s a s e t o f p s e u d o m e c h a n i c

    l a n g u a g e i n s t r u c t i o n s t h a t a r e u n d e r s t o o d b y t h e

    J V M ( J a v a V i r t u a l M a c h i n e ) a n d a r e i n d e p e n d e n t

    o f t h e u n d e r l y i n g h a r d w a r e .

    Q. What do you understand by JVM?

    A n s : J V M o r J a v a V i r t u a l M a c h i n e i s a n a b s t r a c tm a c h i n e d e s i g n e d t o b e i m p l e m e n t e d o n t o p o f

    e x i s t i n g p r o c e s s o r s . I t h i d e s t h e u n d e r l y i n g O S f r o m

    J a v a a p p l i c a t i o n . P r o g r a m s w r i t t e n i n J a v a a r ec o m p i l e d i n t o J a v a b y t e - c o d e , w h i c h i s t h e n

    i n t e r p r e t e d b y a s p e c i a l j a v a I n t e r p r e t e r f o r as p e c i f i c p l a t f o r m . A c t u a l l y t h i s J a v a i n t e r p r e t e r i s

    k n o w n a s J a v a V i r t u a l M a c h i n e ( J V M ) .

    Q. What is JDK (Java Development Kit)?A n s : T h e J a v a d e v e l o p m e n t k i t c o m e s w i t h a

    c o l l e c t i o n o f t o o l s t h a t a r e u s e d f o r d e v e l o p i n g

    a n d r u n n i n g j a v a p r o g r a m s .Q. What are Java APIs?

    A n s : T h e J a v a A P I s ( A p p l i c a t i o n P r o g r a m I n t e r f a c e )

    c o n s i s t o f l i b r a r i e s o f p r e - c o m p i l e d c o d et h a t p r o g r a m m e r s c a n u s e i n t h e i r a p p l i c a t i o n .

    Q. Write the five characteristics of Java/BlueJ?

    Top Companies Hiring. If Your CV Is Ready, Register Now With Shine.com!

    www.Shine.Com/Teaching_Jobs

    Companies Hiring Freshers Now. Sign up for Free to Apply.

    MonsterIndia.com

    10,000+ Job Openings across India Upload Resume.Apply to TATA Now!TimesJobs.com/TATA-Hiring

    I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c s

    e / j t h e o r y . h t m 1

  • 7/31/2019 Java Theroy ! Easy to Learn

    2/53

    o f2 4 8

    / 2 0

    / 2 0

    1 1

    1 1 :2 7P M

    A n s : 1 . W r i t e O n c e R u n A n y w h e r e 2 . L i g h t w e i g h t

    c o d e 3 . S e c u r i t y 4 . B u i l t i n G r a p h i c s 5 . O b j e c t

    O r i e n t e d L a n g u a g e 6 . S u p p o r t M u l t i m e d i a 7 . P l a t f o r m

    I n d e p e n d e n t . 8 . O p e n P r o d u c t .

    Q. What do you know about BlueJ?A n s : B l u e J i s a J a v a d e v e l o p m e n t e n v i r o n m e n t . I t i s

    a n I D E ( I n t e g r a t e d D e v e l o p m e n t E n v i r o n m e n t ) ,

    w h i c h i n c l u d e s a n e d i t o r a d e b u g g e r a n d av i e w e r .

    Q. How you create, compile and execute a program in Java or BlueJ? Explain youranswer?

    A n s : C r e a t e : C l i c k o n n e w c l a s s b u t t o n f r o m B l u e J

    e d i t o r , t h e n t y p e t h e c l a s s n a m e a p r o g r a m i c o nw i l l b e c r e a t e d . d o u b l e c l i c k o n i t , a p r o g r a m e d i t o r

    w i l l b e o p e n , e r a s e t h e c o d e a n d t y p e y o u r p r o g r a m

    c o d i n g . C o m p i l e : c l i c k t h e c o m p i l e b u t t o n o n t h el e f t o f t h e w i n d o w o r r i g h t c l i c k o n t h e c l a s s i c o n

    a n d s e l e c t c o m p i l e f r o m t h e m e n u o p t i o n s . E x e c u t e :

    R i g h t c l i c k o n t h e c l a s s i c o n a n d s e l e c t n e w c l a s sn a m e o p t i o n . A d i a l o g u e b o x a p p e a r s t y p e t h e n a m e

    o f t h e o b j e c t . A o b j e c t i c o n w i l l b e c r e a t e d a t t h e

    b o t t o m . R i g h t c l i c k o n t h e o b j e c t i c o n a n d s e l e c tt h e m e t h o d w e w a n t t o e x e c u t e .

    Q. The two types of Java programs/applications are? [2007]A n s : T h e t w o t y p e s o f J a v a A p p l i c a t i o n s a r e

    ' I n t e r n e t A p p l e t s ' a n d ' S t a n d a l o n e a p p l i c a t i o n ' .

    Q. State the distinguishing features of Java and C++?

    A n s : ( i ) J a v a d o e s n o t s u p p o r t o p e r a t o r

    o v e r l o a d i n g . ( i i ) J a v a d o e s n o t u s e p o i n t e r s . ( i i i )T h e r e a r e n o h e a d e r f i l e s i n J a v a . ( i v ) J a v a d o e s

    n o t h a v e t e m p l a t e c l a s s e s a s i n C + + .Q. State the differences between Syntax errors and Logical errors.

    A n s : T h e c o m p i l e r c a n o n l y t r a n s l a t e a p r o g r a m i f

    t h e p r o g r a m i s s y n t a c t i c a l l y c o r r e c t ; o t h e r w i s e

    t h e c o m p i l a t i o n f a i l s a n d y o u w i l l n o t b e a b l e t o

  • 7/31/2019 Java Theroy ! Easy to Learn

    3/53

    r u n y o u r p r o g r a m . S y n t a x r e f e r s t o t h e s t r u c t u r e o f y o u r p r o g r a m a n d t h e r u l e s a b o u t t h a t s t r u c t u r e . T h e

    s e c o n d t y p e o f e r r o r i s a r u n - t i m e e r r o r , s o - c a l l e d

    b e c a u s e t h e e r r o r d o e s n o t a p p e a r u n t i l y o u r u n

    t h e p r o g r a m . I n J a v a , r u n - t i m e e r r o r s o c c u r w h e n

    t h e i n t e r p r e t e r i s r u n n i n g t h e b y t e c o d e a n ds o m e t h i n g g o e s w r o n g .Q. "Object is an instance of a class", explain

    A n s : O b j e c t o f a c l a s s c o n t a i n s d a t a a n d f u n c t i o n s

    p r o v i d e d i n a c l a s s . i t p o s s e s s e s a l l t h e f e a t u r e s

    o f a c l a s s . H e n c e o b j e c t i s t e r m e d a s i n s t a n c e o f a

    c l a s s .

    Q. Name four basic features of JAVA.A n s : B a s i c f e a t u r e s o f J a v a a s f o l l o w s : i ) I t i s a n

    o b j e c t o r i e n t e d l a n g u a g e . i i ) J a v a p r o g r a m i s b o t h

    c o m p i l e d a n d i n t e r p r e t e d . i i i ) J a v a p r o g r a m c a n b ea p p l i c a t i o n o r a p p l e t . i v ) j a v a i s c a s e s e n s i t i v e

    l a n g u a g e , i . e . i t d i s t i n g u i s h e d u p p e r a n d l o w e r c a s el e t t e r s .

    Q. Differentiate between Compiler and Interpreter.

    A n s : C o m p i l e r c o n v e r t s o u r c e c o d e t o m a c h i n el a n g u a g e w h o l e a t a t i m e . I n t e r p r e t e r c o n v e r t s

    p r o g r a m f r o m h i g h l e v e l l a n g u a g e t o m a c h i n e l e v e l

    l a n g u a g e l i n e b y l i n e o r s t a t e m e n t b y s t a t e m e n t .Q. Java uses compiler as well as interpreter, explain.

    A n s : J a v a c o m p i l e r c o n v e r t s J a v a s o u r c e c o d e t o

    b y t e c o d e . T h i s b y t e c o d e i s f u r t h e r c o n v e r t e di n t o m a c h i n e c o d e t o m a k e i t a p p l i c a b l e f o r t h e

    s p e c i f i c p l a t f o r m b y u s i n g i n t e r p r e t e r .

    Q. Differentiate between Source code andByte code.A n s : S o u r c e c o d e i s t h e p r o g r a m d e v e l o p e d i n J a v a

    L a n g u a g e , w h i c h i s i n p u t t o a c o m p u t e r t h r o u g ht h e k e y b o a r d . C o m p i l e r c o n v e r t s s o u r c e c o d e t o b y t e

    c o d e f o r i n t e r p r e t a t i o n .

    Q. Differentiate between Testing and Debugging.

    A n s : T e s t i n g i s t h e p r o c e s s o f c h e c k i n g p r o g r a m

    l o g i c m a n u a l l y t o e n s u r e w h e t h e r i t c o n t a i n s a n ye r r o r o r n o t . D e b u g g i n g i s t h e p r o c e s s o f r e m o v i n g

    e r r o r s f r o m a p r o g r a m .E l e m e n t a r y C o n c e p t s o f O b j e c t & C l a s s

    [ICSE Syllabus on this Topic]Modeling entities and their behavior by objects.

    A class as a specification of objects and as an objectfactory, computation

  • 7/31/2019 Java Theroy ! Easy to Learn

    4/53

    as message passing/function call between objects (many example should bedone to

    I C S E B l u e J

    T h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c se / j t h e o r y . h t m 2o f

    2 4 8

    / 2 0

    / 2 0

    1 1

    1 1 :2 7

    P M

    illustrate this). Object encapsulate state (attribute) and have behaviors(functions). Class as a user definedtype.

    Q. What is an Object? [2006]A n s : A n O b j e c t i s a n i d e n t i f i a b l e e n t i t y w i t h s o m e

    c h a r a c t e r i s t i c s a n d b e h a v i o r . E . g . t a k e a c l a s s

    ' C a r ' . A c a r c l a s s h a s c h a r a c t e r i s t i c s l i k e c o l o u r ,g e a r s , p o w e r , l e n g t h e t c . n o w w e c r e a t e t h e o b j e c t

    o f t h a t c l a s s ' C a r ' n a m e l y ' I n d i c a ' .

    Q. What is OOP? What are the features/concepts in OOP's? [2007]ORName any twoOOP'S principles. [2005]

    A n s : T h e O b j e c t O r i e n t e d P r o g r a m m i n g P a r a d i g m i s

    t h e l a t e s t i n t h e s o f t w a r e d e v e l o p m e n t a n d t h em o s t a d o p t e d o n e i n t h e p r o g r a m m i n g d e v e l o p m e n t .

    T h e P a r a d i g m m e a n s o r g a n i s i n g p r i n c i p l e o f a

    p r o g r a m . I t i s a n a p p r o a c h t o p r o g r a m m i n g . T h ec o n c e p t s o f O O P ' s a r e : ( 1 ) D a t a A b s t r a c t i o n ( 2 )

    D a t a E n c a p s u l a t i o n ( 3 ) M o d u l a r i t y ( 4 ) I n h e r i t a n c e ( 5 )P o l y m o r p h i s m .

    Q. Explain all the Concepts of OOP's?

    A n s : A b s t r a c t i o n : I t r e f e r s t o t h e a c t o f

    r e p r e s e n t i n g e s s e n t i a l f e a t u r e s w i t h o u t i n c l u d i n g

    t h e b a c k g r o u n d d e t a i l s o r e x p l a n a t i o n .E n c a p s u l a t i o n : I t i s t h e w a y o f c o m b i n i n g b o t h d a t a

    a n d t h e f u n c t i o n t h a t o p e r a t e s o n t h e d a t a u n d e r as i n g l e u n i t . M o d u l a r i t y : I t i s t h e p r o p e r t y o f a

    s y s t e m t h a t h a s b e e n d e c o m p o s e d i n t o a s e t o f

    c o h e s i v e a n d l o o s e l y c o u p l e m o d u l e s . I n h e r i t a n c e :

    I t i s t h e c a p a b i l i t y o f o n e c l a s s o f t h i n g t o

  • 7/31/2019 Java Theroy ! Easy to Learn

    5/53

    i n h e r i t p r o p e r t i e s f r o m a n o t h e r c l a s s . P o l y m o r p h i s m :I t i s t h e a b i l i t y f o r a m e s s a g e o r d a t a t o b e

    p r o c e s s e d i n m o r e t h e n o n e f o r m .

    Q. What are the advantages of OOP's?

    A n s : ( 1 ) E l i m i n a t i o n o f r e d u n d a n t c o d i n g s y s t e m

    a n d u s a g e o f e x i s t i n g c l a s s e s t h r o u g h i n h e r i t a n c e .( 2 ) P r o g r a m c a n b e d e v e l o p e d b y s h a r i n g e x i s t i n gm o d u l e s . ( 3 ) P o s s i b i l i t i e s o f m u l t i p l e i n s t a n c e o f

    a n o b j e c t s w i t h o u t a n y i n t e r f e r e n c e . ( 4 ) S e c u r i t y o f

    d a t a v a l u e s f r o m o t h e r s e g m e n t o f t h e p r o g r a m

    t h r o u g h d a t a h i d i n g .

    Q. What is Class? How Object is related to the Class?

    A n s : A C l a s s r e p r e s e n t a s e t o f O b j e c t s t h a t s h a r ec o m m o n c h a r a c t e r i s t i c s a n d b e h a v i o r . O b j e c t s

    a r e i n s t a n c e o f a c l a s s . T h e O b j e c t r e p r e s e n t s t h e

    a b s t r a c t i o n r e p r e s e n t a t i o n b y t h e c l a s s i n t h e r e a ls e n s e .

    Q. What is the need of a class in Java?A n s : C l a s s e s i n J a v a a r e n e e d e d t o r e p r e s e n t r e a l -

    w o r l d e n t i t i e s , w h i c h h a v e d a t a t y p e p r o p e r t i e s .

    C l a s s e s p r o v i d e c o n v e n i e n t m e t h o d s f o r p a c k i n gt o g e t h e r a g r o u p o f l o g i c a l r e l a t e d d a t a i t e m s a n d

    f u n c t i o n s t h a t w o r k o n t h e m . I n j a v a t h e d a t a i t e m s

    a r e c a l l e d f i e l d s & t h e f u n c t i o n s a r e c a l l e dm e t h o d s .

    Q. What are Methods? How are these related to an Objects?

    A n s : A M e t h o d i s a n o p e r a t i o n a s s o c i a t e d t o a nO b j e c t . T h e b e h a v i o r o f a n O b j e c t i s r e p r e s e n t e d

    t h r o u g h a s s o c i a t e d f u n c t i o n , w h i c h a r e c a l l e d

    M e t h o d s .Q. Point out the differences between Procedural Programming and Object Oriented

    Programming.A n s : P r o c e d u r a l p r o g r a m m i n g a i m s m o r e a t

    p r o c e d u r e s . T h e e m p h a s i s i s a d o i n g t h i n g s r a t h e r

    t h e n t h e d a t a b e i n g u s e d . I n p r o c e d u r a l P r o g r a m m i n g

    p a r a d i n g d a t a a r e s h a r e d a m o n g a l l t h e

    f u n c t i o n s p a r t i c i p a t i n g t h e r e b y r i s k i n g d a t a s a f e t ya n d s e c u r i t y . O b j e c t O r i e n t e d P r o g r a m m i n g i s b a s e d

    o n p r i n c i p l e s o f d a t a h i d i n g , a b s t r a c t i o n ,i n h e r i t a n c e a n d p o l y m o r p h i s m . I t i m p l e m e n t s

    p r o g r a m s u s i n g c l a s s e s a n d o b j e c t s , I n O O P ' s d a t a

    a n d p r o c e d u r e b o t h g i v e n e q u a l i m p o r t a n c e . D a t a

  • 7/31/2019 Java Theroy ! Easy to Learn

    6/53

    a n d f u n c t i o n s a r e e n c a p s u l a t e d t o e n s u r e d a t as a f e t y a n d s e c u r i t y .

    Q. What is an abstraction?

    A n s : A n a b s t r a c t i o n i s a n a m e d c o l l e c t i o n o f

    a t t r i b u t e s a n d b e h a v i o r s r e q u i r e d t o r e p r e s e n t a n

    e n t i t y o r c o n c e p t f o r s o m e p a r t i c u l a r p r o b l e md o m a i n .Q. What is

    and how it is useful in Java. [2008]

    A n s : I t i s p r o c e s s b y w h i c h o b j e c t s o f o n e c l a s s

    a c q u i r e t h e p r o p e r t i e s o f o b j e c t s o f a n o t h e r

    c l a s s . I n h e r i t a n c e s u p p o r t s t h e c o n c e p t s o f h i e r a r c h i c a l r e p r e s e n t a t i o n . I n O O P t h e c o n c e p t s o f

    i n h e r i t a n c e p r o v i d e s t h e i d e a o f r e u s a b i l i t y .

    Q. What role does polymorphism play as java feature?A n s : I t m e a n t h e a b i l i t y t o t a k e m o r e t h a n o n e

    f o r m . F o r e x a m p l e , a n o p e r a t i o n , m a n y t y p e s o f d a t a u s e d i n t h e o p e r a t i o n .

    Q. What is Data hiding?

    I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c se / j t h e o r y . h t m 3

    o f

    2 4 8/ 2 0

    / 2 0

    1 11 1 :

    2 7P M

    A n s : D a t a H i d i n g m e a n s r e s t r i c t i n g t h e a c c e s s i b i l i t y

    o f d a t a a s s o c i a t e d w i t h a n o b j e c t i n s u c h a w a y

    t h a t i t c a n b e u s e d o n l y t h r o u g h t h e m e m b e r

    m e t h o d s o f t h e o b j e c t .Q. What are nested classes?

    A n s : I t i s p o s s i b l e t o d e f i n e a c l a s s w i t h i n a n o t h e rc l a s s , s u c h c l a s s e s a r e k n o w n a s n e s t e d c l a s s e s .

    A n e s t e d c l a s s h a s a c c e s s t o t h e m e m b e r s

    i n c l u d i n g p r i v a t e m e m b e r s o f t h e c l a s s i n w h i c h i t

  • 7/31/2019 Java Theroy ! Easy to Learn

    7/53

    i s n e s t e d . H o w e v e r t h e e n c l o s i n g c l a s s n o t h a v ea c c e s s t o t h e m e m b e r s o f t h e n e s t e d c l a s s .

    Q. Differentiate between

    and

    class. [2008]A n s : B A S E C L A S S - A c l a s s f r o m w h i c h a n o t h e r

    c l a s s i n h e r i t s ( A l s o c a l l e d S U P E R C L A S S ) D E R I V E D

    C L A S S - A c l a s s i n h e r i t i n g p r o p e r t i e s f r o m a n o t h e r

    c l a s s . ( A l s o c a l l e d S U B C L A S S )

    C l a s s a s t h e B a s i s o f a l l C o m p u t a t i o n

    [ICSE Syllabus on this Topic]Objects encapsulates state and behavior -numerous example, member variables, attributes or features.Variable define

    states, Member functions/operation/methods/messages defines behaviors.

    Class asabstractions for set of objects, class as an object factory, concept of type,primitive data types, compositedata types. Var iable declaration for both types,

    diffe rence between the two types. Objects as instance of a class. Modeling bycomposition.

    Q. What are keywords? can keywords be used as a identifiers?

    A n s : K e y w o r d s a r e t h e w o r d s t h a t c o n v e y a s p e c i a lm e a n i n g t o t h e l a n g u a g e c o m p i l e r . N o , k e y w o r d s

    c a n n e v e r b e u s e d a s i d e n t i f i e r s .

    Q. What is an identifier? What is the identifier formatting rule of Java? OR What arethe rules for naming a variable?

    A n s : I d e n t i f i e r s a r e n a m e s g i v e n t o d i f f e r e n t p a r t s

    o f a p r o g r a m e . g . v a r i a b l e s , f u n c t i o n s , c l a s s e s e t c .T h e i d e n t i f i e r s i n J a v a . ( i ) C a n c o n t a i n s a l p h a b e t s ,

    d i g i t s , d o l l a r s i g n a n d u n d e r s c o r e . ( i i ) M u s t n o t

    s t a r t w i t h a d i g i t . ( i i i ) C a n n o t b e a J a v ak e y w o r d s . ( i v ) C a n h a v e a n y l e n g t h a n d a r e c a s e -

    s e n s i t i v e .Q. Why keyword is different from identifiers?

    A n s : K e y w o r d s a r e p r e d e f i n e s e t s o f w o r d s t h a t

    h a v e a s p e c i a l m e a n i n g f o r t h e J a v a c o m p i l e r .

    I d e n t i f i e r s o n t h e o t h e r h a n d a r e c r e a t e d b y J a v a

    p r o g r a m m e r s i n o r d e r t o g i v e n a m e s t o v a r i a b l e s ,f u n c t i o n , c l a s s e s e t c .

    Q. State the difference between Token and Identifier.[2008]A n s : T h e s m a l l e s t i n d i v i d u a l u n i t o f a p r o g r a m i s

    k n o w n a s T o k e n . T h e f o l l o w i n g T o k e n s a r e a v a i l a b l e

    i n J a v a : K e y w o r d s , I d e n t i f i e r s , L i t e r a l s ,

    P u n c t u a t i o n s , O p e r a t o r s . I d e n t i f i e r s a r e n a m e s g i v e n

  • 7/31/2019 Java Theroy ! Easy to Learn

    8/53

    t o d i f f e r e n t p a r t s o f a p r o g r a m e . g . v a r i a b l e s ,f u n c t i o n s , c l a s s e s e t c . T h e i d e n t i f i e r s i n J a v a .

    Q. What are literals? How many types of integer literals are avail able in

    Java?

    A n s : A l i t e r a l i s s e q u e n c e o f c h a r a c t e r s u s e d i n a

    p r o g r a m t o r e p r e s e n t a c o n s t a n t v a l u e . F o r e x a m p l e' A ' i s a l i t e r a l t h a t r e p r e s e n t s t h e v a l u e A o f t y p ec h a r , a n d 1 7 L i s a l i t e r a l t h a t r e p r e s e n t s t h e

    n u m b e r 1 7 a s v a l u e o f t y p e l o n g . D i f f e r e n t t y p e s o f

    l i t e r a l s a v a i l a b l e i n J a v a , t h e y a r e : I n t e g e r l i t e r a l ,

    F l o a t l i t e r a l , B o o l e a n l i t e r a l , C h a r a c t e r l i t e r a l ,

    S t r i n g l i t e r a l a n d n u l l l i t e r a l .

    Q. What is an integer constant? Write integer forming rule of Java.A n s : I n t e g e r c o n s t a n t s a r e w h o l e n u m b e r s w i t h o u t

    a n y d e c i m a l p a r t . T h e r u l e f o r f o r m i n g a n

    i n t e g e r c o n s t a n t s i s : A n i n t e g e r c o n s t a n t m u s t h a v ea t l e a s t o n e d i g i t a n d c a n n o t c o n t a i n a d e c i m a l

    p o i n t . I t m a y c o n t a i n s + o r - s i g n . A n u m b e r w i t h n os i g n i s i n t e r p r e t e d t o b e p o s i t i v e .

    Q. What do you mean by Escape sequence and name few escape sequences in Java?

    A n s : J a v a h a v e c e r t a i n n o n g r a p h i c c h a r a c t e r s( n o n g r a p h i c c h a r a c t e r s a r e t h o s e c h a r a c t e r s t h a t

    c a n n o t b e t y p e d d i r e c t l y f r o m k e y b o a r d e . g .

    b a c k s p a c e , t a b , c a r r i a g e r e t u r n e t c . ) . T h o s en o n g r a p h i c c h a r a c t e r c a n b e r e p r e s e n t e d b y e s c a p e

    s e q u e n c e . A n e s c a p e s e q u e n c e i s r e p r e s e n t e d b y

    b a c k s l a s h f o l l o w e d b y o n e o r m o r e c h a r a c t e r . T h ef e w e s c a p e s e q u e n c e c h a r a c t e r s a r e : \ n f o r n e w

    l i n e , \ t f o r H o r i z o n t a l T a b , \ v f o r V e r t i c a l T a b , \ b

    f o r B a c k s p a c e , \ " f o r D o u b l e Q u o t e s e t c .Q. How many integer constants are allowed in Java? How are they written?

    I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c s

    e / j t h e o r y . h t m 4

    o f2 4 8

    / 2 0/ 2 0

    1 1

    1 1 :

  • 7/31/2019 Java Theroy ! Easy to Learn

    9/53

    2 7P M

    A n s : J a v a a l l o w s t h r e e t y p e s o f i n t e g e r c o n s t a n t s :

    O c t a l ( b a s e 8 ) , D e c i m a l ( b a s e 1 0 ) , a n d

    H e x a d e c i m a l ( b a s e 1 6 ) . A n O c t a l i n t e g e r m u s t b e

    s t a r t e d w i t h a z e r o ' 0 ' , a H e x a d e c i m a l i n t e g e rs t a r t s w i t h a ' 0 X ' , a l l o t h e r s a r e t r e a t e d a s d e c i m a li n t e g e r c o n s t a n t .

    Q. What is meant by a floating constant in Java? How many ways can a floating

    constant be represented into?

    A n s : F l o a t i n g c o n s t a n t s a r e r e a l n u m b e r s . A

    f l o a t i n g c o n s t a n t c a n e i t h e r b e a f r a c t i o n a l o r i n

    e x p o n e n t f o r m .Q. Differentiate between Integer and Floating type constants.

    A n s : I n t e g e r c o n s t a n t s a r e t h e w h o l e n u m b e r s

    ( w i t h o u t d e c i m a l p o i n t s ) . e . g . 1 2 3 1 . F l o a t i n gp o i n t c o n s t a n t s a r e f r a c t i o n a l n u m b e r s ( n u m b e r w i t h

    d e c i m a l p o i n t s ) . e . g . 1 4 . 2 3 5 6Q. Write the following real constants into fractional form: 0.113E04, 0.417E-04, 0.4E-05,

    0.123E02

    A n s : 0 . 1 1 3 E 0 4 b e c o m e s 1 1 3 0 , 0 . 4 1 7 E - 0 4 b e c o m e s. 0 0 0 0 4 1 7 , 0 . 4 E - 0 5 b e c o m e s . 0 0 0 0 0 4 ,

    0 . 1 2 3 E 0 2 b e c o m e s 1 2 . 3

    Q. What is a type or 'Data Type'? How this term is related to programming?A n s : A t y p e o r d a t a t y p e r e p r e s e n t s a s e t o f

    p o s s i b l e v a l u e s . W h e n w e s p e c i f y t h a t a v a r i a b l e

    h a s c e r t a i n t y p e , w e a r e s a y i n g w h a t v a l u e s t h ee x p r e s s i o n c a n h a v e . F o r e x a m p l e t o s a y t h a t a

    v a r i a b l e i s o f t y p e i n t s a y s t h a t i n t e g e r v a l u e s i n a

    c e r t a i n r a n g e c a n b e s t o r e d i n t h a t v a r i a b l e .Q. What is primitive data type? Name its different types.

    A n s : P r i m i t i v e d a t a t y p e s a r e t h o s e t h a t a r e n o tc o m p o s e d o f o t h e r d a t a t y p e s . N u m e r i c

    I n t e g r a l , F r a c t i o n a l , c h a r a c t e r a n d b o o l e a n a r e

    d i f f e r e n t p r i m i t i v e d a t a t y p e s .

    Q. State the two kind on data types? [2006]

    A n s : T h e t w o t y p e s o f d a t a t y p e s a r e : P r i m i t i v e a n dn o n - p r i m i t i v e / c o m p o s i t e / u s e r d e f i n e d a t a t y p e s .

    T h e p r i m i t i v e d a t a t y p e s a r e : b y t e , s h o r t , i n t , l o n g ,f l o a t , d o u b l e , c h a r a n d B o o l e a n . T h e n o n -

    p r i m i t i v e / r e f e r e n c e d a t a t y p e s a r e : c l a s s , a r r a y a n d

    i n t e r f a c e .

  • 7/31/2019 Java Theroy ! Easy to Learn

    10/53

    Q. Write down the names of three primitive and three non-primitive/reference datatypes in Java/BlueJ.

    A n s : T h e p r i m i t i v e d a t a t y p e s a r e : b y t e , s h o r t , i n t ,

    l o n g , f l o a t , d o u b l e , c h a r a n d B o o l e a n . T h e n o n -

    p r i m i t i v e / r e f e r e n c e d a t a t y p e s a r e : c l a s s , a r r a y a n d

    i n t e r f a c e .Q. How many bytes occupied by the following data types: byte, short, int, long, float,double, char, boolean.

    A n s : c h a r - 2 b y t e , b y t e - 1 b y t e , s h o r t - 2 b y t e s , i n t - 4

    b y t e s , l o n g - 8 b y t e s , f l o a t - 4 b y t e s , d o u b l e - 8

    b y t e s , b o o l e a n - J a v a r e s e r v e 8 b i t s b u t o n l y u s e 1

    b i t .

    Q. What is the range of the following data types: byte, short, int, long, float, double,char, boolean.

    A n s : b y t e - > - 1 2 8 t o 1 2 7 s h o r t - > - 3 2 7 6 8 t o 3 2 7 6 7 i n t -

    > - 231

    to 231

    -1l o n g - > - 2

    63to 2

    63

    -1f l o a t - > - 3 . 4 x 1 038

    t o 3 . 4 x 1 0

    38d o u b l e - > - 1 . 7 x 1 0

    308

    t o 1 . 7 x 1 0308

    c h a r - > 0 t o 6 5 5 3 6 b o o l e a n - > t r u e o r f a l s eQ. What is the largest and smallest value for floating point primitive data types float?

    A n s : T h e s m a l l e s t v a l u e i s - 3 . 4 E + 3 8 a n d l a r g e s t

    v a l u e s i s 3 . 4 E + 3 8 o f f l o a t i n g p o i n t d a t a t y p e .

    Q. What is Token? What are the tokens available in Java? [2008]

    A n s : T h e s m a l l e s t i n d i v i d u a l u n i t o f a p r o g r a m i sk n o w n a s T o k e n . T h e f o l l o w i n g T o k e n s a r e a v a i l a b l e

    i n J a v a : - K e y w o r d s , I d e n t i f i e r s , L i t e r a l s ,P u n c t u a t i o n s , O p e r a t o r s .

    Q. What do you mean by variables? [2006]

  • 7/31/2019 Java Theroy ! Easy to Learn

    11/53

    A n s : A v a r i a b l e i s a n a m e d m e m o r y l o c a t i o n , w h i c hh o l d s a d a t a v a l u e o f a p a r t i c u l a r d a t a t y p e s .

    E . g . d o u b l e p ;

    Q. What do you mean by variables? What do you mean by dynamic initialization of a

    variable?

    A n s : A v a r i a b l e i s a n a m e d m e m o r y l o c a t i o n , w h i c hh o l d s a d a t a v a l u e o f a p a r t i c u l a r d a t a t y p e s .W h e n a m e t h o d o r f u n c t i o n s i s c a l l e d a n d t h e r e t u r n

    v a l u e i s i n i t i a l i s e t o a v a r i a b l e i s c a l l e d d y n a m i c

    i n i t i a l i s a t i o n . e x a m p l e d o u b l e p = M a t h . p o w ( 2 , 3 ) ;

    Q. What is the function of an operator?

    I C S E B l u e J

    T h e o r y h t t p : / / w w w . a mi t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c s

    e / j t h e o r y . h t m 5o f

    2 4 8/ 2 0

    / 2 0

    1 11 1 :

    2 7

    P MA n s : O p e r a t o r s a r e s p e c i a l s y m b o l s t h a t r e p r e s e n t

    o p e r a t i o n s t h a t c a n b e c a r r i e d o u t o n

    v a r i a b l e s , c o n s t a n t s o r e x p r e s s i o n s .Q. What do you mean by operator and write the name of all operators given in your

    textbook.

    A n s : T h e o p e r a t i o n s a r e r e p r e s e n t e d b y o p e r a t o r sa n d t h e o b j e c t o f t h e o p e r a t i o n s a r e r e f e r r e d t o

    a s o p e r a n d s . T h e t y p e s o f O p e r a t o r s a v a i l a b l e i nJ a v a a r e : 1 . A r i t h m e t i c 2 . I n c r e m e n t / D e c r e m e n t 3 .

    R e l a t i o n a l 4 . L o g i c a l 5 . S h i f t 6 . B i t w i s e 7 .

    A s s i g n m e n t 8 . C o n d i t i o n a l 9 . [ ] o p e r a t o r 1 0 . n e w

    o p e r a t o r 1 1 . ( t y p e ) c a s t O p e r a t o r 1 2 . ( ) o p e r a t o r .

    1 3 . d o t o p e r a t o r .Q. What are arithmetic operators?

    A n s : A r i t h m e t i c a l o p e r a t o r s a r e u s e d f o r v a r i o u sm a t h e m a t i c a l c a l c u l a t i o n s . T h e r e s u l t o f a n

    a r i t h m e t i c a l e x p r e s s i o n i s a n u m e r i c a l v a l u e s .

    A r i t h m e t i c a l o p e r a t o r s a r e o f f o l l o w i n g t y p e s :

    U n a r y a n d B i n a r y o p e r a t o r s .

  • 7/31/2019 Java Theroy ! Easy to Learn

    12/53

    Q. Write major difference between the unary and binary operators?A n s : T h e o p e r a t o r s t h a t a c t s o n o n e o p e r a n d a r e

    r e f e r r e d t o a s U n a r y O p e r a t o r . T h e r e a r e t w o

    U n a r y o p e r a t o r s U n a r y + o p e r a t o r a n d U n a r y -

    o p e r a t o r . T h e o p e r a t o r s t h a t a c t s u p o n t w o

    o p e r a n d s a r e r e f e r r e d t o a s B i n a r y O p e r a t o r . T h eB i n a r y O p e r a t o r s a r e A d d i t i o n ( + ) , S u b t r a c t i o n ( - ) ,M u l t i p l i c a t i o n ( * ) , D i v i s i o n ( / ) a n d M o d u l u s ( % ) .

    Q. What is increment operator? What are postfix and prefix increment operators?

    A n s : T h e ' + + ' o p e r a t o r i s c a l l e d i n c r e m e n t

    o p e r a t o r . T h e i n c r e m e n t o p e r a t o r s a d d 1 t o i t s

    o p e r a n d . T h e s e a r e t w o t y p e s ( i ) P r e f i x a n d ( i i )

    P o s t f i x T h e p r e f i x v e r s i o n c o m e s b e f o r e t h eo p e r a n d f o r e . g . + + a , w h e r e a s p o s t f i x c o m e s a f t e r

    t h e o p e r a n d e . g . a + +

    Q. Find the value of x after evaluating x += x++ + --x + 4 where x=3 before theevaluation. Explain your answer.

    A n s : R e s u l t i s 1 3 , b e c a u s e x + + i s 3 , - - x i s 2 + 4t h e a n s w e r i s 9 a d d t h i s w i t h x t h a t i s 3 i t

    b e c o m e s 1 2 a n d d u e t o p r e i n c r e m e n t o f x + + t h e

    r e s u l t b e c o m e s 1 3 .Q. What do you mean by Relational Operators.

    A n s : R e l a t i o n a l o p e r a t o r s a r e u s e d t o d e t e r m i n e

    t h e r e l a t i o n s h i p b e t w e e n d i f f e r e n t o p e r a n d s . T h e s ea r e u s e d i n w o r k o f c o m p r e s s i o n a l s o . T h e r e l a t i o n a l

    e x p r e s s i o n ( c o n d i t i o n ) r e t u r n s 0 i f t h e r e l a t i o n i s

    f a l s e a n d r e t u r n 1 i f t h e r e l a t i o n i s t r u e . < ( l e s st h e n ) , > ( g r e a t e r t h e n ) , < = ( l e s s t h e n e q u a l s t o ) ,

    > = ( g r e a t e r t h e n e q u a l s t o ) , = = ( e q u a l s t o ) , ! = ( n o t

    e q u a l s t o ) .Q. What is Logical operators?

    A n s : T h e l o g i c a l o p e r a t o r s c o m b i n e t h e r e s u l t o f o rm o r e t h e n t w o e x p r e s s i o n s . T h e m o d e o f

    c o n n e c t i n g r e l a t i o n s h i p i n t h e s e e x p r e s s i o n s r e f e r s

    a s l o g i c a l a n d t h e e x p r e s s i o n s a r e c a l l e d l o g i c a l

    e x p r e s s i o n . T h e l o g i c a l e x p r e s s i o n r e t u r n s 1 i f t h e

    r e s u l t i s t r u e o t h e r w i s e 0 r e t u r n s . T h e l o g i c a lo p e r a t o r s p r o v i d e d b y J a v a a r e & & L o g i c a l A N D , | |

    L o g i c a l O R , ! L o g i c a l N O T .Q. What do you man by Assignment Statement or Assignment Operator?

    A n s : A s s i g n m e n t o p e r a t o r i s r e p r e s e n t b y s y m b o l

    ' = ' . I t t a k e s t h e v a l u e o n t h e r i g h t a n d s t o r e s i t i n

  • 7/31/2019 Java Theroy ! Easy to Learn

    13/53

    t h e v a r i a b l e o n t h e l e f t s i d e . f o r e x a m p l e x = y +3 0

    Q. What do you mean by Shift operators? OR Differentiate between Shift LEFT and

    Shift RIGHT operators.

    A n s : A S h i f t o p e r a t o r s p e r f o r m s b i t m a n i p u l a t i o n o n

    d a t a b y s h i f t i n g t h e b i t s o f i t s f i r s t o p e r a n d r i g h tt o l e f t . T h e s h i f t o p e r a t o r s a v a i l a b l e i n J a v a a r e : ( 1 )> > s h i f t b i t s o f r i g h t b y d i s t a n c e . ( s i g n e d

    s h i f t i n g ) ( 2 ) < < s h i f t b i t s o f l e f t b y d i s t a n c e .

    ( s i g n e d s h i f t i n g ) ( 3 ) > > > s h i f t b i t s o f r i g h t b y

    d i s t a n c e ( u n s i g n e d s h i f t i n g )

    Q. Differentiate between Shift LEFT and Shift RIGHT operators.

    A n s : S h i f t L E F T ( < < ) o p e r a t r s h i f t s t h e b i t p a t t e r no f t h e o p e r a n d t o w a r d s l e f t b y d e f i n e d n u m b e r o f

    b i t s . S h i f t R I G H T ( > > ) o p e r a t o r s h i f t s t h e b i t p a t t e r n

    o f t h e o p e r a n d t o w a r d s r i g h t b y d e f i n e d n u m b e r o f b i t s . e . g . 1 3 > > 2 i s 3 b i n a r y v a l u e o f 1 3 i s 1 1 0 1 > > 2 i s

    0 0 1 1 i s e q u i v a l e n t t o 3 . S i m i l a r l y L E F T s h i f t ( < < )o p e r a t o r i s a l s o w o r k .

    Q. What do you mean by Bitwise operators?

    A n s : T h e B i t w i s e o p e r a t i o n s a r e p e r f o r m e d b yB i t w i s e o p e r a t o r . T h e B i t w i s e o p e r a t i o n s c a l c u l a t e

    e a c h b i t o f t h e i r r e s u l t b y c o m p a r i n g t h e

    c o r r e s p o n d i n g b i t s o f t h e t w o o p e r a n d s . ( a ) T h e A N Do p e r a t o r & ( b ) T h e O R o p e r a t o r | ( c ) T h e X O R

    o p e r a t o r ^ ( d ) T h e c o m p l i m e n t o p e r a t o r ~

    I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c se / j t h e o r y . h t m 6

    o f2 4 8

    / 2 0

    / 2 0

    1 1

    1 1 :2 7

    P MQ. Illustrate '?' operator with an example? [2009]

    A n s : I t i s a c o n d i t i o n a l o p e r a t o r , t h a t s t o r e s a

    v a l u e d e p e n d i n g u p o n a c o n d i t i o n . T h i s o p e r a t o r i s

    a l s o k n o w n a s t e r n a r y o p e r a t o r . T h e s y n t a x f o r t h i s

  • 7/31/2019 Java Theroy ! Easy to Learn

    14/53

    o p e r a t o r i s e x p r e s s i o n 1 ? e x p r e s s i o n 2 : e x p r e s s i o n 3 .a n d t h e e x a m p l e i s b o n u s = s a l e s > 1 5 0 0 0 ? 2 5 0 : 5 0 ;

    Q. What is the purpose of new operator?

    [2006]

    A n s : W e c a n u s e n e w o p e r a t o r t o c r e a t e a n e w

    o b j e c t s o r n e w a r r a y . E x . m y C l a s s o b j = n e wm y C l a s s ( ) ; i n t a r r [ ] = n e w i n t [ 5 ] ;Q. What do you mean by precedence? Illustrate with the help of example.

    A n s : P r e c e d e n c e i s t h e o r d e r i n w h i c h a p r o g r a m

    e v a l u a t e s t h e o p e r a t i o n s i n a f o r m u l a o r

    e x p r e s s i o n . A l l o p e r a t o r s h a v e p r e c e d e n c e v a l u e . A n

    o p e r a t o r w i t h h i g h e r p r e c e d e n c e v a l u e i s e v a l u a t e d

    f i r s t t h e n t h e o p e r a t o r h a v i n g l o w e r p r e c e d e n c ev a l u e . c o n s i d e r t h e f o l l o w i n g e x a m p l e x = 5 + 4

    * 6 ; T h e v a l u e o f t h i s e x p r e s s i o n i s 2 9 n o t 5 4 o r 3 4 .

    M u l t i p l i c a t i o n h a s b e e n p e r f o r m e d f i r s t i n t h i se x p r e s s i o n .

    Q. What is operands?A n s : A n o p e r a t o r a c t s o n d i f f e r e n t d a t a

    i t e m s / e n t i t i e s c a l l e d o p e r a n d s .

    Q. What do you mean by constant? How you declare a variable as constant variables.A n s : T h e m e m o r y v a r i a b l e s / l o c a t i o n s w h o s e v a l u e s

    c a n n o t b e c h a n g e d w i t h i n t h e p r o g r a m i s

    c a l l e d c o n s t a n t s . T h e k e y w o r d f i n a l m a k e s a v a r i a b l ea s c o n s t a n t s .

    Q. Which class is used for using different mathematical function in Java program?

    [2007]A n s : T h e c l a s s u s e d f o r d i f f e r e n t m a t h e m a t i c a l

    f u n c t i o n s i n J a v a i s j a v a . l a n g . M a t h

    Q. Write down the equivalent expression for the mathematical expression (a) (cos x/tan-1

    x)+x (b) |ex

    - x|

    A n s : ( M a t h . c o s ( x ) / M a t h . a t a n ( x ) ) + x a n d

    M a t h . a b s ( M a t h . e x p ( x ) - x )

    Q. What is the difference between these two function Math.ceil() and Math.rint(), explainwith example.

    A n s : M a t h . c e i l ( ) t h i s f u n c t i o n r e t u r n s t h e s m a l l e s tw h o l e n u m b e r g r e a t e r t h e n o r e q u a l t o t h e

    g i v e n n u m b e r . e . g . M a t h . c e i l ( 1 2 . 8 5 ) g i v e s o u t p u t 1 3

    a n d M a t h . c e i l ( 1 2 . 3 5 ) a l s o g i v e s o u t p u t 1 3 . W h e r e a s

    t h e M a t h . r i n t ( ) r e t u r n s t h e r o u n d u p n e a r e s t i n t e g e r

  • 7/31/2019 Java Theroy ! Easy to Learn

    15/53

    v a l u e . e . g . M a t h . r i n t ( 1 2 . 8 5 ) g i v e s o u t p u t 1 3b u t M a t h . r i n t ( 1 2 . 3 5 ) g i v e s o u t p u t 1 2 .

    Q. What do you mean by type conversion? What is the difference between implicit and

    explicit type conversion explainwith example.

    A n s : T h e p r o c e s s o f c o n v e r t i n g o n e p r e d e f i n e d t y p e

    i n t o a n o t h e r i s c a l l e d T y p e C o n v e r s i o n . A i m p l i c i tt y p e c o n v e r s i o n i s a c o n v e r s i o n p e r f o r m e d b y t h ec o m p i l e r . T h e J a v a c o m p i l e r c o n v e r t s a l l o p e r a n d s

    u p t o t h e t y p e o f t h e l a r g e s t o p e r a n d . T h i s i s a l s o

    k n o w n a s t y p e p r o m o t i o n . e . g . ' c ' - 3 2 i s c o n v e r t e d t o

    i n t t y p e . W h e r e a s a n e x p l i c i t t y p e c o n v e r s i o n i s

    u s e r d e f i n e d t h a t f o r c e s a n e x p r e s s i o n t o b e o f

    s p e c i f i c t y p e , t h i s a l s o k n o w n a s t y p e c a s t i n g . e . g .( f l o a t ) ( x + y / 2 )

    Q. What is coercion? How it is implemented?

    A n s : I m p l i c i t t y p e c o n v e r s i o n o f a n e x p r e s s i o n i st e r m e d a s c o e r c i o n . A i m p l i c i t t y p e c o n v e r s i o n i s

    a c o n v e r s i o n p e r f o r m e d b y t h e c o m p i l e r . T h e J a v ac o m p i l e r c o n v e r t s a l l o p e r a n d s u p t o t h e t y p e o f

    t h e l a r g e s t o p e r a n d . T h i s i s d e f a u l t t y p e c o n v e r s i o n .

    Q. What do you mean by type casting? What is the type cast operator? [2007]A n s : T h e e x p l i c i t c o n v e r s i o n o f a n o p e r a n d t o a

    s p e c i f i c t y p e i s c a l l e d t y p e c a s t i n g . T h e o p e r a t o r

    t h a t c o n v e r t s i t s o p e r a n d t o a s p e c i f i e d t y p e i sc a l l e d t h e t y p e c a s t o p e r a t o r . T h e t y p e c a s t o p e r a t o r

    i s ( ) i n J a v a a n d i s u s e d a s ( t y p e - t o - b e - c o n v e r t e d -

    i n )Q. Explain the methods print() and println()?

    A n s : A c o m p u t e r p r o g r a m i s w r i t t e n t o m a n i p u l a t e a

    g i v e n s e t o f d a t a a n d t o d i s p l a y o r p r i n t t h er e s u l t s . J a v a s u p p o r t s t w o o u t p u t m e t h o d s t h a t c a n

    b e u s e d t o s e n d t h e r e s u l t s t o t h e s c r e e n . p r i n t ( )m e t h o d p r i n t l n ( ) m e t h o d . T h e p r i n t ( ) m e t h o d s e n d s

    i n f o r m a t i o n i n t o a b u f f e r . T h i s b u f f e r i s n o t

    f l u s h e d u n t i l a n e w l i n e ( o r e n d - o f - l i n e ) c h a r a c t e r

    i s s e n t . A s a r e s u l t p r i n t ( ) m e t h o d p r i n t s o u t p u t o n

    o n e l i n e . T h e p r i n t l n ( ) m e t h o d b y c o n t r a s t t a k e s t h ei n f o r m a t i o n p r o v i d e d a n d d i s p l a y s i t o n a l i n e

    f o l l o w e d b y a l i n e f e e d .Q. What is an Expression? Explain its different types.

    I C S E B l u e J

    T h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

  • 7/31/2019 Java Theroy ! Easy to Learn

    16/53

    r g . i n / m a t e r i a l s / i c se / j t h e o r y . h t m 7

    o f

    2 4 8

    / 2 0

    / 2 01 11 1 :

    2 7

    P M

    A n s : A n E x p r e s s i o n i s a n y s t a t e m e n t w h i c h i s

    c o m p o s e d o f o n e o r m o r e o p e r a n d s a n d r e t u r n a

    v a l e . I t m a y b e c o m b i n a t i o n o f o p e r a t o r s , v a r i a b l e sa n d c o n s t a n t s . T h e r e a r e t h r e e d i f f e r e n t t y p e s o f

    e x p r e s s i o n s . ( 1 ) C o n s t a n t E x p r e s s i o n s : 8 * 1 2 / 2 ( 2 )

    I n t e g r a l E x p r e s s i o n s : f o r m e d b y c o n n e c t i n g i n t e g e rc o n s t a n t s x = ( a + b ) / 2 ( 3 ) L o g i c a l E x p r e s s i o n s : a >

    b o r a ! = bQ. Mention two different styles of expressing a

    comment

    in a program. [2005]A n s : T h e t w o w a y s o f i n s e r t i n g a c o m m e n t s i n a

    p r o g r a m a r e : ( i ) u s i n g / / s i n g l e l i n e c o m m e n t s ( i i )

    u s i n g / * * / m u l t i p l e l i n e c o m m e n t sQ. Differentiate between

    operator

    andexpression

    . [2005]

    A n s : T h e o p e r a t i o n s a r e r e p r e s e n t e d b y o p e r a t o r sa n d t h e o b j e c t o f t h e o p e r a t i o n s a r e r e f e r r e d t o

    a s o p e r a n d s . T h e e x p r e s s i o n i s a n y v a l i dc o m b i n a t i o n o f o p e r a t o r s , c o n s t a n t a n d v a r i a b l e s .

    Q. What is a

    compound Statement

    ? Give an Example. [2005]

    A n s : I t i s a b l o c k o f c o d e c o n t a i n i n g m o r e t h e no n e e x e c u t a b l e s t a t e m e n t . I n J a v a t h e { } i s c a l l e d

    b l o c k a n d t h e s t a t e m e n t s w r i t t e n u n d e r { } i s c a l l e dc o m p o u n d s t a t e m e n t s o r b l o c k s t a t e m e n t . T h e { }

    o p e n i n g a n d c l o s i n g b r a c e s i n d i c a t e s t h e s t a r t a n d

    e n d o f a c o m p o u n d s t a t e m e n t . f o r ( i n t

  • 7/31/2019 Java Theroy ! Easy to Learn

    17/53

    i = 1 ; i < = 5 ; i + + ) {S y s t e m . o u t . p r i n t l n ( " H e l l o " ) ; S y s t e m . o u t . p r in t l n ( " H o w " ) ; S y s t e m . o u t . p r i n t l n ( " a r e y o u ? " ) ; }

    U s e o f C o n s t r u c t o r

    [ICSE Syllabus on this Topic]Default constructor, Constructor with arguments,

    default initializing. Overloading constructor.

    Q. What is constructor?A n s : A c o n s t r u c t o r i s a M e m b e r f u n c t i o n t h a ta u t o m a t i c a l l y c a l l e d , w h e n t h e o b j e c t i s c r e a t e d o f

    t h a t c l a s s . I t h a s t h e s a m e n a m e a s t h a t o f t h e

    c l a s s n a m e a n d i t s p r i m a r y j o b i s t o i n i t i a l i s e t h e

    o b j e c t t o a l e g a l v a l u e f o r t h e c l a s s .

    Q. Why do we need a constructor as a class member? [2007]

    A n s : C o n s t r u c t o r i s u s e d c r e a t e a n i n s t a n c e o f o f ac l a s s , T h i s c a n b e a l s o c a l l e d c r e a t i n g a n o b j e c t .

    Q. Why does a constructor should be define as public?

    A n s : A c o n s t r u c t o r s h o u l d b e d e f i n e i n p u b l i cs e c t i o n o f a c l a s s , s o t h a t i t s o b j e c t s c a n b e

    c r e a t e d i n a n y f u n c t i o n .Q. Explain default constructor? [2006]

    A n s : T h e c o n s t r u c t o r t h a t a c c e p t s n o p a r a m e t e r i s

    c a l l e d t h e d e f a u l t c o n s t r u c t o r . I f w e d o n o te x p l i c i t l y d e f i n e a c o n s t r u c t o r f o r a c l a s s . , t h e n

    j a v a c r e a t e s a d e f a u l t c o n s t r u c t o r f o r t h e c l a s s .

    T h e d e f a u l t c o n s t r u c t o r i s o f t e n s u f f i c i e n t f o rs i m p l e c l a s s b u t n o t f o r s o p h i s t i c a t e d

    c l a s s e s . E x a m p l e : c l a s s a n t {i n t i ; p u b l i c s t a t i c v o i d

    m a i n ( ) a n t n c = n e w a n t ( ) ; }t h e l i n e n e w a n t ( ) c r e a t e sa n o b j e c t a n d c a l l s t h e d e f a u l t c o n s t r u c t o r ,

    w i t h o u t i t w e h a v e n o m e t h o d t o c a l l t o b u i l d o u r

    o b j e c t s . o n c e y o u c r e a t e a c o n s t r u c t o r w i t ha r g u m e n t t h e d e f a u l t c o n s t r u c t o r b e c o m e s h i d d e n .

    Q. Explain the Parameterised constructor?I C S E B l u e J

    T h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c s

    e / j t h e o r y . h t m 8o f

    2 4 8/ 2 0

    / 2 0

    1 1

    1 1 :

  • 7/31/2019 Java Theroy ! Easy to Learn

    18/53

    2 7P M

    A n s : I f w e w a n t t o i n i t i a l i s e o b j e c t s w i t h o u r

    d e s i r e d v a l u e , w e c a n u s e p a r a m e t e r s w i t h

    c o n s t r u c t o r a n d i n i t i a l i s e t h e d a t a m e m b e r s b a s e d

    o n t h e a r g u m e n t s p a s s e d t o i t . C o n s t r u c t o r t h a tc a n t a k e a r g u m e n t s a r e c a l l e d P a r a m e t e r i s e dc o n s t r u c t o r . E x a m p l e : p u b l i c c l a s s r e s u l t {i n t p e r ; i n t

    t o t ; p u b l i c r e s u l t ( i n t

    p e r c e n t a g e ) {p e r = p e r c e n t a g e ; t o t = 0 ; }}

    Q. Give an syntax/example of constructor overloading. Define a class, which accept roll

    number and marks of a student.Write constructor for the class, which accepts

    parameter to initialise the data member. Also take care of the case wherethe studenthas not appeared for the test where just the roll number is passed as argument.

    A n s : c l a s s s t u d e n t {i n t r o l l ; f l o a t m a r k s ; s t u d e n t ( i n t r ,

    f l o a t m ) / / c o n s t r u c t o r w i t h t w oa r g u m e n t . {r o l l = r ; m a r k s = m ; }s t u d e n t ( i n t r ) / /

    c o n s t r u c t o r w i t h o n ea r g u m e n t {r o l l = r ; m a r k s = 0 ; }s t u d e n t ( ) / / d e f a u l t

    c o n s t r u c t o r {r o l l = 0 ; m a r k s = 0 ; }}

    Q. Mention some characteristics of constructors.A n s : T h e s p e c i a l c h a r a c t e r i s t i c s o f c o n s t r u c t o r s

    a r e : ( i ) C o n s t r u c t o r s s h o u l d b e d e c l a r e d i n t h e

    p u b l i c s e c t i o n o f t h e c l a s s . ( i i ) T h e y a r e i n v o k e da u t o m a t i c a l l y w h e n a n o b j e c t o f t h e c l a s s i s

    c r e a t e d . ( i i i ) T h e y d o n o t h a v e a n y r e t u r n t y p e a n d

    c a n n o t r e t u r n a n y v a l u e s . ( i v ) L i k e a n y o t h e rf u n c t i o n , t h e y c a n a c c e p t a r g u m e n t s . ( v ) A c l a s s

    c a n h a v e m o r e t h a n o n e c o n s t r u c t o r . ( v i ) D e f a u l t

    c o n s t r u c t o r d o n o t a c c e p t p a r a m e t e r s . ( v i i ) I f n oc o n s t r u c t o r i s p r e s e n t i n t h e c l a s s t h e c o m p i l e r

    p r o v i d e s a d e f a u l t c o n s t r u c t o r .Q. State the difference between

    Constructor

    and

    Method

    . [2005]A n s : T h e f u n c t i o n h a s a r e t u r n t y p e l i k e i n t . b u t

    t h e c o n s t r u c t o r h a s n o r e t u r n t y p e . T h e f u n c t i o nm u s t b e c a l l e d i n p r o g r a m s w h e r e a s c o n s t r u c t o r

    a u t o m a t i c a l l y c a l l e d w h e n t h e o b j e c t o f t h a t c l a s s

    i s c r e a t e d .

  • 7/31/2019 Java Theroy ! Easy to Learn

    19/53

    Q. Enter any two variables through constructor parameters and write a program toswap and print the values. [2005]

    c l a s s s w a p {i n t a , b ; s w a p ( i n t x , i n t y ) {a = x ; b = y ; }p u b l i c

    v o i d m a i n ( S t r i n g a r g s [ ] ) {i n t

    t = a ; a = b ; b = t ; S y s t e m . o u t . o u t . p r i n t l n ( " t h e v a l u e o f a

    a n d b a f t e r s w a p i n g : " + a + " " + b ) ;I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c s

    e / j t h e o r y . h t m 9

    o f

    2 4 8/ 2 0

    / 2 0

    1 11 1 :

    2 7P M

    }}

    Q. What are the types of Constructors used in a class?A n s : T h e d i f f e r e n t t y p e s o f c o n s t r u c t o r s a r e a s

    f o l l o w s : i . D e f a u l t C o n s t r u c t o r s . i i . P a r a m e t e r i z e d

    C o n s t r u c t o r . i i i . C o p y C o n s t r u c t o r s .Q. Define Copy constructors.

    A n s : A c o p y c o n s t r u c t o r s i n i t i a l i z e s t h e i n s t a n t

    v a r i a b l e s o f a n o b j e c t b y c o p y i n g t h e i n i t i a l v a l u eo f t h e i n s t a n t v a r i a b l e s f r o m a n o t h e r o b j e c t s .

    e . g . c l a s s x y z {i n t a . b ; x y z ( i n t x , i n t z ) {a = x ; b = y ; }x y z ( x y z

    p ) {a = p . x ; b = p . y ; }}U s e r D e f i n e F u n c t i o n s

    [ICSE Syllabus on this Topic]Function as a way to defineoperations/methods/messages. Pure functions return values and do not

    changestate, impure functions may return values but also change state,

    return type argument to function, functionprototype and function signature,

    overloading. Variable of a class type as reference to an objects,invocation

    of function on objects through the reference, the concept of this. Argumentpassing in functions,pass by value, what happened when a reference is

    passed side effect.Q. What is Function? Why do we use functions while programs handling?

    A n s : A n a m e d u n i t o f a g r o u p o f p r o g r a m s

    s t a t e m e n t s . T h i s u n i t c a n b e i n v o k e d f r o m o t h e r

    p a r t s o f t h e p r o g r a m .

  • 7/31/2019 Java Theroy ! Easy to Learn

    20/53

    Q. Define Function prototype?A n s : T h e f u n c t i o n p r o t o t y p e i s t h e f i r s t l i n e o f t h e

    f u n c t i o n d e f i n i t i o n t h a t t e l l s t h e p r o g r a m a b o u t t h e

    t y p e o f t h e v a l u e r e t u r n e d b y t h e f u n c t i o n a n d t h e

    n u m b e r a n d t y p e s o f a r g u m e n t s .

    Q. What is the use of void before function name? [2007]A n s : v o i d d a t a t y p e s p e c i f i e s a n e m p t y s e t o f v a l u e s a n d i t i s u s e d a s t h e r e t u r n t y p e f o r

    f u n c t i o n s t h a t d o n o t r e t u r n a v a l u e . T h u s a

    f u n c t i o n t h a t d o e s n o t r e t u r n a v a l u e i s d e c l a r e d

    a s f o l l o w s . v o i d < f u n c t i o n s n a m e > ( p a r a m e t e r l i s t )

    Q. Explain Functions/Methods Definitions with syntax?

    A n s : A f u n c t i o n m u s t b e d e f i n e d b e f o r e i t i s u s e da n y w h e r e i n t h e p r o g r a m . [ a c c e s s

    s p e c i f i e r ] [ m o d i f i e r ] r e t u r n - t y p e f u n c t i o n - n a m e

    ( p a r a m e t e r l i s t ) {b o d y o f t h e f u n c t i o n }[ a c c e s ss p e c i f i e r ] c a n b e e i t h e r P u b l i c , P r o t e c t e d o r

    P r i v a t e . [ m o d i f i e r ] c a n b e o n e o f f i n a l ,n a t i v e , s y n c h r o n i z e , t r a n s i e n t , v o l a t i l e . r e t u r n - t y p e

    s p e c i f i e s t h e t y p e o f v a l u e t h a t t h e r e t u r n

    s t a t e m e n t o f t h e f u n c t i o n r e t u r n s . I t m a y b e a n yv a l i d J a v a d a t a t y p e . p a r a m e t e r l i s t i s c o m m a

    s e p a r a t e d l i s t o f v a r i a b l e s o f a f u n c t i o n .

    I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c se / j t h e o r y . h t m 1

    0

    o f2 4 8

    / 2 0/ 2 0

    1 1

    1 1 :

    2 7

    P MQ. Why main() function so special?

    A n s : T h e m a i n ( ) f u n c t i o n i s i n v o k e d i n t h e s y s t e mb y d e f a u l t . h e n c e a s s o o n a s t h e c o m m a n d f o r

    e x e c u t i o n o f t h e p r o g r a m i s u s e d , c o n t r o l d i r e c t l y

    r e a c h e s t h e m a i n ( ) f u n c t i o n .

    Q. Explain the function prototype and the signature?

  • 7/31/2019 Java Theroy ! Easy to Learn

    21/53

    A n s : T h e f u n c t i o n p r o t o t y p e i s t h e f i r s t l i n e o f t h ef u n c t i o n d e f i n i t i o n s , t h a t t e l l s t h e p r o g r a m a b o u t

    t h e t y p e o f t h e v a l u e r e t u r n e d b y t h e f u n c t i o n a n d

    t h e n u m b e r a n d t y p e o f t h e a r g u m e n t s . F u n c t i o n

    s i g n a t u r e b a s i c a l l y r e f e r s t o t h e n u m b e r a n d t y p e s

    o f t h e a r g u m e n t s , i t i s t h e p a r t o f t h e p r o t o t y p e .Q. Explain the function of a return statement? [2006]A n s : T h e r e t u r n s t a t e m e n t i s u s e f u l i n t w o w a y s .

    F i r s t a n i m m e d i a t e l y e x i t f r o m t h e f u n c t i o n i s

    c a u s e d a s s o o n a s a r e t u r n s t a t e m e n t i s

    e n c o u n t e r e d a n d t h e c o n t r o l b a c k t o t h e m a i n

    c a l l e r . S e c o n d u s e o f r e t u r n s t a t e m e n t i s t h a t i t i s

    u s e d a v a l u e t o t h e c a l l i n g c o d e .Q. Write advantages of using functions in programs

    A n s : ( i ) f u n c t i o n s l e s s e n t h e c o m p l e x i t y o f

    p r o g r a m s ( i i ) f u n c t i o n s h i d e t h e i m p l e m e n t a t i o nd e t a i l s ( i i i ) f u n c t i o n s e n h a n c e r e u s a b i l i t y o f c o d e

    Q. Difference between Actual argument and Formal argument? [2007,2008]A n s : T h e p a r a m e t e r t h a t a p p e a r s i n f u n c t i o n c a l l

    s t a t e m e n t a r e c a l l e d a c t u a l a r g u m e n t a n d T h e

    p a r a m e t e r t h a t a p p e a r s i n f u n c t i o n d e f i n i t i o n a r ec a l l e d f o r m a l p a r a m e t e r .

    Q. What are static members?

    A n s : T h e m e m b e r s t h a t a r e d e c l a r e d s t a t i c i s c a l l e ds t a t i c m e m b e r s . T h e s e m e m b e r s a r e a s s o c i a t e d

    w i t h t h e c l a s s i t s e l f r a t h e r t h e n i n d i v i d u a l o b j e c t s ,

    t h e s t a t i c m e m b e r s a n d s t a t i c m e t h o d s a r e o f t e nr e f e r r e d t o a s c l a s s v a r i a b l e s a n d m e t h o d s .

    Q. What is the use of static in main() methods? [2007]

    A n s : ( i ) T h e y c a n o n l y c a l l o t h e r s t a t i c m e t h o d s .( i i ) T h e y c a n o n l y a c c e s s s t a t i c d a t a . ( i i i ) T h e y

    c a n n o t r e f e r t o t h i s o r s u p e r i n a n y w a y .Q. What is

    call by value

    ? [2005]

    A n s : ( i ) I n c a l l b y v a l u e , t h e c a l l e d f u n c t i o n s

    c r e a t e s i t s o w n w o r k c o p y f o r t h e p a s s e dp a r a m e t e r s a n d c o p i e s t h e p a s s e d v a l u e s i n i t . A n y

    c h a n g e s t h a t t a k e p l a c e r e m a i n i n t h e w o r k c o p ya n d t h e o r i g i n a l d a t a r e m a i n s i n t a c t .

    Q. Explain the term "passed by reference"? [2007]

    A n s : I n p a s s e d b y r e f e r e n c e , t h e c a l l e d f u n c t i o n

    r e c e i v e s t h e r e f e r e n c e t o t h e p a s s e d p a r a m e t e r s

  • 7/31/2019 Java Theroy ! Easy to Learn

    22/53

    a n d t h r o u g h t h i s r e f e r e n c e , i t a c c e s s t h e o r i g i n a ld a t a . A n y c h a n g e s t h a t t a k e p l a c e a r e r e f l e c t e d i n

    t h e o r i g i n a l d a t a .

    Q. Differentiate between call by value and call by reference?

    A n s : I n c a l l b y v a l u e , t h e c a l l e d f u n c t i o n s c r e a t e s

    i t s o w n w o r k c o p y f o r t h e p a s s e d p a r a m e t e r s a n dc o p i e s t h e p a s s e d v a l u e s i n i t . A n y c h a n g e s t h a tt a k e p l a c e r e m a i n i n t h e w o r k c o p y a n d t h e

    o r i g i n a l d a t a r e m a i n s i n t a c t . I n c a l l b y r e f e r e n c e ,

    t h e c a l l e d f u n c t i o n r e c e i v e s t h e r e f e r e n c e t o t h e

    p a s s e d p a r a m e t e r s a n d t h r o u g h t h i s r e f e r e n c e , i t

    a c c e s s t h e o r i g i n a l d a t a . A n y c h a n g e s t h a t t a k e

    p l a c e a r e r e f l e c t e d i n t h e o r i g i n a l d a t a .Q. Define an impure functions? [2006]

    A n s : I m p u r e F u n c t i o n c h a n g e t h e s t a t e o f t h e

    o b j e c t a r g u m e n t s t h e y h a v e r e c e i v e d a n d t h e nr e t u r n . T h e f o l l o w i n g f u n c t i o n s i s t h e e x a m p l e o f a n

    i m p u r e f u n c t i o n : p u b l i c s t a t i c v o i d i n c r e m e n t ( T i m eo b j , d o u b l e s e c s ) {t i m e . s e c o n d s + = s e c s ; r e t u r n ( T i m e ) ; }

    Q. What is the difference between pure and impure functions? [2009]

    A n s : P u r e F u n c t i o n : T h e s e f u n c t i o n s t a k e s o b j e c t sa s a n a r g u m e n t s b u t d o e s n o t m o d i f y t h e s t a t e o f

    t h e o b j e c t s . T h e r e s u l t o f t h e p u r e f u n c t i o n i s t h e

    r e t u r n v a l u e . I m p u r e F u n c t i o n : T h e s e f u n c t i o n sc h a n g e t h e s t a t e o f t h e o b j e c t a r g u m e n t s t h e y h a v e

    r e c e i v e d .

    Q. How are following passed in Java? [2005](i) primitive types (ii) reference typesA n s : ( i ) B y v a l u e , ( i i ) B y r e f e r e n c e .

    I C S E B l u e J

    T h e o r y h t t p : / / w w w . a mi t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c se / j t h e o r y . h t m 1

    1

    o f

    2 4 8

    / 2 0/ 2 0

    1 11 1 :

    2 7

    P M

    Q. What does function overloading mean? What is its significance?

  • 7/31/2019 Java Theroy ! Easy to Learn

    23/53

    A n s : A F u n c t i o n n a m e h a v i n g s e v e r a l d e f i n i t i o n s i nt h e s a m e s c o p e t h a t a r e d i f f e r e n t i a b l e b y t h e

    n u m b e r o r t y p e o f t h e i r a r g u m e n t s , i s s a i d t o b e a n

    o v e r l o a d e d f u n c t i o n . F u n c t i o n o v e r l o a d i n g n o t o n l y

    i m p l e m e n t s p o l y m o r p h i s m b u t a l s o r e d u c e t h e n u m b e r

    o f c o m p a r i s o n s i n a p r o g r a m a n d t h e r e b y m a k e st h e p r o g r a m s r u n f a s t e r .Q. Illustrate the concept of function overloading with the help of an example. [2006]

    A n s : - A f u n c t i o n n a m e h a v i n g s e v e r a l d e f i n i t i o n s

    t h a t a r e d i f f e r e n t i a b l e b y t h e n u m b e r s o r t y p e s o f

    t h e i r a r g u m e n t s i s k n o w n a s f u n c t i o n o v e r l o a d i n g .

    F o r e x a m p l e f o l l o w i n g c o d e o v e r l o a d s a f u n c t i o n

    a r e a t o c o m p u t e r a r e a s o f c i r c l e r e c t a n g l e a n dt r i a n g l e . f l o a t a r e a ( f l o a t r a d i u s ) / / c i r c l e {r e t u r n

    ( 3 . 1 4 * r a d i u s * r a d i u s ) ; }f l o a t a r e a ( f l o a t l e n g t h ,

    f l o a t b r e a d t h ) / / r e c t a n g l e {r e t u r n( l e n g t h * b r e a d t h ) ; }f l o a t a r e a ( f l o a t s i d e 1 , f l o a t

    s i d e 2 , f l o a t s i d e 3 ) / / a r e a o f t r i a n g l e {f l o a t s =( s i d e 1 + s i d e 2 + s i d e 3 ) / 2 ; f l o a t a r = M a t h . s q r t ( s

    * ( s - s i d e 1 ) * ( s - s i d e 2 ) * ( s - s i d e 3 ) ) ; r e t u r n ( a r ) ; }

    Q. What is this keyword? What is its significance? [2009]A n s : T h e t h i s k e y w o r d i s u s e d t o r e f e r t o c u r r e n t l y

    c a l l i n g o b j e c t s . T h e m e m b e r f u n c t i o n s o f e v e r y

    o b j e c t s h a v e a c c e s s t o a s o r t o f m a g i c k e y w o r dn a m e t h i s , w h i c h p o i n t s t o t h e o b j e c t i t s e l f . T h u s

    a n y m e m b e r f u n c t i o n c a n f i n d o u t t h e a d d r e s s o f

    t h e o b j e c t o f w h i c h i t i s a m e m b e r . T h e t h i sk e y w o r d r e p r e s e n t s a n o b j e c t t h a t i n v o k e s a m e m b e r

    f u n c t i o n . i t s t o r e s t h e a d d r e s s o f t h e o b j e c t t h a t

    i n v o k i n g a m e m b e r f u n c t i o n a n d i t i s a n i m p l i c i ta r g u m e n t t o t h e m e m b e r f u n c t i o n b e i n g i n v o k e d .

    T h e t h i s k e y w o r d i s u s e f u l i n r e t u r n i n g t h e o b j e c t o f w h i c h t h e f u n c t i o n i s a m e m b e r .

    Q. What do you mean by recursive function?

    A n s : W h e n a m e t h o d i s c a l l e d i n s i d e i t s o w n

    d e f i n i t i o n t h e p r o c e s s i s k n o w n a s f u n c t i o n s

    r e c u r s i o n a n d t h i s f u n c t i o n c a l l e d r e c u r s i v ef u n c t i o n .

    Q. What is the difference between Methods and Functions?A n s : T h e m a j o r d i f f e r e n c e b e t w e e n m e t h o d s a n d

    f u n c t i o n s i s t h a t m e t h o d s c a l l e d b y t h e

    r e f e r e n c e v a r i a b l e s c a l l e d o b j e c t s w h e r e a s t h e

    f u n c t i o n s d o n o t h a v i n g a n y r e f e r e n c e v a r i a b l e s .

  • 7/31/2019 Java Theroy ! Easy to Learn

    24/53

    C l a s s a s a U s e r D e f i n e d T y p e s[ICSE Syllabus on this Topic]Class as a composite type, distinction between

    primitive type and composite of class type.

    Q. What is data type?

    A n s : D a t a t y p e s a r e m e a n s t o i d e n t i f y t h e t y p e o f

    d a t a a n d a s s o c i a t e d o p e r a t i o n s o f h a n d l i n g i t .Q. What is composite (user define) data type? Explain with an example? [2007] [2009]A n s : A c o m p o s i t e d a t a t y p e i s t h a t d a t a t y p e t h a t

    a r e b a s e d o n f u n d a m e n t a l o r p r i m i t i v e d a t a t y p e s . A

    ' c l a s s ' i s a n e x a m p l e o f c o m p o s i t e d a t a t y p e s . c l a s s

    D a t e {i n t d d , m m , y y ; p u b l i c

    D a t e ( ) {d d = 1 ; m m = 1 ; y y = 2 0 0 5 ; }}

    Q. What is user define datatype?A n s : A u s e r d e f i n e d d a t a t y p e i s a d a t a t y p e t h a t i s

    n o t a p a r t o f t h e l a n g u a g e a n d i s c r e a t e d b y

    a p r o g r a m m e r .I C S E B l u e J

    T h e o r y h t t p : / / w w w . a mi t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c s

    e / j t h e o r y . h t m 12

    o f

    2 4 8/ 2 0

    / 2 0

    1 11 1 :

    2 7

    P MQ. Can you refer to a class as a user defined (composite) datatype? [2009]

    A n s : Y e s , w e c a n r e f e r t o a c l a s s n o t h a v i n g am a i n ( ) m e t h o d a s u s e r - d e f i n e d d a t a t y p e .

    Q. What is the difference between primitive datatypes and composite datatypes?

    A n s : ( i ) p r i m i t i v e d a t a t y p e s a r e b u i l t - i n d a t a t y p e s .

    J a v a p r o v i d e s t h e s e d a t a t y p e s . U s e r - d e f i n e d

    d a t a t y p e s a r e c r e a t e d b y u s e r s . ( i i ) T h e s i z e o f p r i m i t i v e d a t a t y p e s a r e f i x e d . T h e s i z e o f u s e r -

    d e f i n e d d a t a t y p e s a r e v a r i a b l e . ( i i i ) P r i m i t i v ed a t a t y p e s a r e a v a i l a b l e i n a l l p a r t s o f J a v a

    p r o g r a m s . T h e a v a i l a b i l i t y o f u s e r - d e f i n e d d a t a t y p e s

    d e p e n d s u p o n t h e i r s c o p e .

    Q. Compare a class as a user defined datatype and class as an application?

  • 7/31/2019 Java Theroy ! Easy to Learn

    25/53

    A n s : I n J a v a , a l l f u n c t i o n a l i t y i s e n c l o s e d i nc l a s s e s . B u t i n o r d e r f o r a c l a s s t o b e u s e r -

    d e f i n e d d a t a t y p e , i t s h o u l d b e a c t d i f f e r e n t f r o m

    t h a t o f a n a p p l i c a t i o n . i . e . i t s h o u l d n o t i n c l u d e

    m a i n ( ) m e t h o d i n i t . A l t h o u g h w e c a n c r e a t e

    i n s t a n c e o f c l a s s e s c o n t a i n i n g m a i n m e t h o d , t h e ys h o u l d n o t b e r e f e r r e d t o a s u s e d - d e f i n e d d a t a t y p e .S u c h c l a s s e s ( c o n t a i n i n g m a i n ( ) m e t h o d ) a r e m o r e

    a n a l o g u e s t o a p p l i c a t i o n t h a n a d a t a t y p e .

    Q. Where can the following members of a class be accessed? private, protected, public

    and default access. [2008]

    A n s : A c c e s s s p e c i f i e r c a n b e o f f o l l o w i n g t y p e s : ( a )

    P U B L I C : P u b l i c m e m b e r s o f a c l a s s a r e g l o b a l l ya c c e s s i b l e . ( b ) P R I V A T E : P r i v a t e m e m b e r s o f a c l a s s

    b e a c c e s s e d b y t h e m e m b e r f u n c t i o n s o f t h e c l a s s

    o n l y . ( c ) P R O T E C T E D : P r o t e c t e d m e m b e r s o f a c l a s sa r e a c c e s s i b l e i n t h e p a c k a g e w h e r e t h e c l a s s i s

    d e f i n e d a n d i n a l l t h e s u b - c l a s s e s o f t h e c l a s s . ( d )D e f a u l t ( f r i e n d l y ) a c c e s s : m e m b e r s w i t h d e f a u l t

    ( f r i e n d l y ) a c c e s s c a n b e u s e d w i t h i n t h e

    p a c k a g e w h e r e t h e c l a s s i s d e f i n e d .Q. How are private member different from public member of a class.

    A n s : P r i v a t e m e m b e r s o f a c l a s s a r e a c c e s s i b l e i n

    t h e m e m b e r f u n c t i o n o f t h e c l a s s o n l y , w h e r e a sp u b l i c m e m b e r s a r e a c c e s s i b l e g l o b a l l y .

    Q. How are protected members different from public and private members of a class.

    A n s : P r o t e c t e d m e m b e r s o f a c l a s s a r e a c c e s s i b l ei n a l l t h e c l a s s e s i n t h e s a m e p a c k a g e a n d

    s u b c l a s s i n t h e o t h e r p a c k a g e s . p r i v a t e m e m b e r s o f

    a c l a s s a c c e s s i b l e i n t h e m e m b e r f u n c t i o n s i n t h ec l a s s o n l y . W h e r e a s p u b l i c m e m b e r s a r e a c c e s s i b l e

    g l o b a l l y .Q. Mention any

    attributes required for class declaration. [2008]

    A n s : T h e t w o a t t r i b u t e s f o r c l a s s d e c l a r a t i o n a r e :

    1 . A c c e s s S p e c i f i e r 2 . M o d i f i e r 3 . C l a s s N a m eD e c i s i o n M a k i n g

    [ICSE Syllabus on this Topic]Application of if-then, if-then-else, switch(default, break).

    Q. What is a statement?

    A n s : S t a t e m e n t s a r e t h e i n s t r u c t i o n s g i v e n t t h e

    c o m p u t e r t o p e r f o r m a n y k i n d o f a c t i o n , a s

  • 7/31/2019 Java Theroy ! Easy to Learn

    26/53

    d a t a m o v e m e n t s , m a k i n g d e c i s i o n o r r e p e a t i n ga c t i o n . S t a t e m e n t s f o r m t h e s m a l l e s t e x e c u t a b l e

    u n i t a n d t e r m i n a t e d w i t h s e m i - c o l o n .

    Q. What are the three constructs that govern statement flow?

    A n s : T h e t h r e e c o n s t r u c t s t h a t g o v e r n s s t a t e m e n t

    f l o w a r e : S e q u e n c e , S e l e c t i o n a n d I t e r a t i o nc o n s t r u c t s .Q. What is a selection/conditional statement? Which selection statements does Java

    provides?

    A n s : A s e l e c t i o n s t a t e m e n t i s t h e o n e t h a t i s u s e d

    t o d e c i d e w h i c h s t a t e m e n t s h o u l d b e e x e c u t e n e x t .

    T h i s d e c i s i o n i s b a s e d u p o n a t e s t c o n d i t i o n . T h e

    s e l e c t i o n s t a t e m e n t s p r o v i d e d b y J a v a a r e : i f - e l s ea n d s w i t c h . T h e c o n d i t i o n a l o p e r a t o r ? : c a n a l s o b e

    u s e d t o t a k e s i m p l e d e c i s i o n .

    Q. What is an 'if' statement? Explain with an example.A n s : t h e ' i f ' s t a t e m e n t h e l p s i n s e l e c t i n g o n e

    a l t e r n a t i v e o u t o f t h e t w o . T h e e x e c u t i o n o f ' i f 's t a t e m e n t s t a r t s w i t h t h e e v a l u a t i o n o f c o n d i t i o n .

    T h e ' i f ' s t a t e m e n t t h e r e f o r e h e l p s t h e p r o g r a m m e r

    t o t e s t f o r t h e c o n d i t i o n . G e n e r a l f o r m o f ' i f 's t a t e m e n t .

    NIIT Offers Java Courses. Fast Track Career Programs. Enroll Now!NIIT.com/Java-Training

    Online Tests, Exam Resources &More Classes 9-10 Subjects Maths&ScienceTopperlearning.com/IC

    Download NeuroSolutions and apply neural networks to your applicationwww.neurosolutions.com

    I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c s

    e / j t h e o r y . h t m 1

    3o f

    2 4 8/ 2 0

    / 2 0

    1 1

    1 1 :

  • 7/31/2019 Java Theroy ! Easy to Learn

    27/53

    2 7P M

    i f ( e x p r e s s i o n )

    s t a t e m e n t i f ( m a r k s > = 8 0 ) S y s t e m . o u t . p r i n t l n ( " G r a d e A " ) ;

    Q. What is the significance of a test-condition in a if statement?

    A n s : I t i s t h e t e s t c o n d i t i o n o f a n i f s t a t e m e n tt h a t d e c i d e s w h e t h e r t h e c o d e a s s o c i a t e d w i t h t h ei f p a r t o r t h e o n e a s s o c i a t e d w i t h t h e e l s e p a r t

    s h o u l d b e e x e c u t e d . T h e f o r m e r i s e x e c u t e d i f t h e

    t e s t c o n d i t i o n e v a l u a t e s t o t r u e a n d t h e l a t t e r

    w o r k s i f t h e c o n d i t i o n e v a l u a t e s t o f a l s e .

    Q. Write one advantage and one disadvantage of using ?: in place of an if.

    A n s : A d v a n t a g e : I t l e a d s t o a m o r e c o m p a c tp r o g r a m . D i s a d v a n t a g e : N e s t e d ? : b e c o m e s d i f f i c u l t

    t o u n d e r s t a n d o r m a n a g e .

    Q. What do you understand by nested 'if' statements?ORQ. Explain with an examplethe if-else-if construct. [2007]

    A n s : A n e s t e d ' i f ' i s a n s t a t e m e n t t h a t h a s a n o t h e r' i f ' i n i t s b o d y o r i n i t ' s a p p e a r a n c e . I t t a k e s

    t h e f o l l o w i n g g e n e r a l

    f o r m . i f ( c h > = ' A ' ) {i f ( c h < = ' Z ' ) + + u p c a s e ; e l s e + + o t h e r ; }Q. What is the problem of dangling-else? When does it arise? What is the default

    dangling-else matching and how it beoverridden?

    A n s : T h e n e s t e d i f - e l s e s t a t e m e n t i n t r o d u c e s as o u r c e o f p o t e n t i a l a m b i g u i t y r e f e r r e d t o a s

    d a n g l i n g - e l s e p r o b l e m . T h i s p r o b l e m a r i s e s w h e n i n a

    n e s t e d i f s t a t e m e n t , n u m b e r o f i f ' s i s m o r e t h e nt h e n u m b e r o f e l s e c l a u s e . T h e q u e s t i o n t h e n a r i s e s ,

    w i t h w h i c h i f d o e s t h e a d d i t i o n a l e l s e c l a u s e

    p r o p e r t y m a t c h . F o rE x a m p l e i f ( c h > = ' A ' ) i f ( c h < = ' Z ' ) + + u p c a s e ; e l s e + + o t h e r ; T

    h e i n d e n t a t i o n i n t h e a b o v e c o d e f r a g m e n ti n d i c a t e s t h a t p r o g r a m m e r w a n t s t h e e l s e t o b e

    w i t h t h e o u t e r i f . H o w e v e r J a v a m a t c h e s a n e l s e

    w i t h t h e p r e c e d i n g u n m a t c h e d i f . O n e m e t h o d f o r

    o v e r - r i d i n g t h e d e f a u l t d a n g l i n g - e l s e m a t c h i n g i s t o

    p l a c e t h e l a s t o c c u r r i n g u n m a t c h e d i f i n ac o m p o u n d s t a t e m e n t , a s i t i s

    s h o w n b e l o w . i f ( c h > = ' A ' ) {i f ( c h < = ' Z ' ) + + u p c a s e ; }e l s e + + o th e r ;

    Q. Compare and contrast IF with ?:

    A n s : ( i ) C o m p a r e t o I F s e q u e n c e , ? : o f f e r m o r e

    c o n c i s e , c l e a n a n d c o m p a c t c o d e , b u t i t i s l e s s

  • 7/31/2019 Java Theroy ! Easy to Learn

    28/53

    o b v i o u s a s c o m p a r e d t o I F . ( i i ) A n o t h e r d i f f e r e n c e i st h a t t h e c o n d i t i o n a l o p e r a t o r ? : p r o d u c e s a n

    e x p r e s s i o n , a n d h e n c e a s i n g l e v a l u e c a n b e

    a s s i g n e d , f o r l a r g e r e x p r e s s i o n I f i s m o r e f l e x i b l e .

    ( i i i ) W h e n ? : o p e r a t o r i s u s e d i n i t s n e s t e d f o r m , i t

    b e c o m e s c o m p l e x a n d d i f f i c u l t t o u n d e r s t a n d .Q. What is a switch statement? How is a switch statement executed?A n s : S w i t c h s t a t e m e n t s u c c e s s i v e l y t e s t s t h e v a l u e

    o f a n e x p r e s s i o n a g a i n s t a s e t o f i n t e g e r s o r

    c h a r a c t e r c o n s t a n t s . W h e n a m a t c h i s f o u n d , t h e

    s t a t e m e n t s a s s o c i a t e d w i t h t h e c o n s t a n t s a r e

    e x e c u t e d . T h e s y n t a x s w i t c h ( e x p r e s s i o n ) {c a s e

    c o n s t a n t s : s t a t e m e n t s ; b r e a k ; c a s e c o n s t a n t s :s t a t e m e n t s ; b r e a k ; }T h e e x p r e s s i o n i s e v a l u a t e d a n d

    i t s v a l u e s a r e m a t c h e d a g a i n s t t h e v a l u e o f t h e

    c o n s t a n t s s p e c i f i e d i n t h e c a s e s t a t e m e n t s . W h e n am a t c h i s f o u n d , t h e s t a t e m e n t s s e q u e n c e a s s o c i a t e d

    w i t h t h a t c a s e i s e x e c u t e d u n t i l t h e b r e a k s t a t e m e n to r t h e e n d o f s w i t c h s t a t e m e n t i s r e a c h e d .

    Q. What is the significance of break statement in a switch statement?

    I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . o

    r g . i n / m a t e r i a l s / i c se / j t h e o r y . h t m 1

    4

    o f2 4 8

    / 2 0

    / 2 01 1

    1 1 :2 7

    P M

    A n s : I n s w i t c h s t a t e m e n t w h e n a m a t c h i s f o u n d t h e

    s t a t e m e n t s e q u e n c e o f t h a t c a s e i s e x e c u t e d u n t i l

    a ' b r e a k ' s t a t e m e n t i s f o u n d o r t h e e n d o f s w i t c h i sr e a c h e d , w h e n a ' b r e a k ' s t a t e m e n t i s f o u n d

    p r o g r a m e x e c u t i o n j u m p s t o t h e l i n e o f c o d ef o l l o w i n g t h e s w i t c h s t a t e m e n t .

    Q. What is a control variable in a switch case?

  • 7/31/2019 Java Theroy ! Easy to Learn

    29/53

    A n s : A c o n t r o l v a r i a b l e i n s w i t c h c a s e i s o n e w h i c hg u i d e s t h e c o n t r o l t o j u m p o n a s p e c i f i e d c a s e .

    e . g . s w i t c h ( x ) , h e r e ' x ' i s t h e c o n t r o l v a r i a b l e .

    Q. What is a "fall through"?

    A n s : T h e t e r m " f a l l t h r o u g h " r e f e r s t o t h e w a y t h e

    s w i t c h s t a t e m e n t e x e c u t e s i t s v a r i o u s c a s es e c t i o n s . E v e r y s t a t e m e n t t h a t f o l l o w s t h e s e l e c t e dc a s e s e c t i o n w i l l b e e x e c u t e d u n l e s s a b r e a k

    s t a t e m e n t i s e n c o u n t e r e d .

    Q. What is the effect of absence of break in a switch statement?

    A n s : A b s e n c e o f b r e a k s t a t e m e n t i n a s w i t c h

    s t a t e m e n t l e a d s t o s i t u a t i o n c a l l e d " f a l l t h r o u g h "

    w h e r e o n c e a m a t c h i n g c a s e i s f o u n d t h es u b s e q u e n c e c a s e b l o c k s a r e e x e c u t e d

    u n c o n d i t i o n a l l y

    Q. Write one limitation and one advantage of switch statement?A n s : A d v a n t a g e : M o r e e f f i c i e n t i n c a s e a v a l u e i s

    t o b e t e s t e d a g a i n s t a s e t o f c o n s t a n t s .D i s a d v a n t a g e : s w i t c h c a n t e s t o n l y f o r q u a l i t y , s o

    f o r t h e r e s t o f c o m p a r i s o n s o n e n e e d s t o u s e i f -

    e l s e .Q. Discuss when does an if statement prove more advantageous then switch statement.

    A n s : I n t h e f o l l o w i n g c a s e i f s t a t e m e n t p r o v e s t o

    b e m o r e a d v a n t a g e o v e r s w i t c h s t a t e m e n t : ( i ) W h e na r a n g e o f v a l u e s n e e d t o b e t e s t e d f o r . ( i i ) W h e n

    r e l a t i o n b e t w e e n m u l t i p l e v a r i a b l e s n e e d s t o b e

    t e s t e d . ( i i i ) W h e n m u l t i p l e c o n d i t i o n s n e e d t o b et e s t e d . ( i v ) W h e n e x p r e s s i o n s h a v i n g a d a t a t y p e

    o t h e r t h e n i n t e g e r o r c h a r a c t e r n e e d t o b e t e s t e d .

    Q. When does switch statement prove more advantageous over an if statement?A n s : T h e s w i t c h s t a t e m e n t i s m o r e a d v a n t a g e o u s

    t h e n t h e i f s t a t e m e n t w h e n t h e t e s t e x p r e s s i o nw h o s e d a t a t y p e i s e i t h e r o f b y t e , s h o r t , c h a r a c t e r ,

    i n t e g e r o r l o n g i s t o b e t e s t e d a g a i n s t a s e t o f

    c o n s t a n t s . T h e r e a s o n b e i n g t h a t t h e s w i t c h

    s t a t e m e n t e v a l u a t e s t h e e x p r e s s i o n o n c e w h e r e a s

    t h e e q u i v a l e n t i f s t a t e m e n t e v a l u a t e s t h e e x p r e s s i o nr e p e a t e d l y .

    Q. Explain, with the help of an example, the purpose ofdefault

    in a switch statement. [2005]

    A n s : T h e d e f a u l t s e c t i o n i s a n o p t i o n a l p a r t o f t h e

    s w i t c h s t a t e m e n t a n d t h e s t a t e m e n t w r i t t e n

  • 7/31/2019 Java Theroy ! Easy to Learn

    30/53

    u n d e r d e f a u l t c l a u s e a r e e x e c u t e d w h e n n om a t c h i n g c a s e i s f o u n d . s w i t c h ( n ) {c a s e 1 :

    S y s t e m . o u t . p r i n t l n ( " S u n d a y " ) ; b r e a k ; c a s e 2 :

    S y s t e m . o u t . p r i n t l n ( " M o n d a y " ) ; b r e a k ; c a s e 3 :

    S y s t e m . o u t . p r i n t l n ( " T u e s d a y " ) ; b r e a k ; c a s e 4 :

    S y s t e m . o u t . p r i n t l n ( " W e d n e s d a y " ) ; b r e a k ; c a s e 5 :S y s t e m . o u t . p r i n t l n ( " T h u r s d a y " ) ; b r e a k ; c a s e 6 :S y s t e m . o u t . p r i n t l n ( " F r i d a y " ) ; b r e a k ; c a s e 7 :

    S y s t e m . o u t . p r i n t l n ( " S a t u r d a y " ) ; b r e a k ; d e f a u l t :

    S y s t e m . o u t . p r i n t l n ( " I n v a l i d I n p u t " ) ; }

    Q. Differentiate between if and switch statements. [2006]

    A n s : B o t h a r e u s e d a s a s e l e c t i o n s t a t e m e n t s ,

    t h e r e a r e s o m e d i f f e r e n c e i n t h e i r o p e r a t i o n s . ( i )s w i t c h c a n o n l y t e s t f o r e q u a l i t y , w h e r e a s i f c a n

    e v a l u a t e a r e l a t i o n a l o r l o g i c a l e x p r e s s i o n . ( i i ) i t

    s t a t e m e n t c a n h a n d l e r a n g e s , w h e r e a s s w i t c h c a s el e v e l m u s t b e a s i n g l e v a l u e . ( i i i ) i f s t a t e m e n t c a n

    h a n d l e f l o a t i n g p o i n t t e s t a l s o , w h e r e a s t h e s w i t c hc a s e l a b e l s m u s t b e a n i n t e g e r o r c h a r a c t e r .

    C o n c e p t s o f C o n d i t i o n s a n d L o o p s

    [ICSE Syllabus on this Topic]Utilization of loops. Fixed number of Iteration.The for Loop, unknown number of Iteration - while, do-whileloop, continue,

    break. Nested Loops.

    Q. What are iteration statements? Name the iteration statements provided by Java?A n s : I t e r a t i o n s t a t e m e n t s a r e s t a t e m e n t s t h a t

    a l l o w s a s e t o f i n s t r u c t i o n s t o b e e x e c u t e d

    r e p e a t e d l y t i l l s o m e c o n d i t i o n i s s a t i s f i e d . T h ei t e r a t i o n s t a t e m e n t s p r o v i d e d b y J a v a a r e : f o r

    l o o p , w h i l e l o o p , d o - w h i l e l o o p .

    I C S E B l u e JT h e o r y h t t p : / / w w w . a m

    i t a b h s i r k i c l a s s e s . or g . i n / m a t e r i a l s / i c s

    e / j t h e o r y . h t m 1

    5

    o f

    2 4 8/ 2 0

    / 2 01 1

    1 1 :

    2 7

    P M

  • 7/31/2019 Java Theroy ! Easy to Learn

    31/53

    Q. What is the difference between entry controlled and exit controlled loop? orWhat isthe difference between while and do-while loop?

    A n s : w h i l e l o o p i s k n o w n a s e n t r y c o n t r o l l e d l o o p

    a n d d o - w h i l e l o o p i s k n o w n a s e x i t - c o n t r o l l e d l o o p .

    T h e d i f f e r e n c e s b e t w e e n t h e s e t w o l o o p s a r e : ( 1 ) I n

    w h i l e l o o p t h e t e s t e x p r e s s i o n i s e v a l u a t e d a tt h e b e g i n n i n g w h e r e a s i n d o - w h i l e l o o p t e s te x p r e s s i o n i s e v a l u a t e d a t t h e b o t t o m , a f t e r t h e

    b o d y o f t h e l o o p . ( 2 ) I n w h i l e l o o p i f t h e t e s t

    e x p r e s s i o n i s f a l s e l o o p d o e s n o t c o n t i n u e d b u t i n

    d o - w h i l e w h a t e v e r t h e t e s t e x p r e s s i o n t h e l o o p

    e x e c u t e a t l e a s t o n c e .

    Q. Explain the difference betweenbreak

    and

    continuewith an example. [2005] [2008]

    A n s : B o t h s t a t e m e n t s a r e u s e d a s a j u m p e ds t a t e m e n t . B u t t h e r e i s a d i f f e r e n c e b e t w e e n B r e a k

    a n d C o n t i n u e s t a t e m e n t . T h e b r e a k s t a t e m e n t

    t e r m i n a t e t h e l o o p , b u t t h e c o n t i n u e s t a t e m e n t s k i pt h e r e s t o f t h e l o o p s t a t e m e n t a n d c o n t i n u e d t h e

    n e x t i t e r a t i o n o f t h e l o o p . e . g . o f B r e a k S t a t e m e n t i n t

    i = 0 ; w h i l e ( i < = 1 0 ) {i + + ; i f ( i = = 5 ) b r e a k ; S y s t e m . o u t . p r i n t l n (i ) ; }e . g . o f C o n t i n u e S t a t e m e n t i n t

    i = 0 ; w h i l e ( i < = 1 0 ) {i + + ; i f ( i = = 5 ) c o n t i n u e ; S y s t e m . o u t . p r i n

    t l n ( i ) ; }Q. Compare