Programming in Java(2004-2005)

Embed Size (px)

Citation preview

  • 8/13/2019 Programming in Java(2004-2005)

    1/50

    1

    PROGRAMMING IN JAVA

    LAB MANUAL

    M.C.A. II Year IV Semester

    2004 -05

    MALLA REDDY ENGINEERING COLLEGE

    DEPAR MEN O! M. C. A.

    Dept. of MCA programming in java Lab ---D.U.V

  • 8/13/2019 Programming in Java(2004-2005)

    2/50

    2

    INDE"

    S.No Contents Page No.

    1 Lab Objective 3

    2 Introduction About Lab 4

    3 Guidelines to Students

    4 List o! Lab "#ercises and s$llabus Progra%s &

    'escri(tion about installation and setting o!class(at) and (at)

    *

    + Setting t)e (re re,uired needs !or success!ulrunning o! t)e java a((lications12

    & -ava a((lications based on various Conce(ts 1

    & iva /uestions and Ans0ers 43

    e!erences

    Dept. of MCA programming in java Lab ---D.U.V

  • 8/13/2019 Programming in Java(2004-2005)

    3/50

    3

    LAB OBJEC IVE

    Upon successful completion of t is Lab t e stu!ent "ill be able to#

    1. Demonstrate o" to install t e java soft"are of various version suc as j!$ 1.%&2.% etc.

    2. 'etting t e pre re(uire! nee!s for successful running of t e java applications

    .3. Learn to "rite t e java programs& compiling an! running t e programs.). Learn o" to use variables& Data t*pes &Arra*s control statements

    +. ,rite t e programs base! on concepts/0ncapsulation& n eritance&

    Abstractions an! pol*morp ism.. ,rite t e applications basing on concept of interfaces an! 0 ception an!ling..

    4. Able to create multi t rea!s an! communicate bet"een t em.

    5. Able to an!le t e various events suc as 6e* &mouse events.

    7. 8uil! o"n application base! on applets

    1%. Able to Design t e 0ffective ,08 A90

    Dept. of MCA programming in java Lab ---D.U.V

  • 8/13/2019 Programming in Java(2004-2005)

    4/50

    )

    IN RODUC ION ABOU LAB

    : ere are % s*stems /, ; < installe! in t is Lab . : eir configurations areas follo"s#

    rocessor # ntel Dual Core= 2.0 G#$;AM # +1 M8>ar! Dis$ # 5% 98Mouse # ptical Mouse

    ?et"or$ nterface car! # resent

    So!t0are

    All s*stems are configure! to connect to a 'erver t roug LA? running Linuoperating s*stem.

    : is is useful because stu!ents can save t eir "or$ in t eir o"n accounts. 0acstu!ent@s "or$ is safe an! secure from ot er stu!ents.

    Latest :ec nologies li$e racle 7i an! 200 are installe! in all t e s*stems.

    MA'M / Macro Assembler < is installe! in all t e s*stems

    'tu!ents can e ecute t eir assembl* language programs using MA'M. MA'M is ver*useful stu!ents because " en t e* e ecute t eir programs t e* can see contents ofrocessor ;egisters an! o" eac instruction is being e ecute! in t e C U.

    ;ational ;ose 'oft"are is installe! in some s*stems

    Using t is soft"are& stu!ents can !epict UML !iagrams of t eir projects.

    'oft"are installe!# C& CBB& D61.+& MA'M& C0- & 200 an! D : ?0:&;ational ;ose& racle 7i& nformatica 4.1.2.'*stems are provi!e! for stu!ents in t e 1#1 ratio.

    '*stems are assigne! numbers an! same s*stem is allotte! for stu!ents " en t e* !ot e lab.

    Dept. of MCA programming in java Lab ---D.U.V

  • 8/13/2019 Programming in Java(2004-2005)

    5/50

    +

    Guidelines to Students

    Sett%&' () PA # a&* CLASSPA #

    +%s se,t%(& e /a%&s +( t( 1se t+e PA 5 a&* CLASSPA 5 e& %r(&me&t ar%a3/es (& M%,r(s()t %&*( s S(/ar%s a&* L%&1 .C(&s1/t t+e %&sta//at%(& %&str1,t%(&s %&,/1*e* %t+ 6(1r %&sta//at%(& ()t+e Ja a De e/( me&t 7%t 8JD79 s()t are 31&*/e )(r ,1rre&t%&)(rmat%(&.

    A)ter %&sta//%&' t+e s()t are t+e JD7 *%re,t(r6 %// +a e t+e str1,t1res+( & 3e/( .

    +e bin *%re,t(r6 ,(&ta%&s 3(t+ t+e ,(m %/er a&* t+e /a1&,+er.

    U *ate t+e PA # Var%a3/e 8M%,r(s()t %&*( s N :2000:"P9

    Y(1 ,a& r1& Ja a a /%,at%(&s ;1st )%&e %t+(1t sett%&' t+e PA 5 ar%a3/e. Or 6(1 ,a& ( t%(&a//6 set %t as a ,(& e&%e&,e.

    Set t+e PA 5 ar%a3/e %) 6(1 a&t t( 3e a3/e t( ,(& e&%e&t/6 r1& t+ee e,1ta3/es 8 javac.e#e java.e#e javadoc.e#e a&* s( (&9 )r(m a&6

    *%re,t(r6 %t+(1t +a %&' t( t6 e t+e )1// at+ () t+e ,(mma&*. I) 6(1*( &(t set t+e PA 5 ar%a3/e 6(1 &ee* t( s e,%)6 t+e )1// at+ t( t+ee e,1ta3/e e er6 t%me 6(1 r1& %t s1,+ asolder Na%e fiel! at t e bottomof t e "iEar!& as s o"n belo".

    Dept. of MCA programming in java Lab ---D.U.V

  • 8/13/2019 Programming in Java(2004-2005)

    11/50

    11

    'tep 7 Clic$ Ne#t to continue. Jou s oul! see a Progress panel t at ta$es a fe" minutes to got roug t e installation.

    'tep 1% , en t e installation is complete& *ou s oul! see t e follo"ing

    'tep11. Clic$ inis to e it t e "iEar!.

    Dept. of MCA programming in java Lab ---D.U.V

  • 8/13/2019 Programming in Java(2004-2005)

    12/50

    12

    2. 'etting t e pre re(uire! nee!s for successful running of t e java applications

    'tep1.:o a!! t e ava e ecutable to *our Co%%and Pro%(t pat & open t e Control Panel /from StartB Control Panel o" to !efine an Abstract classWAns0er6 A class containing abstract met o! is calle! Abstract class. An Abstract class canGt beinstantiate!.0 ample of Abstract class#abstract class testAbstractClass N

    protecte! 'tring m*'tringK public 'tring getM*'tring/< N

    return m*'tringKO

    public abstract string an*Abstract unction/o" to !efine an nterfaceWAns0er6 n ava nterface !efines t e met o!s but !oes not implement t em. nterfacecan inclu!e constants. A class t at implements t e interfaces is boun! to implement allt e met o!s !efine! in nterface.0maple of nterface#

    public interface sample nterface N public voi! function ne/

  • 8/13/2019 Programming in Java(2004-2005)

    45/50

    )+

    'crollable result sets- using ne" met o!s in t e ;esult'et interface allo"s programmaticall* move t e to particular ro" or to a position relative to its current position

    D8C 2.% Core A provi!es t e 8atc Up!ates functionalit* to t e java applications. ava applications can no" use t e ;esult'et.up!ate met o!s.

    ?e" !ata t*pes - interfaces mapping t e 'XL3 !ata t*pes Custom mapping of user-!efine! t*pes /U:Ds< Miscellaneous features& inclu!ing performance ints& t e use of c aracter streams& full

    precision for java.mat .8igDecimal values& a!!itional securit* & an! support for timeEones in !ate& time& an! timestamp values.

    /uestion6 0 plain garbage collectionWAns0er6 9arbage collection is one of t e most important feature of ava. 9arbagecollection is also calle! automatic memor* management as VM automaticall* removes

    t e unuse! variables objects /value is null< from t e memor*. User program cannGt!irectl* free t e object from memor*& instea! it is t e job of t e garbage collector toautomaticall* free t e objects t at are no longer reference! b* a program. 0ver* classin erits !inaliEe;< met o! from java.lang.Object & t e finaliEe/< met o! is calle! b*garbage collector " en it !etermines no more references to t e object e ists. n ava& it isgoo! i!ea to e plicitl* assign null into a variable " en no more in use. ava on callingS$ste%.gc;< an! unti%e.gc;o" *ou can force t e garbage collectionW

    Ans0er6 9arbage collection automatic process an! canGt be force!.

    /uestion6 , at is 'WAns0er6 is t e common abbreviation for bject- riente! rogramming.

    /uestion6 Describe t e principles of '.Ans0er6 : ere are t ree main principals of oops " ic are calle! ol*morp ism&n eritance an! 0ncapsulation.

    /uestion6 0 plain t e 0ncapsulation principle.Ans0er6 0ncapsulation is a process of bin!ing or "rapping t e !ata an! t e co!es t atoperates on t e !ata into a single entit*. : is $eeps t e !ata safe from outsi!e interfacean! misuse. ne "a* to t in$ about encapsulation is as a protective "rapper t at

    prevents co!e an! !ata from being arbitraril* accesse! b* ot er co!e !efine! outsi!e t e"rapper.

    Dept. of MCA programming in java Lab ---D.U.V

    http://www.roseindia.net/interviewquestions/corejava.shtmlhttp://www.roseindia.net/interviewquestions/corejava.shtmlhttp://www.roseindia.net/interviewquestions/corejava.shtmlhttp://www.roseindia.net/interviewquestions/corejava.shtmlhttp://www.roseindia.net/interviewquestions/corejava.shtmlhttp://www.roseindia.net/interviewquestions/corejava.shtmlhttp://www.roseindia.net/interviewquestions/corejava.shtmlhttp://www.roseindia.net/interviewquestions/corejava.shtmlhttp://www.roseindia.net/interviewquestions/corejava.shtml
  • 8/13/2019 Programming in Java(2004-2005)

    46/50

    )

    /uestion6 0 plain t e n eritance principle.

    Ans0er6 n eritance is t e process b* " ic one object ac(uires t e properties ofanot er object.

    /uestion6 0 plain t e ol*morp ism principle.Ans0er6 : e meaning of ol*morp ism is somet ing li$e one name man* forms.ol*morp ism enables one entit* to be use! as as general categor* for !ifferent t*pes ofactions. : e specific action is !etermine! b* t e e act nature of t e situation. : econcept of pol*morp ism can be e plaine! as Sone interface& multiple met o!sS.

    /uestion6 0 plain t e !ifferent forms of ol*morp ism.Ans0er6 rom a practical programming vie"point& pol*morp ism e ists in t ree !istinctforms in ava#

    Met o! overloa!ing Met o! overri!ing t roug in eritance Met o! overri!ing t roug t e ava interface

    /uestion6 , at are Access 'pecifiers available in avaWAns0er6 Access specifiers are $e*"or!s t at !etermines t e t*pe of access to t e member of aclass. : ese are#

    ublic rotecte! rivate

    Defaults

    /uestion6 Describe t e "rapper classes in ava.Ans0er6 ,rapper class is "rapper aroun! a primitive !ata t*pe. An instance of a "rapperclass contains& or "raps& a primitive value of t e correspon!ing t*pe.

    ollo"ing table lists t e primitive t*pes an! t e correspon!ing "rapperclasses#

    Pri%itive 8ra((er

    boolean java.lang.Foolean

    b$te java.lang.F$te

    c)ar java.lang.C)aracter

    double java.lang.'ouble

    !loat java.lang.>loat

    Dept. of MCA programming in java Lab ---D.U.V

  • 8/13/2019 Programming in Java(2004-2005)

    47/50

    )4

    int java.lang.Integer

    long java.lang.Long

    s)ort java.lang.S)ort

    void java.lang. oid

    /uestion6 ;ea! t e follo"ing program#

    public class test N public static voi! main/'tring QR args< N int P 3K int * P 1K if / P *< '*stem.out.println/S?ot e(ualS

  • 8/13/2019 Programming in Java(2004-2005)

    48/50

    )5

    : is met o! onl* c ec$s if t e classname "e ave passe! is e(ual to java.lang.Mat .: e class java.lang.Mat is loa!e! b* t e bootstrap ClassLoa!er. : is class is an abstractclass.: is class loa!er is responsible for loa!ing classes. 0ver* Class object contains areference to t e ClassLoa!er t at !efines. getClass/< met o! returns t e runtime class ofan object. t fetc es t e java instance of t e given full* (ualifie! t*pe name. : e co!e "e

    ave "ritten is not necessar*& because "e s oul! not compare getClass.get?ame/

  • 8/13/2019 Programming in Java(2004-2005)

    49/50

    )7

    /uestion6 , at is List interface WAns0er6 List is an or!ere! collection of objects.

    /uestion6 , at is a Vector Ans"er# Vector is a gro" able arra* of objects.

    /uestion6 , at is t e !ifference bet"een *iel!/< an! sleep/

  • 8/13/2019 Programming in Java(2004-2005)

    50/50

    +%

    E2E EN0ES ,

    Text (oo/s:1.o4 to program .

    0.Batri-A +aughton &>er2ert S-hildt& Complete !e:eren-e a2a0 3e&TM>

    3. 7oel SAlar UBrin-iples o: We% ans 9ergstan& 7a2a Ser2er Bages &B

    0. Se%esta U Brogramming the World Wide We% .B

    3. !eeta Sahoo&5angan Sahoo. 7a2a 0 the -omplete re:eren-e

    9ooA &5algotia.