260 likes | 363 Views
Creating and running a Java program. Some Tips for Using Eclipse. Create a New Java Project. Create new Java Project. File/New/Java Project. Create New Project – Give it a name. Name the project. Add a class to the project. Right-click on src . Select New/Class. New project is open.
E N D
Creating and running a Java program Some Tips for Using Eclipse
Create a New Java Project Create new Java Project File/New/Java Project
Create New Project – Give it a name Name the project
Add a class to the project Right-click on src. Select New/Class New project is open
Adding a new Driver Class Give the class a name If this is the driver class, add a main method Make sure this is checked Click Finish
Generated code Fill in class purpose Fill in method description Fill in body of main method
Add Another Non-Driver class • Use same technique without a main method Class name
Generate Default Constructor Deselect All to Generate Default Constructor Select both Select me
Default Constructor Fill in the Description Fill in the body of the default constructor
Generate Parameterized Constructor • Follow the same process but do NOT deselect the attributes (fields) • All of the following code is generated
Resulting code so far . . . Fill in purpose Fill in parameter details
Generate Getters and Setters Choose those you want Remember it is not always desirable to have getters and setters – depends on what needs to remain private Select me
Added Getters/Setters Depending on which are selected in the previous dialog, a series of getters and setters like this is generated
Other code generators Comment out (or uncomment) the selectedlines of code Add a block of comments to a method you have written Generate a toString method for your class Generate hashCode ( ) and equals ( ) methods
Renaming an attribute or method • Use Refactor / Rename to change the name of a method or attribute of a class, a localvariable, parameter, or even the name of a class. • This changes the name everywhere it appears in the code.
Which import do I need? If you refer to a class that is not in your ownproject or in anyimportedclass, Eclipse puts a redsquigglyline underneath the reference
Let Eclipse help you select the right import • Hover the mouse cursor over the underlined word and a tool-tip will appear; choose what you want from the tool-tip and Eclipse does rest Click this choice
Alternatively, do this • Press ctrl-shift-O (letter O, not zero) and Eclipse will fill in the correct import for you or it will list possible imports and let you choose one
Running a program Right-click on (or in) the driver (code) To run a program
Another way to run the program … Click me
Submitting a project … from your workspace
Project Folder Contents in Workspace Contains .java files for your project Contains the compiled .class files
The bin folder This folder contains the compiled .class files. Do NOT submit them.
The src Folder .java files for the project Zip ONLY these files, naming the zipped folder appropriately. DO NOTzip the containing folder (src or DemoProject1) If you are using a non-Windows machine such as a Mac or a Linux machine, it is your responsibility to be sure your system does NOT add extraneous folders and other items to your zipped folder.
Zipping the files Select the files to be zipped and right-click … some other archiving tool such as 7-zip Use SendTo Compressed Folder or …