Download presentation
Presentation is loading. Please wait.
Published byGavin Perry Modified over 8 years ago
1
Creating and running a Java program
2
Eclipse Interactive Development Environment (IDE) Eclipse is an Interactive Development Environment (IDE) for Java programmers It provides project manager A project manager to manage all Java projects throughout the semester codeeditor NotePad++) An code editor that helps write correct Java instructions (no need for NotePad++) executionenvironmentcompile testrunwithoutleaving no more Command Line An execution environment in which one can compile, test, and run Java programs without leaving Eclipse (no more Command Line use)
3
Eclipse Workspace Eclipse Workspace folder allJavaprojects An Eclipse Workspace is simply a folder where all Java projects for the semester will be stored must remember where it is You must remember where it is once you select it write access permissions It must be a place where you have write access permissions It must be a place that you can access when you need it thumb driveZ:\ portableharddrive cloudstorageDropBoxOneDriveBox Example: thumb drive, Z:\ drive, portable hard drive, or cloud storage such as DropBox, OneDrive, Box, etc. Workspace Make sure there is enough space in the Workspace to hold all projects for the semester
4
Eclipse Be sure Java is selected Java editor – type code here Error messages and running program output display here Java projects in your workspace
5
Create a New Java Project Create new Java Project File/New/Java Project
6
Create New Project – Give it a name Name the project
7
New Project in the Package Explorer new project PackageExplorer Eclipse After creating a new project as on the previous slide, it will appear in the Package Explorer column on the left in Eclipse Project name Subfolder for.java files Java library – contains Java API classes such as String, Scanner, etc.
8
Add a class to the project Right-click on src. Select New/Class New project is open
9
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 Assign a package name
10
Generated code Fill in class purpose Fill in method description Fill in body of main method
11
Add Another Non-Driver class Use same technique without a main method Class name hw1
12
Add desired attributes
13
Generate Default Constructor Select me Deselect All to Generate Default Constructor Select both
14
Default Constructor Fill in the Description Fill in the body of the default constructor
15
Generate Parameterized Constructor Follow the same process but do NOT deselect the attributes (fields) All of the following code is generated
16
Resulting code so far... Fill in purpose Fill in parameter details
17
Generate Getters and Setters Select me Choose those you want Remember it is not always desirable to have getters and setters – depends on what needs to remain private
18
Added Getters/Setters Depending on which are selected in the previous dialog, a series of getters and setters like this is generated
19
Other code generators Comment out (or uncomment) the selected lines 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
20
Renaming an attribute or method Use Refactor / Rename to change the name of a method or attribute of a class, a local variable, parameter, or even the name of a class. This changes the name everywhere it appears in the code.
21
If you refer to a class that is not in your own project or in any imported class, Eclipse puts a red squiggly line underneath the reference Which import do I need?
22
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
23
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
24
Running a program To run a program Right-click on (or in) the driver (code)
25
Another way to run the program … Click me
26
… from your workspace Submitting a project
27
Project Folder Contents in Workspace Contains.java files for your project Contains the compiled.class files
28
The bin folder This folder contains the compiled.class files. Do NOT submit them.
29
The src Folder.java files for the project Zip ONLY these files, naming the zipped folder appropriately. DO NOT zip 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.
30
Zipping the files Use Send To Compressed Folder or … … some other archiving tool such as 7-zip Select the files to be zipped and right-click
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.