Professional Documents
Culture Documents
NetBeans IDE 3 Quickstart
NetBeans IDE 3 Quickstart
6QuickStartGuide
NetBeansIDE3.6QuickStartGuide
ThisdocumenttakesyouthroughthebasicsofusingNetBeansIDE3.6bycreatingasimpleHelloWorldapplication.This
documentisdesignedtogetyougoingasquicklyaspossible.IfyouwantamoredetaileddescriptionofNetBeansIDEfeatures,
seethefollowingdocuments:
NetBeansOnlineHelp.ThedocumentationincludedinNetBeansIDEitself.PressF1toopentheonlinehelp.
UsingNetBeansIDE:ThecompleteguidetodevelopingJavaapplicationsinNetBeansIDE.Archivedonthe
netbeans.orgsite.
GUIBuildinginNetBeansIDE3.6:AquickguidetobuildinggraphicaluserinterfaceswiththeNetBeansIDEFormEditor.
Archivedonthenetbeans.orgsite.
NetBeansSupportandDocs(forthecurrentrelease)Fulllistofarticles,FAQs,andmailinglistsforNetBeansIDE
users.
ProjectSetup
Task Description
Createanew 1.ChooseProject>ProjectManager(CtrlShiftN).
project 2.ClickNew,givetheprojectaname,andclickOK.
Addasource 1.ChooseFile>MountFilesystem.
directory 2.SelecttheLocalDirectorynodeinthewizardthatappearsandclickNext.
3.OnSelectItemstoMountpageofthewizard,createafolderonyoursystemcalledsrc.
Note:IfyouareonaWindowssystem,youcannotcreateanewfolderinyourMyDocumentsfolder.
4.SelectthefolderandclickFinish.
ThesrcfilesystemnodeappearsintheFilesystemswindow.Thefilesystem'ssourcesareaddedtothe
projectclasspath.
Note:Don'tnavigateintothesrcdirectory.JustselectthesrcdirectoryandclickFinish.
Createanew 1.RightclickthesrcdirectorynodeintheFilesystemswindowandchooseNew>JavaPackage.
package 2.Inthenamefield,typehelloandclickFinish.
Createanew 1.Rightclickthehellopackage'snodeintheFilesystemswindowandchooseNew>JavaMainClass.
file 2.Inthenamefield,typeHelloWorldandclickFinish.
EditingSourceFiles
Task Description
Introduction Inthissection,wewillwritethecodefortheHelloWorldapplication.Wewillusethefollowingtools:
Codecompletion.TheSourceEditorparsesallofthepackagesandclassesintheclasspath,including
thestandardJDKclasses,andautomaticallysuggestsmatchingpackagesandclassesasyoutype.
Abbreviations.TheIDEincludesabbreviationsformanycommonlyusedwordcombinationsthat
expandtothefullwordswhenyoupressSpace.Forexample,typingpsfandpressingSpaceexpands
theabbreviationtopublicstaticfinal.
FastImport.TheSourceEditorletsyouautomaticallygeneratetheimportstatementforanyclass.
Automaticformattinganderrorhighlighting.
Whenyouaredonewiththissection,HelloWorld.javawilllooklikethis:
/*
*HelloWorld.java
*
*Createdon16November2004,11:52
*/
packagehello
importjava.util.Date
/**
*
*@authorme:)
*/
publicclassHelloWorld{
/**CreatesanewinstanceofHelloWorld*/
publicHelloWorld(){
}
http://ibcomp.fis.edu/NetBeans/quickstart.htm 1/3
24/03/2017 NetBeansIDE3.6QuickStartGuide
/**
*@paramargsthecommandlinearguments
*/
publicstaticvoidmain(String[]args){
Stringdate=newDate().toString()
System.out.println("Helloworld!It's"+date)
}
Usecode 1.Placethecursorattheendofthepublicstaticvoidmain(String[]args){lineandpressEnter.
completion 2.TypeStringdate=newDatandwait.Withinasecondortwo,thecodecompletionboxshould
appear,listingalloftheJDKclassesthatbeginwithDat.Youcanalsomanuallyopenthecode
completionboxbypressingCtrlSpace.
TheSourceEditoralsoshowstheJavadocdescriptionofeachclass,ifavailable.TheIDEextractsthis
descriptionfromtheJavadoccommentsinthesourcecode.Formoreinformationonworkingwith
Javadocdocumentation,seetheUsingNetBeansIDEguide.
3.Inthecodecompletionbox,scrolldowntoDate.NoticetherearetwoDateclassesintheclasspath.
SelecteitherofthetwoandpressEnter.u
Note:Unlessyouuseafullyqualifiednameforaclass,thecodecompletionboxoffersthemethodsof
allclasseswiththesamename.Itthereforedoesnotmatterwhetheryouchoosejava.sql.Dateor
java.util.Datefromthecodecompletionboxinthestepabove.
4.Type(.NoticetheIDEautomaticallyfillsintheclosingparentheses.
5.Gototheendofthelineandtypea.aftertheclosingparentheses.Thecodecompletionsboxopens
listingallofthemethodsintheDateclass.Deprecatedmethodsareshownwithalinecrossed
throughthem.StarttypingtoStringtonarrowtheselectiondown,thenselecttoStringandpress
Enter.
6.Typeaclosing.
Createimport 1.PlacetheinsertionpointanywhereinthewordDateandpressAltShiftI.
statement 2.IntheFastImportdialogbox,choosejava.util.DateandclickOK.Theimportstatementiscreated
andtheSourceEditornolongershowsanerrorfortheline.
Expand 1.PlacethecursorattheendoftheStringdate=newDate().toString()lineandpressEnter.
abbreviations 2.TypesoutandpressSpace.ThesoutabbreviationexpandstoSystem.out.println("")
3.TypeHelloWorld!It'sbetweenthequotationmarks(besuretoincludeaspaceafterIt's).
4.Aftertheclosingquotationmark,type+date.
Reformatcode Ifthespacingforthecommentlinedoesnotmatchthespacingfortherestofthefile,pressCtrl
ShiftFtoreformattheentirefile.IfanylinesareselectedwhenyoupressCtrlShiftF,onlythose
linesarereformatted.
CompilingandRunningYourProgram
Task Description
Compilethe ChooseBuild>Compile(F9).
program TheOutputwindowopensatthebottomoftheIDEanddisplaysanycompileroutput,including
compilationerrors.Youcandoubleclickanyerrortogotoitslocationinthesourcecode.
Runthe ChooseBuild>Execute(F6).
program TheIDErunstheprogramandprintstheoutputtotheOutputwindow.Youshouldseethefollowing
messageintheOutputwindow(withadifferentdate,ofcourse):
HelloWorld!It'sWedDec1018:15:20CET2003
DebuggingYourProgram
Task Description
Adda Clickintheleftmargin(ShiftF8)ofthefileontheSystem.out.println("HelloWorld!It's"+
breakpointtoa date)line.
file Aredbreakpointiconappearsinthemarginandthelineishighlighted.
Addawatchto 1.RightclicktheworddateintheStringdate=newDate().toString()lineandchooseNew
http://ibcomp.fis.edu/NetBeans/quickstart.htm 2/3
24/03/2017 NetBeansIDE3.6QuickStartGuide
avariable Watch(CtrlShiftF7).
2.MakesurethattheWatchExpressionfieldcontainsdate(withalowercased)andclickOKinthe
dialogbox.
Starta ChooseDebug>StartSession>RuninDebugger(AltF5).
debugging TheIDErunsthefileuntilthebreakpointisreached.Usethedebuggerviewsatthebottomofthe
session IDEtomonitoryourprogram'sstate,suchasthevalueofthedatevariable(listedunderbothLocal
VariablesandWatches).
Stepthrough UseStepInto(F7)andStepOver(F8)toexecutetheprogramonelineatatime.
program
execution
Stopa ChooseDebug>FinishSessions(ShiftF5).
debugging
session
http://ibcomp.fis.edu/NetBeans/quickstart.htm 3/3