Page|1
SUMMERTRAININGREPORT
ON
JAVA
Submittedinthepartialfulfillmentforthe
awardofdiplomaofengineeringincomputer
science&engineering.
Govt.polytechnic,kashipur
(2017-2018)
SUBMITTEDTO SUBMITTEDBY
Mrs.AnitaMam ShivaBhatt
ComputerScience&
Eng.
Page|2
TABLEOFCONTENTS
TOPIC Page(s)
1:Introduction 3-6
1.1.IntroductiontoOOPS
1.2 Objects
1.3Class
1.4 Polymorphism
1.5 Encapsulation
1.6Inheritance
1.7 Abstraction
1.8 Newoperator
1.9 Instances
2: Constructor 7-9
2.1DefaultConstructor
2.2ParameterizedConstructor
2.3ConstructorOverloading
3:Statickeyword 10-11
3.1Staticvariable
3.2Staticmethod
3.3Staticblock
4:Polymorphism 12-13
4.1TypesofPolymorphism
Page|3
4.2FunctionOverloading
4.3DataShadowing
5:Inheritance 14-15
5.1FunctionOverriding
5.2Upcasting
5.3Downcasting
6:Abstraction 16-18
6.1Abstractclass
6.2Interfaces
6.3Extendinginterfaces
6.4Extendingmultipleinterfaces
7:StringHandling 18
7.1Rules
7.2MethodsofStringclass
8.ProjectforInstituteManagementusingSwingandpackage 19
1.IntroductiontoOOPs:
OOPsstandsforObjectOrientedProgrammingthatprovidesmanyconcepts
suchasInheritance,Abstraction,Encapsulation,Polymorphismetc.
1.1Object
Anyentitythathasstateandbehaviorisknownasanobject.Forexample:
Page|4
chair,pen,table,keyboard,bikeetc.Itcanbephysicalandlogical.
1.2Class
Collectionofobjectsiscalledclass.Itisalogicalentity.
1.3Inheritance
Whenoneobjectacquiresallthepropertiesandbehaviorsofparentobjecti.e.
knownasinheritance.Itprovidescodereusability.Itisusedtoachieveruntime
polymorphism.
1.4Polymorphism
Whenonetaskisperformedbydifferentwaysi.e.knownaspolymorphism.
Forexample:toconvincethecustomerdifferently,todrawsomethinge.g.
shapeorrectangleetc.
Injava,weusemethodoverloadingandmethodoverridingtoachieve
polymorphism.
Anotherexamplecanbetospeaksomethinge.g.catspeaksmeaw,dogbarks
woofetc.
1.5Abstraction
Page|5
Hidinginternaldetailsandshowingfunctionalityisknownasabstraction.For
example:phonecall,wedon'tknowtheinternalprocessing.
Injava,weuseabstractclassandinterfacetoachieveabstraction.
1.6Encapsulation
Binding(orwrapping)codeanddatatogetherintoasingleunitisknownas
encapsulation.Forexample:capsule,itiswrappedwithdifferentmedicines.
Ajavaclassistheexampleofencapsulation.Javabeanisthefully
encapsulatedclassbecauseallthedatamembersareprivatehere.
1.7NewOperator
Itdynamicallyallocatesbufferinheapwiththereferencewedefinepointed
fromthestack.
Foreg. Demoobj;
Obj=newDemo();
Thisstatementdoestwothings:
1.Itcreatesactual(physical)objectinheapwiththevariable‘obj’instack
pointingtheobject.
2.Itcallstheconstructorof‘Demo’classfortheintializationofobject.
Page|6
 Injava,onlyobjectsaregettingmemoryatruntime.
 Newoperatorisonlyusedtoallocateamemoryforobjectonly.
 Thememorythathasbeenallocatedatruntimedoesnothaveany
name.
 Injava,pointersarenotdefined.ItusesReferenceIDfortheallocation
whichisstoredinsideReferenceVariable.
1.8Instance:
Itisactuallythephysicalexistenceofanobject.
Foreg.Carisaclassandifweseeanycarinreality,thenitisgeneralthing.
2.ConstructorsInJava:
Constructorinjava isa specialtypeofmethod thatisusedtoinitializethe
Page|7
object.
Javaconstructoris invokedatthetimeofobjectcreation.Itconstructsthe
valuesi.e.providesdatafortheobjectthatiswhyitisknownasconstructor.
Rulesforcreatingjavaconstructor
Therearebasicallytworulesdefinedfortheconstructor.
1. Constructornamemustbesameasitsclassname
2. Constructormusthavenoexplicitreturntype
Typesofjavaconstructors
Therearetwotypesofconstructors:
1. Defaultconstructor(no-arguementconstructor)
2. Parameterizedconstructor
2.1DefaultConstructor:
Eg.
classBike1{
Bike1(){
System.out.println("Bikeiscreated");
}
publicstaticvoidmain(Stringargs[]){
Page|8
Bike1b=newBike1();}}
Output:
Bikeiscreated
Rule:Ifthereisnoconstructorinaclass,compilerautomaticallycreatesa
defaultconstructor.
2.2ParameterizedConstructor:
A constructorthathaveparametersisknownasparameterizedconstructor.
Parameterizedconstructorisusedtoprovidedifferentvaluestothedistinct
objects.
ConstructorOverloadinginJava
ConstructoroverloadingisatechniqueinJavainwhichaclasscanhaveany
numberofconstructorsthatdifferinparameterlists.Thecompiler
differentiatestheseconstructorsbytakingintoaccountthenumberof
parametersinthelistandtheirtypes.
Page|9
3.Javastatickeyword
Thestatickeywordinjavaisusedformemorymanagementmainly.Wecan
applyjavastatickeywordwithvariables,methods,blocksandnestedclass.
Thestatickeywordbelongstotheclassthaninstanceoftheclass.
Thestaticcanbe:
variable(alsoknownasclassvariable)
method(alsoknownasclassmethod)
block
nestedclass
1)Javastaticvariable
Ifyoudeclareanyvariableasstatic,itisknownstaticvariable.
Thestaticvariablecanbeusedtoreferthecommonpropertyofallobjects
(thatisnotuniqueforeachobject)e.g.companynameofemployees,college
nameofstudentsetc.
Thestaticvariablegetsmemoryonlyonceinclassareaatthetimeofclass
loading.
Advantageofstaticvariable
Itmakesyourprogrammemoryefficient(i.eitsavesmemory).
Understandingproblemwithoutstaticvariable
classStudent{
introllno;
Stringname;
Stringcollege="ITS";
Page|10
}
Supposethereare500studentsinmycollege,nowallinstancedatamembers
willgetmemoryeachtimewhenobjectiscreated.Allstudenthaveitsunique
rollnoandnamesoinstancedatamemberisgood.Here,collegereferstothe
commonpropertyofallobjects.Ifwemakeitstatic,thisfieldwillgetmemory
onlyonce.
Javastaticpropertyissharedtoallobjects.
2)Javastaticmethod
Ifweapplystatickeywordwithanymethod,itisknownasstaticmethod.
Astaticmethodbelongstotheclassratherthanobjectofaclass.
Astaticmethodcanbeinvokedwithouttheneedforcreatinganinstanceofa
class.
staticmethodcanaccessstaticdatamemberandcanchangethevalueofit.
3)Javastaticblock
Isusedtoinitializethestaticdatamember.
Itisexecutedbeforemainmethodatthetimeofclassloading.
Page|11
4. POLYMORPHISM:
Wheneveranobjectgivesdifferentbehavioraccordingtodifferent
environmentthenitissaidtobepolymorphism.
Eg.System.out.println(10);
System.out.println(“hi”);
System.out.println(2.4);
Here,byusingonlyonefunction,wepasseddifferenttypeofvalues.
*Polymorphismisalwaysachievedbythebehaviorofanobject.
Polymorphismareoftwotypes:
1.RunTimePolymorphism(LateBinding):
Objectisbindwithitsfunctionalityatruntime.
2.CompileTimepolymorphism(EarlyBinding):
Objectisbindwithitsfunctionalityatcompiletime.
 JavadoesnotsupportOperatoroverloadingexplicitly.
Rule:JavadoesnotsupportCompiletimePolymorphism.Onlyincaseof
Staticfunction CompileTimePolymorphismissupported.ButStatic
functionsarebindatclasslevel.SoCTPinjavaisnotsupported.
Rule:Bydefaultallthenonstaticfunctionexceptstatic,final,privateare
implicitvirtual andvirtualfunctionalwaysbindatruntime.
4.1. Functionoverloading:
Functionoverloadingsaysifyouhavemorethanonefunctionwith
samenameinoneclassbuthavingdifferentprototypes.
Functionprototypesconsistsof5thimgs:
1.Accessspecifier
Page|12
2.Accessmodifier
3.Returntype
4.Name
5.Argiuement
 Accessspecifier,accessmodifier,andreturntypedonotplayanyrole
infunctionoverloading.
 Functionoverloadingcanonlybeachievedbychangingargumentsin2
ways:
1.Changeinnumberofarguments
2.Changeindatatypeofargument
4.2DataShadowing
Wheneverclasslevelvariableandlocallevelvariablehavesamename
,ThenlocalVariablevalueovershadowstheclasslevelvariable’svalue.
ThisconceptiscalledDatashadowing.
Thiskeyword:
 Allthenonstaticfunction,implicitlyaccessclasslevelvariablein
objectbyusing‘this’keyword.
 ‘this’catchesRIDofobjectimplicitlyinnonstaticfunction.
Ifdatashadowingoccursthentoaccessclasslevelvariablevalues,use
of‘this’ismandatory.
 ‘this’keywordcannotbeusedinstaticfunction.
Page|13
6.Inheritance:
Itisusedtoachievereusability,optimization,timeandcostutilization.
ItisachievedbyFunctionOverriding.
Eg.SyntaxofjavaisinheritedfromyhesyntaxofClanguage.
InheritanceisaISARELATIONSHIP.
 Javadoesnotsupportmultipleinheritance.
 Bydefaultallthedatamemberandmemberfunctionofparentclass
areavailabletochildclassiftheyarenotprivate.
6.1Functionoverriding:
Wheneverparentclassandchildclassbothhavememberfunction
ofsamesamethenchildfunctionoverridesparentfunction.This
conceptiscalledfunctionoverriding.
 Staticmethodcannotoverrideanotherstaticmethod,buttheycanhide
anothermethodanditiscalledfunctionhiding.
 Ifmethodofparentismadeprivatethenwhatevertheaccessspecifier
ofmethodofchildis,functionoverridingisnotpossible.
 Finalmethodscannotbeoverriddenbymethodofchildclass.
 Onlyinheritedmethodcanbeoverridden.
 Theoverridingmethodandoverriddenmethodmusthavesame
argumentlistandareofsamereturntype.
 Constructorscan’tbeoverriddenbutcanbeoverloaded.
 Abstractmethodmustbeoverriddenbynonabstractsubclass.
6.2 Upcasting
TheRIDofchildclassobjectisputintheRVofparentclassbutvice
Page|14
versaisnottrue.
Eg.Parentp=newChild();
6.3 Downcasting
TheprocessofgettingbackRIDofachildclassobjectfromparent
classRVtochildclassRV. Eg.Childc=(Child)p;
Page|15
7.Abstraction:
Itisusedtodefinestandards.
Itisusedtohidetheinternalworking.
Abstractfunctiondefinestandards,implementationvariesfrom
onestandardtoother.
Therearetwowaystoachieveabstraction:
1.ViaabstractClass
2.ViaInterface
7.1AbstractClass
 Abstractclassissimilartonormalclassinjavaexceptitcan’tbe
instanciated.
 Abstractclasscanonlycontainabstractmethods.
 Itmaycontainmorethanoneabstractmethodsoralsocontainnon
abstractmethods.
 Achildclasshastooverridealltheabstractmethodofanabstract
methods,Otherwiseithastomakeitselfabstract.
Eg.
abstractClassBase{
Intx;inty;
voidshow(){
System.out.println(x);System.out.println(y);
}
Abstractvoidget();}
ClassChildextendsBase{
Page|16
Voidget(intx,inty){
this.x=x;
this.y=y;}
publicstaticvoidmain(Stringargs[])
{
Childc1=newChild();
C1.get(1,2);
C1.show();
}
}
Output:
1
2
7.2Interfaces:
Interfacesaretheblueprintofaclass.
Itisareferencetypeinjava.Itisacollectionofabstractmethods.
Aclassimplementsaaninterface,therebyinheritinganabstract
methodsftheinterface.
Alongwiththeabstractmethods,italsocontainconstants,default
methods,staticmethods,andnestedmethods.
Interfacecontainsthebehaviorthataclassimplements.
 Interfacecan’tbeinstanciated.
 Interfacedoesnotcontainanyconstructors.
 Allthemethodsofinterfaceareabstract.
 Aninterfaceisnotextendedbyaclass.
Page|17
 Aninterfacecanextendmultipleinterfaces.
Interfacekeywordisusedtodeclareinterface.
Foreg.
InterfaceMy{
voidshow();}
classChildimplementsMy{
publicvoidshow()
{System.out.println(“show”);}
Publicstaticvoidmain(Stringargs[]){
Mym=newMy();
m.show();}
output:
show
7.3ExtendindInterfaces:
Eg.
publicinterfaceSports{
publicvoidshow();
}
PublicinterfaceFootballextendsSports{
Publicvoidscore();
}
7.4Extendingmultipleinterfaces
Eg.PublicinterfacehockeyextendsSports,Football{}
8.StringHandling:
Creatingstringbymostdirectway:
Page|18
Stringg=“Helloworld”;
 Stringclassisimmutablesoonceobjectiscreateditcan’tbechanged.
ImportantmethodsofStringclass:
1.byteb[]=g.getBytes();
2.charch[]=g.toCharArray();
3.charc=g.charAt(2);
4.Strings1=g.toUpperCase();
5.Strings2=g.toLowerCase();
6.Strings1=g.subString(10);
7.Strings2=g.subString(0,4);
8.Strings=String.valueOf(10);
9.intI=Integer.parseInt(“10”);etc.
StringConcatenation:
Strings=“good”;
S=s+“morning”;
StringComparision:
1.Booleanb=s1.equals(s2);
Italwayscomparesthecontentofreferencevariable,ifsamethenreturns
true;
2.booleanb=s1.equalsIgnoreCase(s2);
3.intx=s1.CompareTo(s2);
Page|19
9.ProjectforInstituteManagementUsingSwingandPanel:
InthiswehavemadeaLibrearymanagementprojectinwhichanadmin
managestheRecordofbooks,AddbookwhichyouwanttostoreonLibreary,
Availablebooks,,IssueBook,ReturnBook.Onlytheadministratorhasthe
permissiontomanagethisinstitutemanagementapplication.
Forcreatingthisapplication,weneedthefollowingfile:
1.Javafile:
forwritingcode.Inthisfileweuseswingandpackagecomponentsto
createaregistrationformwithpasswordvalidation.
2.Odbc.jarfile:
ThisjarfileprovidesawaytosetupaJavaconnectionwithanOracle
Database.
3.Msaccessfile:whichisusedtostorethedatabasetables.
4.Regtableindatabase1.mdb(msaccessfile):forfetchingrecordswe
needadatabasetable.
Page|20
INTERODUCTION:-LibrarymanagementsystemprothemainobjectiveoftheLibrary
Managementsystemprojectisdisciplineoftheplanning,organizingandmanagingthe
librarytasks.Ourprojectaimsatmakingthetaskoflibraryeasy.LibraryManagementis
enteringtherecordsofnewbookandretrievingthedetailsofbookavailableinthelibrary.
Wecanissuebooktothelibrarymemberandmaintaintheirrecordsandcanalsochecks
howmanybookareissuedandstockavailableinthelibrary.Intheprojectwecanmaintain
thelatefineoflibrarymemberwhoreturntheissuedbookaftertheduedate.ThisLibrary
managementsystemprojectinJAVAandMSSQLserver.
Projecttitle:
Librarymanagementsystem/LibrarymanagementsystemprojectinJAVA
RDBMS
Languageandsoftwaretoolused:
Page|21
FrontEnd:Java
OperatingSystem:Window10
BackEnd:MicrosoftSQLServer
ProposedSystem:
Intheproposedsystem,weassumethateachmemberwillbehavingaidentitywhichcan
beusedforthelibrarybookissue.wheneverlibrarymemberwishtotakeabook,thebook
issuedbythelibraryauthoritywillbecheckboththebookdetailsaswellasthestudent
detailsandstoreitinlibrarydatabase.
 ModuleDescription:
1.UserModule:
 Inthismodulestudentcancheckavailabilityofthebook…
 Thefollowingarethesubmoduleintheusermodule.
Bookreturn:Herestudentwillreturnthebookstothelibrary…
 2.LiberianModule:
 Thisisthemainmoduleintheproposedproject.TheLiberiancanreadand
writeinformationaboutanystudent.TheLiberiancanalsoupdate,createand
deletetherecordofstudentasperrequirementandimplementationplans.
 Thefollowingarethesubmoduleintheadministratormodule.
 Bookdetails:AllowLiberiantoenteredbookdetails.
 Bookissue:HereLiberianissuesthebookstothestudentfromlibrary.
 Futurescopeoftheproject:
Wecanconsidermuchfuturescopetothisapplication.Thefollowingare
Page|22
someofthere.
 OnlineuseofthelibrarycanbegoodfeaturefortheLibraryManagement
system.
 Advancedfinepaymentsystemcanbeadded.
 Inventorysystemcanbeusedtomaintainthebooksofthelibrary.
 Hardwarerequirement:Operatingsystem:Window10
 Harddisks:GB
 RAM:MB
Softwarerequirement:
 Javalanguage
 Javadevelopmentkit7
 MSSQLserver
ModuleOfProject:
 LoginPage.
 Menu.
 AddBook.
 AvailableBook.
 IssueBook.
 ReturnBook.
 Bookdetails:AllowLiberiantoenteredbookdetails.
Page|23
 Bookissue:HereLiberianissuesthebookstothestudentfromlibrary.
 Futurescopeoftheproject:
Wecanconsidermuchfuturescopetothisapplication.Thefollowingare
someofthere.
 OnlineuseofthelibrarycanbegoodfeaturefortheLibraryManagement
system.
 Advancedfinepaymentsystemcanbeadded.
 Inventorysystemcanbeusedtomaintainthebooksofthelibrary.
 Hardwarerequirement:Operatingsystem:Window10
 Harddisks:GB
 RAM:MB
Softwarerequirement:
 Javalanguage
 Javadevelopmentkit7
 MSSQLserver
ModuleOfProject:
 LoginPage.
 Menu.
 AddBook.
 AvailableBook.
 IssueBook.
 ReturnBook.
Page|24
LoginPage-:
TheLoginpageisthefirstpageoftheproject.Whichisthegrantthepermissiontothe
liberationbyaccessingthecorrectsecuritylevel?WheretheusernameorPassword.
HerethethreePanelareusedintheLoginPage,inwhichthefirstpanelisusesforthe
LIBRARYMANAGMENT.thesecondpanelisusedfortheuseridandpasswordandthelast
panel,panelthreeisusedforthefinalprocessoftheloginpageasaLoginintheprojector
canceltheloginpage.
Afterthecorrectinformationprovidingintheloginpagetheauthorisedusercanenterin
theproject...andhewillbeaccessallthefunctionoftheproject.suchasaddbook,return
booketc
Completetheprocessofloginpageasacompleteandcorrecttheauthorisedusergoes
awaythenextpage(Menu).
Inthecaseofincorrectusernameorpasswordtheloginpagewillbeshowthedialogbox
andinstructionthattheusernameorpasswordisinvalid.
Page|25
Menu-:
Themenupageoftheprojectiscontainthe4button.whichistheuseforopennewpage
forusingspecialaction.
Wherethefollowingbuttonsareusing.theyarefollowingtypes-----
 AddBook.
 AvailableBook.
 IssueBook.
 ReturnBook.
Page|26
AddBook-:
Theaddbookpageoftheprojectisthepageinwhichthenewbooksaretheaddingin
libraryrecordthrowthelibrarian.
Wherethegeneralinformationshouldmusttoaddedinthefield.Afterthesubmittingthe
alldetailsthedetailofthebookissavedintheavailablebook.
Page|27
AvailableBook-:
 Theavailablebookoftheprojectistherecordoftheallbookswhicharetheaddedin
thelibrary.Theaddbooksdatabaseareconnectedwiththeavailablebook.Thebooks
whoaretheaddedintheaddbookpagetheyarestoredintheavailablebook.Inwhich
thealldetail
Page|28
ofthebooksaretheincludedsuchas,bookname,bookid,publisher,publishingyear,
addingdateetc.
IssueBook-:
Theissuebookistheprocessofthedestructionofthelibrary’sbooktotheusers,where
theallgeneralinformationofuser’s&booksareaddedinthepageoftheissuebook.after
thatthebooksarethecheckoutfromthelibrary.
Page|29
ReturnBook-:
Thereturnbookofthejavalibrarymanagementsystemisthelastpage,inwhichthe
booksarecheckininthelibrarywhicharethecheckoutbythelibrary.
Thebasicdetailofthebooksandusersaresubmittingsameastheissuebookpage.after
thatthebooksarecheckininthelibrary.
Page|30
Conclusion
Thistrainingfocusseduponincreasingourknowledge
andinterestintowardthejava.Becausejavaismost
interestingandmostusedlanguageinthesedays.We
learnthowtocreateawebsitesandwebpages.Itwas
agreatexperience.Itincreaseourpracticalskills
that‟sthemainthingwhichwelearntinthetraining
session.Thus,webelievethatourprojectwillbe
beneficialforvariouspurposes&henceourefforts
willbefruitful.

summer training report on java