Difference between revisions of "Teams Winter 2011/team4/lab1"
(→Preparing Eclipse) |
Cwdesautels (talk | contribs) |
||
(22 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
=Lab 1= | =Lab 1= | ||
*[http://zenit.senecac.on.ca/wiki/index.php/Teams_Winter_2011/team4 Teampage] | *[http://zenit.senecac.on.ca/wiki/index.php/Teams_Winter_2011/team4 Teampage] | ||
− | |||
==Tutorial== | ==Tutorial== | ||
===Preparing Eclipse=== | ===Preparing Eclipse=== | ||
− | + | * First,begin by visiting [http://http://www.eclipse.org/downloads/ here] and choose Eclipse IDE for Java Developers (pay attention to 32bit and 64bit versions) | |
− | + | * Unzip the downloaded file int /Eclipse_Platform/Basics directory | |
− | + | * Start Eclipse by going into your newly created directory (/Eclipse_Platform/Basics/) and click the Eclipse executable | |
− | + | * There will be a dialog box that opens that requests the location of your workspace, enter the following: '''./wksp/{app type}''' where {app type} is something along the lines of 'lab', 'simple', 'hello', ect | |
===Creating your first Java project=== | ===Creating your first Java project=== | ||
+ | |||
+ | * Now that you have Eclipse open and have defined a workspace, click File->New->Java Project | ||
+ | * After doing so a window will popup requiring you to enter a name for your Java Project, enter any name appropriate to the work you will be doing | ||
+ | * Click the next button, followed by the finish button, and you have no created your first Java Project | ||
+ | |||
===Browsing Java elements using the package explorer=== | ===Browsing Java elements using the package explorer=== | ||
+ | |||
+ | * The package explorer allows one to explore the contents of various packages within their project | ||
+ | * By default, package explorer is open in eclipse on the far left of your screen (if it is not open, Navigate->Show In->Package Explorer will open it again) | ||
+ | * There will be a tree diagram in the Package Explorer, displaying your Java Project, packages, src folder, and all class, header files, ect | ||
+ | |||
===Editing Java elements=== | ===Editing Java elements=== | ||
+ | |||
+ | Editing Java elements is as easy as double clicking on a class, header file, or any other file that has text based data. Double clicking on the file will open a new window to edit the Java element. | ||
+ | |||
===Creating a Java class=== | ===Creating a Java class=== | ||
+ | *Select a package in the package explorer, right click: New->Class | ||
+ | *Give the class a meaningful name, click finish | ||
+ | *Note: At least one class that you make should have "public static void main(String [] args)" CHECKED | ||
+ | |||
===Renaming Java elements=== | ===Renaming Java elements=== | ||
+ | |||
+ | * First, locate the Java elements you want to rename in the Package Explorer | ||
+ | * Once you have located your file right click on the Java element, select Refactor->Rename and then choose the new name you want for the file | ||
+ | * Java actually renames all instances of the previous file name to the new file, which is pretty nice | ||
+ | |||
===Moving and copying Java elements=== | ===Moving and copying Java elements=== | ||
+ | |||
+ | * Moving Java elements can be done in various ways such as: | ||
+ | ** Right clicking the Java element, selecting Refactor->Move | ||
+ | ** Simply dragging and dropping the Java element | ||
+ | ** Selecting Refactor in the top menu and then selecting move | ||
+ | * You then choose the new destination of the file you are attempting to move/copy (you can also create a new location/folder if need be) | ||
+ | * Finish by selecting ok | ||
+ | * Copying and pasting is as simple as highlighting the desired text, hitting ctrl+c then pasting by pressing ctrl+v | ||
+ | |||
===Navigate to a Java element's declaration=== | ===Navigate to a Java element's declaration=== | ||
+ | |||
+ | * First, locate the element you want to view the declaration for | ||
+ | * Once located, right click on the elements name and select Open Declaration | ||
+ | |||
===Viewing the type Hierarchy=== | ===Viewing the type Hierarchy=== | ||
+ | |||
+ | To view the type hierarchy of any Java element by right clicking the file and selecting Open Type Hierarchy | ||
+ | |||
===Searching the workbench=== | ===Searching the workbench=== | ||
+ | |||
+ | To use Eclipses Search function, you can either go to the toolbar and select Search->Search and type your search there, or you can hit ctrl+f while you have a file open to search within that file, which is the preferred way to do it in my opinion | ||
+ | |||
===Running your programs=== | ===Running your programs=== | ||
+ | * Ensure that the *NOTE specified in class creation is adhered to: | ||
+ | ** public static void main(String [] args), Must exist in a class | ||
+ | * There are several ways to run your programs in eclipse including: | ||
+ | ** Clicking the run button in the toolbar | ||
+ | ** You can right click a java project or package and select run as (which gives numerous options in which to run your program) | ||
+ | ** And you can also use the keyboard shortcut Ctrl+F11 | ||
+ | |||
===Debugging your programs=== | ===Debugging your programs=== | ||
+ | * Select your Java project in the package explorer, right click: Debug As->Java Application | ||
+ | |||
===Evaluating expressions=== | ===Evaluating expressions=== | ||
+ | |||
+ | * Evaluating expressions requires you to be in Debug Perspective before doing anything | ||
+ | * Once in debug perspective, highlight the line in which you want to evaluate the expression for | ||
+ | * Then, in the toolbar, select Context->Inspect | ||
+ | |||
===Evaluating snippets=== | ===Evaluating snippets=== | ||
+ | |||
+ | * TO evaluate a snippet, we must first create a scrapbook page | ||
+ | ** This is done by File->New->Other->Java->Java Run/Debug->Scrapbook Page | ||
+ | * A window will pop up asking for both a folder and file name, enter these | ||
+ | * An editor will now pop up where you can enter your code snippets that you wish to have evaluated | ||
+ | * To view the results, right click on the snippet and select display | ||
+ | |||
===Using the Java browsing perspective=== | ===Using the Java browsing perspective=== | ||
+ | |||
+ | *Click on Window on the menu bar, Open perspective->Other | ||
+ | **Select Java browsing, Click OK | ||
+ | *These perspective is used to easily traverse through projects and edit code | ||
+ | |||
===Writing and running JUnit tests=== | ===Writing and running JUnit tests=== | ||
+ | *Select a package in the package explorer, right click: New->JUnit Test Case | ||
+ | **Give it a meaningful name, Click Finish | ||
+ | *Ensure your class "extends TestCase" | ||
+ | *Create functions within your class, JUnit will automatically call them if they adhere to the naming conventions: function name = "test" + x | ||
+ | **public void testEquivs() | ||
+ | *Select your Java project in the package explorer, right click: Debug As->JUnit Test |
Latest revision as of 16:14, 27 March 2011
Contents
- 1 Lab 1
- 1.1 Tutorial
- 1.1.1 Preparing Eclipse
- 1.1.2 Creating your first Java project
- 1.1.3 Browsing Java elements using the package explorer
- 1.1.4 Editing Java elements
- 1.1.5 Creating a Java class
- 1.1.6 Renaming Java elements
- 1.1.7 Moving and copying Java elements
- 1.1.8 Navigate to a Java element's declaration
- 1.1.9 Viewing the type Hierarchy
- 1.1.10 Searching the workbench
- 1.1.11 Running your programs
- 1.1.12 Debugging your programs
- 1.1.13 Evaluating expressions
- 1.1.14 Evaluating snippets
- 1.1.15 Using the Java browsing perspective
- 1.1.16 Writing and running JUnit tests
- 1.1 Tutorial
Lab 1
Tutorial
Preparing Eclipse
- First,begin by visiting here and choose Eclipse IDE for Java Developers (pay attention to 32bit and 64bit versions)
- Unzip the downloaded file int /Eclipse_Platform/Basics directory
- Start Eclipse by going into your newly created directory (/Eclipse_Platform/Basics/) and click the Eclipse executable
- There will be a dialog box that opens that requests the location of your workspace, enter the following: ./wksp/{app type} where {app type} is something along the lines of 'lab', 'simple', 'hello', ect
Creating your first Java project
- Now that you have Eclipse open and have defined a workspace, click File->New->Java Project
- After doing so a window will popup requiring you to enter a name for your Java Project, enter any name appropriate to the work you will be doing
- Click the next button, followed by the finish button, and you have no created your first Java Project
Browsing Java elements using the package explorer
- The package explorer allows one to explore the contents of various packages within their project
- By default, package explorer is open in eclipse on the far left of your screen (if it is not open, Navigate->Show In->Package Explorer will open it again)
- There will be a tree diagram in the Package Explorer, displaying your Java Project, packages, src folder, and all class, header files, ect
Editing Java elements
Editing Java elements is as easy as double clicking on a class, header file, or any other file that has text based data. Double clicking on the file will open a new window to edit the Java element.
Creating a Java class
- Select a package in the package explorer, right click: New->Class
- Give the class a meaningful name, click finish
- Note: At least one class that you make should have "public static void main(String [] args)" CHECKED
Renaming Java elements
- First, locate the Java elements you want to rename in the Package Explorer
- Once you have located your file right click on the Java element, select Refactor->Rename and then choose the new name you want for the file
- Java actually renames all instances of the previous file name to the new file, which is pretty nice
Moving and copying Java elements
- Moving Java elements can be done in various ways such as:
- Right clicking the Java element, selecting Refactor->Move
- Simply dragging and dropping the Java element
- Selecting Refactor in the top menu and then selecting move
- You then choose the new destination of the file you are attempting to move/copy (you can also create a new location/folder if need be)
- Finish by selecting ok
- Copying and pasting is as simple as highlighting the desired text, hitting ctrl+c then pasting by pressing ctrl+v
- First, locate the element you want to view the declaration for
- Once located, right click on the elements name and select Open Declaration
Viewing the type Hierarchy
To view the type hierarchy of any Java element by right clicking the file and selecting Open Type Hierarchy
Searching the workbench
To use Eclipses Search function, you can either go to the toolbar and select Search->Search and type your search there, or you can hit ctrl+f while you have a file open to search within that file, which is the preferred way to do it in my opinion
Running your programs
- Ensure that the *NOTE specified in class creation is adhered to:
- public static void main(String [] args), Must exist in a class
- There are several ways to run your programs in eclipse including:
- Clicking the run button in the toolbar
- You can right click a java project or package and select run as (which gives numerous options in which to run your program)
- And you can also use the keyboard shortcut Ctrl+F11
Debugging your programs
- Select your Java project in the package explorer, right click: Debug As->Java Application
Evaluating expressions
- Evaluating expressions requires you to be in Debug Perspective before doing anything
- Once in debug perspective, highlight the line in which you want to evaluate the expression for
- Then, in the toolbar, select Context->Inspect
Evaluating snippets
- TO evaluate a snippet, we must first create a scrapbook page
- This is done by File->New->Other->Java->Java Run/Debug->Scrapbook Page
- A window will pop up asking for both a folder and file name, enter these
- An editor will now pop up where you can enter your code snippets that you wish to have evaluated
- To view the results, right click on the snippet and select display
Using the Java browsing perspective
- Click on Window on the menu bar, Open perspective->Other
- Select Java browsing, Click OK
- These perspective is used to easily traverse through projects and edit code
Writing and running JUnit tests
- Select a package in the package explorer, right click: New->JUnit Test Case
- Give it a meaningful name, Click Finish
- Ensure your class "extends TestCase"
- Create functions within your class, JUnit will automatically call them if they adhere to the naming conventions: function name = "test" + x
- public void testEquivs()
- Select your Java project in the package explorer, right click: Debug As->JUnit Test