Upload
cody-hancock
View
214
Download
0
Tags:
Embed Size (px)
Citation preview
1v1.6 08/02/2006
Module Road Map
1. Overview2. Installing and Running3. Building and Running Java Classes4. Refactoring5. Debugging6. Testing with JUnit
7. Version Control with Subversion Introduction Terminology Adding a repository to Eclipse
Workbench Sharing a project Checking out a project from repository Synchronizing with respository
Lecture 4
2v1.6 08/02/2006
The Problem of Version Control
Suppose two programmers are working on a project.
(See http://svnbook.red-bean.com/en/1.4/svn-book.html#svn.basic)
They edit the same file. Then they both save their changes.
What will happen? One approach: Programmer P1 locks the file,
then unlocks it when done. What is wrong with this?
3v1.6 08/02/2006
Subversion (SVN)
An open-source based version-control system Allows coordination of source code changes made by
individual developers working on a team Client-server method lets developers access code from
anywhere there’s an internet connection. Central server maintains history of all changes made to directory
trees, called repositories Client machines have a copy of all files that developers are working
on. The changes are then reported to the central server using a client
that can access and update repositories.
4v1.6 08/02/2006
Subversion — What it does
Subversion operations Checking out from a repository
Retrieves a directory from a Subversion repository to the Workbench on local machine
Sharing a resource Creates a copy of the resource on the Subversion repository
Synchronizing with a repository Update
Before you can commit changes, Subversion requires your sources to be in sync with any changes committed by other developers.
Commit To make the changes available to other developers, you must commit them
to the repository.
5v1.6 08/02/2006
Download Subversion
6v1.6 08/02/2006
Installing Subversion
I chose the latest stable version of Windows binary
7v1.6 08/02/2006
Unzipping Subversion
8v1.6 08/02/2006
Put Subversion in C:\Program Files
9v1.6 08/02/2006
Install Subversive, the Eclipse Client
10v1.6 08/02/2006
Installing Subversive
In Eclipse: Help > Software Upates > Find and Install
11v1.6 08/02/2006
Search for Features of New Plug-in
12v1.6 08/02/2006
Select New Remote Site
13v1.6 08/02/2006
Fill in the Dialog Box
On the New Update Site dialog enter the name of the update site and URL.
Use the following values:Name: Subversive URL: for Subversive 1.1.x: http://www.polarion.org/projects/subversive/download/1.1/update-site/
for Subversive 1.0.x: http://www.polarion.org/projects/subversive/download/update-site/
Click on the OK button to store update site information.
14v1.6 08/02/2006
Select Subversive
To start searching the update sites, select Subversive and click on the Finish button.
15v1.6 08/02/2006
Installing Subversive Features
You will then be asked to select the features to install.
It is safe to install all features. (If you want to save disk space, see the discussion at http://www.polarion.org/index.php?page=installation&project=subversive#notes
16v1.6 08/02/2006
License Agreement
Accept the terms of the license agreement.
17v1.6 08/02/2006
Install Features
Then install the features.
18v1.6 08/02/2006
Install Features, cont.
Install the feature, despite the warning.
19v1.6 08/02/2006
Restart for Safety
I suggest you restart Eclipse
20v1.6 08/02/2006
Configure Subversive
After installation, choose Help > Software Upgrades > Manage Configuration
21v1.6 08/02/2006
Select Subversive Team Provider
Click to open “Eclipse SDK”; then select SVN Team Provider.
22v1.6 08/02/2006
Connecting with Subversive
Select Window > Open perspective > Other
23v1.6 08/02/2006
Select “Subversion Repository Exploring”
24v1.6 08/02/2006
Click “New Repository Location”
25v1.6 08/02/2006
Select a Repository
Give the URL, user-ID, and password, then click “Finish”.
26v1.6 08/02/2006
Expand the Repository
Click on the name of the repository to expand it
27v1.6 08/02/2006
Check out the Project
Right-click on the name of the project to check it out.
28v1.6 08/02/2006
Project Checked Out
The project at the top of the pane was checked out.
29v1.6 08/02/2006
Modify a Class
30v1.6 08/02/2006
Committing Changes
Save the file, then right-click on the filename and choose Team > Commit
31v1.6 08/02/2006
Subversion » Conflicts
A conflict occurs when you have locally modified a resource for which a more recent revision is available
in the branch in the repository.
3 methods to resolve conflicts: Discard local copy by overwriting it with the newer
version on the repository. Overwrite the copy on the repository with the local copy.
Use extreme caution since you will be erasing changes made by others.
Merge your work and the repository resource, saving locally the merged resource.
32v1.6 08/02/2006
CVS » Conflicts
Conflict types: An auto-mergeable conflicting change occurs when an
source-code file has been changed both remotely and locally (i.e. has non-
committed local changes) but the changes are in different lines.
A non-auto-mergeable conflicting change occurs when one or more of the same lines of a source-code file have been
changed or when a binary file has been changed both remotely and locally.
Binary files are never auto-mergeable.
v1.6 08/02/2006
Introduction to NetBeans v 5.0
Integrated Development Environment
34v1.6 08/02/2006
Lecture Overview
NetBeans Overview Installing and Running NetBeans NetBeans Projects Building and Running Java Classes Building Running Web Applications Refactoring Applications
35v1.6 08/02/2006
Lecture Road Map
NetBeans Overview Introduction to NetBeans Features
NetBeans Projects Installing and Running NetBeans Building and Running Java Classes Building and Running Web Applications Refactoring Applications
36v1.6 08/02/2006
NetBeans Overview » Introduction to NetBeans A comprehensive, modular Java-based IDE (Integrated
Development Environment).
Free and open-source based. Open source since June 2000 Large community of users and developers
Provides a platform for building rich-client Java applications, Web applications, Web services etc.
Supports plug-in architecture. Large set of third-party modules (plug-in’s) are included in the downloadable version.
37v1.6 08/02/2006
NetBeans Overview »
Features
Ant-based project system Apache Ant is a Java-based build tool used to
standardize and automate build and run environments for development.
It is not necessary to know Ant to work with the IDE. See http://ant.apache.org/resources.html for more
information on Ant. Matisse GUI Builder - provides rich framework of
windows, menus, toolbars and actions. Plug-in (module) and rich client application
development wizard. CVS version control. Enhanced Refactoring.
38v1.6 08/02/2006
NetBeans Overview »
Features
Enterprise Development JBoss 4 and Weblogic 9 Support.
Developer Collaboration Discuss/share code with other developers remotely. Conduct code review using chat capabilities. Allow others to make changes which are then represented to the
rest of the group via visual cues. Send messages in plain text, XML, HTML, or Java code format.
Application Profiling CPU performance profiling Memory profiling and memory leak detection
39v1.6 08/02/2006
Lecture Road Map
NetBeans Overview Installing and Running
Where to get NetBeans? Installing NetBeans Running NetBeans
NetBeans Projects Building and Running Java Classes Building and Running Web Applications Refactoring Applications
40v1.6 08/02/2006
Installing and Running NetBeans »
Where to get NetBeans ?
http:// www.netbeans.org provides downloads, articles and tutorials related to NetBeans.
IDE can be downloaded from http://www.netbeans.info/downloads/index.php
41v1.6 08/02/2006
Installing and Running NetBeans »
Installing NetBeans NetBeans is available for Windows, MacOS, Linux and
Solaris operating systems.
Choose the NetBeans IDE 5.5.1 installer for the operating system that is installed on your development system.
For Windows operating system, download the IDE 5.5.1 installer ‘netbeans-5_5_1-windows.exe’.
Prior to NetBeans installation, make sure JVM (Java Virtual Machine) is installed. It is recommended that JDK 5.0 be downloaded from http://java.sun.com/j2se/1.5.0/download.jsp and installed.
Execute the NetBeans self-extracting installer to start NetBeans installation. Follow the install shield instructions.
42v1.6 08/02/2006
Installing and Running NetBeans »
Running NetBeans
On Windows XP, choose
Start » All Programs » NetBeans 5.0 » NetBeans IDE to launch NetBeans IDE.
43v1.6 08/02/2006
Lecture Road Map
NetBeans Overview Installing and Running NetBeans NetBeans Projects
About Projects Project Templates
Building and Running Java Applications Building and Running Web Applications Refactoring Applications
44v1.6 08/02/2006
NetBeans Projects »
About Projects A project is a group of source files and the settings with
which you build, run, and debug those source files.
The NetBeans IDE stores all of the information about a project in an Ant script, a properties file, and a few XML configuration files.
The IDE includes support for two types of projects: Standard Projects: The IDE uses a NetBeans-generated Ant build
script to build, run, clean, test, and debug your application. Free-form Projects: The IDE uses targets in an existing Ant script to
build, run, clean, test, and debug your application.
45v1.6 08/02/2006
NetBeans Projects »
Project Templates
The IDE includes several project templates designed to support different types of development including Web applications, general Java applications, and so forth.
Standard Templates: The IDE controls all source and classpath settings, compilation, running, and debugging. The IDE generates an Ant script in which all project settings are stored.
Standard Java Applications: Java Application, Java Class Library, Java Project with Existing Sources.
Web Applications: Web Application, Web Application with Existing Sources. Enterprise Applications: Enterprise Application, Enterprise Application with
Existing Sources. EJB Modules: EJB Module, EJB Module with Existing Sources NetBeans Plug-in Modules: Module Project, Module Suite Project, Library
Wrapper Module Project.
Free-Form Project Templates: The IDE relies on an existing Ant script for instructions on how to compile, run, and debug applications.
Java Project with Existing Ant Script: A free-form Java project. Web Project with Existing Ant Script: A free-form project containing a web
application. EJB Module with Existing Ant Script: A free-form project containing an
Enterprise JavaBeans module.
46v1.6 08/02/2006
Lecture Road Map
NetBeans Overview Installing and Running NetBeans NetBeans Projects Building and Running Java Applications
Setting up a Project Creating and Editing Java Source Code Compiling, Running and Debugging a Project Testing with JUnit
Building and Running Web Applications Refactoring Applications
47v1.6 08/02/2006
Java Applications »
Setting up a New Project From the main menu,
choose File » New Project.
This opens up the New Project window.
In Categories pane, select General.
In Projects pane, select Java Application and click Next.
48v1.6 08/02/2006
Java Applications »
Setting up a New Project
Enter the name of the project in the Project Name text box.
Choose a folder for the Project Location.
Ensure that Set as Main Project and Create Main Class checkboxes are checked.
Enter the fully qualified name of the main class (without the .java extension) in the text box adjacent to the Create Main Class checkbox.
The class name may be qualified with a package name and a dot (for example, mypackage.MainClass).
Click Finish.
49v1.6 08/02/2006
Java Applications »
Setting up a New Project The project will be
displayed in the Projects window.
The Java file that contains the skeleton code for the main class opens in the Source Editor.
Expand the project name (a.k.a. project node) in the Projects window to view the Java files that belong to the project.
50v1.6 08/02/2006
Java Applications »
Setting up a New Project
Click on the Files tab to view the project’s file structure in the Files window.
51v1.6 08/02/2006
Java Applications » Setting up a New Project » Project Properties
Right-click on the Project node in the Projects window.
This will open the Project Properties window.
In Categories pane, click on Libraries.
Click Manage Platforms button to specify a different JDK platform.
Compile-time and run-time class paths may be specified using the Compile tab and the Run tab respectively.
52v1.6 08/02/2006
Exercise 1
Create a New Java Application Project titled EgApp with a main class titled MainClass in a new package titled csc517.
53v1.6 08/02/2006
Lecture Road Map
NetBeans Overview Installing and Running NetBeans NetBeans Projects Building and Running Java Applications
Setting up a Project Creating and Editing Java Code Compiling, Running and Debugging a Project Testing with JUnit
Building and Running Web Applications Refactoring Applications
54v1.6 08/02/2006
Java Applications »
Creating and Editing Java code
In this module, you will learn how to Create a new class Navigate a Project node Add a new method to a class Create a new field to a class Use editing shortcuts
55v1.6 08/02/2006
Java Applications » Creating and Editing Java code »
Creating a new Java class
To create a new Java class, right-click on the project node in the Projects window and choose New » Java class.
The New Java Class window will be displayed.
Enter the name of the new Java class in the Class Name text box.
If the new class needs to be part of a package, type the name of a new package in the Package text box or choose an existing package from the drop-down list.
Click Finish.
The IDE generates the skeleton source code of the new Java class and opens it up in a new Java source window.
56v1.6 08/02/2006
Java Applications » Creating and Editing Java code »
Navigating the project node
In the Projects window, expand Source packages node under the Project node to view the package nodes and Java file nodes.
Expand the Java file node to view the classes defined in the Java file.
Double-click on the Java file to open the Java file in the Source editor.
Expand the class node to view the fields, constructors and methods of the class.
57v1.6 08/02/2006
Java Applications » Creating and Editing Java code »
Adding a new method to a class
Right-click on the Methods node of the class and click Add Method to create a new Java method.
This opens up the Add New Method window.
The Name, Return Type, Access, Modifiers and Parameters of the new method may be specified in the Add New Method window.
58v1.6 08/02/2006
Java Applications » Creating and Editing Java code »
Adding a new field to a class
Right-click on the Fields node of the class and click Add Field to add a new field.
This opens up the Add New Field window.
The Name, Type, Access, Modifiers and Initial Value of the field may be specified in the Add New Field window.
59v1.6 08/02/2006
Java Applications »
Creating and Editing Java Source
Editing Shortcuts:
Ctrl+Shift+F: Reformat the whole source code window.
Ctrl+Space: Code-completion box. (The IDE offers code completion for all classes and methods in the project's compilation classpath).
60v1.6 08/02/2006
Exercise 2 Create a new class titled NewClass and add it to the package csc517 in the
project EgApp you have created in Exercise 1.
Add a private integer field (member variable) mVar to the class NewClass.
Change the default constructor to accept integer parameter to initialize the private integer field mVar.
Add a public method printField that takes no parameters and returns void.
Add code to the printField method to print the value of the private variable mVar to standard output. (Hint: To use code-completion feature for the print routine, type “sys” and hit Ctrl-Space. The IDE pops-up the code completion box with a list of methods. Choose System.out.println() print routine).
61v1.6 08/02/2006
Lecture Road Map
NetBeans Overview Installing and Running NetBeans NetBeans Projects Refactoring Applications Building and Running Java Applications
Setting up a Project Creating and Editing Java Source Code Compiling, Running and Debugging a Project Testing with JUnit
Building and Running Web Applications
62v1.6 08/02/2006
Java Applications »
Compiling, Running and Debugging a project
In this module, you will learn how to Build a Java project Run a Java project Debug a Java project
63v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a Project » Building a Project
Choose Build » Build Main Project (F11) from the main menu to build (compile) a project.
Choose Build » Clean and Build Main Project (Shift+F11) from the main menu to clean and build a project
Alternatively, right-click on the project node in the project window and click Build Project or Clean and Build Project from the contextual menu.
The Output window displays the build results.
64v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a Project » Running a Project
Choose Run » Run Main Project (F6) from the main menu to run a project.
Alternatively, right-click on the project node in the Project window and click Run Project from the contextual menu.
The Output window displays the project output.
65v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a project » Debugging a project
To set a breakpoint, place the caret in any of the methods in the Java file and press Ctrl+F8.
The selected line will be highlighted indicating that the breakpoint has been set.
Choose Run » Debug Main Project (F5) from the main menu to debug the project.
The IDE runs the project in the debugger until the breakpoint is reached.
The IDE open the Debugger windows at the bottom of the IDE.
66v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a Project » Debugging a Project
To step over a line of code, choose Run » Step Over (F8) from the main menu.
To step into a method, choose Run » Step Into (F7) from the main menu.
To step out of a method, choose Run » Step Out (Ctrl + F7) from the main menu.
To terminate a debugging session, choose Run » Finish Debugger Session (Shift+F5).
67v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a Project » Debugging a Project »
The Local Variables, Watches, and Call Stack windows open by default with every debugging session.
You can open any debugger window by choosing Window » Debugging » window-name (for example, Window »
Debugging » Breakpoints).
Debugger Windows
68v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a Project » Debugging a Project »
Local Variables Window The Local Variables window lists
the local variables in the current call.
The information given for each variable includes the variable name, type, and value.
You can click the control to the left of the name to expand or collapse the variable.
Call Stack Window The Call Stack window lists the
sequence of calls made during execution of the current thread.
The information given for each call includes the name of the method, followed by the filename and line number of the call's currently executing statement.
Debugger Windows
69v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a Project » Debugging a Project »
Watches Window The Watches window lists all variables and
expressions that you have specified to watch while debugging.
The information given for each watch includes the variable or expression name, type, and value.
When you add a new variable or expression to the Watches window, the value of the variable or expression is immediately evaluated and displayed.
The value of a watch is based on the current context. As you move through your program code, the Watches window is updated to show the value of the watch for that context.
Creating a Watch: Select the variable or expression in the Source
Editor, right-click, and choose New Watch (Ctrl+Shift+F7).
The New Watch dialog box opens with the variable or expression entered in the text field. Click OK.
The Watches window opens with the new watch selected.
Debugger Windows
70v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a Project » Debugging a Project »
Classes Window The Classes window displays the hierarchy
of all classes that have been loaded into the virtual machine hosting the program that is being debugged.
You can click the turner control (+) to the left of the class name to expand or collapse the class.
You can inspect the fields, constructors, and methods in your program as well as inspect the value of static variables.
Breakpoints Window The Breakpoints window lists the
breakpoints set in the current project. By default, each entry contains a short text
description of the breakpoint and a boolean flag indicating whether the breakpoint is enabled or disabled.
Debugger Windows
71v1.6 08/02/2006
Java Applications » Compiling, Running and Debugging a Project » Debugging a Project »
Session Window The Sessions window lists the debugging
sessions currently running in the IDE. The information given for each session
includes the session name and state. One session is always considered the current
session, unless no sessions are running. By default, the current session is the session
that you most recently started.
Threads Window The Threads window lists all threads in the
current debugging session. For Java applications, this list also includes
the thread groups in the Java virtual machine.
The information given for each thread is the thread name and state.
Debugger Windows
72v1.6 08/02/2006
Exercise 3 In the project EgApp, based on the class NewClass that was created in
Exercise 2, instantiate an object of type NewClass in the main() routine of the MainClass.
Call the printField routine of the NewClass object. (Use the code-completion feature of the IDE.)
Build (compile) the project EgApp.
Run the project EgApp.
What do you see in the output window ?