CSC 210: Installing and running Java programs using ...Once you install the JDK, then reinstall...

Post on 04-Aug-2020

8 views 0 download

Transcript of CSC 210: Installing and running Java programs using ...Once you install the JDK, then reinstall...

CSC210:InstallingandrunningJavaprogramsusingEclipse

DownloadingEclipse

1. DownloadEclipseOxygenfromhttps://eclipse.org/downloads/byclickingontheappropriatelink.

2. Whenprompted,selecttoinstalltheEclipseIDEforJavaDevelopers3. NotethatinordertorunEclipse,yourcomputerhastohaveaJavaVirtualMachine(JVM)

installed.IfyoudonothaveaJVMinstalled(whichislikely)andyoutrytoinstallEclipse,youwillgetanerrormessagesimilartotheonebelow.

Ifthisisthecase,select‘No’andtheninstalltheJVMbyinstallingtheappropriateJavaStandardEdition(SE)DevelopmentKit(JDK)fromthefirsttablefromthiswebsite:

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html OnceyouinstalltheJDK,thenreinstallEclipse,andEclipseshouldwork.

OpeningEclipse

1. DoubleclicktheEclipseicontoopenEclipse.Youwillbepromptedtoselectadirectoryasaworkspace.ThisdirectorywillstorepreferenceandotherinformationandisthelocationwhereEclipselooksforyourPlaygroundproject.Inyourpersonalcomputer,thedefaultworkspacelocationshouldbeused.Fromaclassroomcomputer,wewillputtheworkspaceinZ:/CSC210,andwillselectthisworkspacewheneveropeningEclipse.

CreatingaProject

1. SelectFileàNewàJavaProject.Nametheproject'Playground'andclickfinish.WewillusethePlaygroundprojectforallprogramsinclass,unlessspecifiedotherwise.ThisPlaygroundprojectwillbecreatedinthecurrentworkspace.

Addingandremovingasingleprogram(i.e.,asingle*.javafile)

1. RightclickontheSourceFolder(e.g.,src)inthePackageExplorertabandselectNewFile2. ClickonAdvancedandclickon'Linktofileinthefilesystem'3. Click'Browse'toselectthefiletoadd,thenclickon'Finish'4. ToremoveaprogramfromEclipse,rightclickontheprogramtoremove,andselectDelete.

Note:youshouldgetamessageindicatingthatonlytheworkspacelinkwillbedeleted.Ifthisisthecase,clickOKtoremovetheprogramfromyourproject.IfthisisNOTthecase,thenremovingtheprogrammaydeletethefilefromyourcomputer.Seemeifthishappens.

Addingandremovingafolderwithmultipleprograms

Note:inthisclass,wewillassumethatallprogramstobeaddedareinthesamefolder,andnotinoneormoresubfolders.AddingafoldercontainingsubfoldersofprogramscanbedoneinEclipse,buttheprocessisalittlemorecomplicated.

1. Ifyouhaveafoldercontainingoneormoreprograms,youcanaddthefolderbyrightclickingontheProjectunderthePackageExplorer(wehavenamedtheprojectPlayground),thenclickingonBuildPathàLinkSourceandselectingtherelevantfolder.

2. Toremovefoldersthathavebeenaddedfollowingthedirectionsabove,rightclickonthefolderthathasbeenadded,andselectDelete.Amessageshouldcomeupindicatingthatonlyworkspacelinkswillbedeleted.Beawarethatifyoudonotreceivethismessage,youwillbedeletingtheactualfilesratherthansimplyremovingthemfromyourproject(whichyouprobablydon'twanttodo–seemeifthisisthecase).ClickonOKtocompletetheprocess.

Creatingandrunningaprogram(wewillnotdothisuntilmuchlaterinthesemester)

1. CreateaProjectinthecurrentworkspaceifyoudonothaveonealready.2. SelectFileàNewàClass3. Giveyourclassaname,suchasHelloWorld.ThiswillcreatethefileHelloWorld.javainyour

Projectfolder.Note:ifyoucreateaprograminthismanner,removingtheprogramfromyourProjectfoldercancauseproblems.

4. Under'Whichmethodstubswouldyouliketocreate?'check'publicstaticvoidmain(String[]args)'

5. Click'Finish'

Forafirstprogram,modifytheHelloWorld.javaprogramwithinEclipsetoreadasfollows:

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }

6. Torunaprogram,clickonthegreenplayicon.Programoutputappearsatthebottomofthescreen.