Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Development Environments AUBG, COS dept Lecture Title: Dev Env: Eclipse (Extract from Syllabus) Reference: www.eclipse.org.

Similar presentations


Presentation on theme: "1 Development Environments AUBG, COS dept Lecture Title: Dev Env: Eclipse (Extract from Syllabus) Reference: www.eclipse.org."— Presentation transcript:

1 1 Development Environments AUBG, COS dept Lecture Title: Dev Env: Eclipse (Extract from Syllabus) Reference: www.eclipse.org

2 2 Lecture Sources: §http://help.eclipse.org/kepler/index.jsp §http://agile.csc.ncsu.edu/SEMaterials/tutorials/eclipse/eclipse_tutorial_3.3.html §Laurie Williams, Dright Ho, Ben Smith and Sarah Heckman §CSC 326 - Software Engineering §Dept of COS, North Carolina State University

3 3 Lecture Contents: §Eclipse – introduction §Eclipse – functionality §Eclipse – configuration

4 4 Eclipse – introduction §.§.

5 5 §Eclipse is a multi-language software development environment comprising an integrated development environment (IDE) and an extensible plug-in system. It is written mostly in Java and can be used to develop applications in Java and, by means of various plug-ins, other programming languages including Ada, C, C++, COBOL, Perl, PHP, Python, R, Ruby, Scala, and Scheme. The IDE is often called l Eclipse ADT (Ada Development Toolkit) for Ada, l Eclipse CDT for C/C++, l Eclipse JDT for Java, l Eclipse PDT for PHP.

6 6 Eclipse – functionality §.§.

7 7 Eclipse – Basic terms §Project Eclipse creates Java application, using the Project concept – a folder to save all associated project files. §Workspace Eclipse stores projects in a folder, called a workspace. At starting time, user is asked to choose a concrete folder to be used as workspace for current session.

8 8 Eclipse – Basic terms §Workbench §Resource §Perspective §Editor §View

9 9 Eclipse – Basic terms §Workbench The term Workbench refers to the desktop development environment. Each Workbench window contains one or more perspectives. Perspectives contain views and editors and control what appears in certain menus and tool bars.

10 10 Sample workbench description §Displayed in a frame. Includes title, Menu bar, Icon tools bar, Collection of views and editors

11 11 Eclipse – Basic terms §Resource §Resources is a collective term for the projects, folders, and files that exist in the Workbench. The navigation views provide a hierarchical view of resources and allows you to open them for editing. §There are three basic types of resources that exist in the Workbench: §Files § §Folders § §Projects

12 12 Eclipse – Basic terms §Files Comparable to files as you see them in the file system.

13 13 Eclipse – Basic terms §Files Comparable to files as you see them in the file system. §Folders Comparable to directories on a file system. In the Workbench, folders are contained in projects or other folders. Folders can contain files and other folders.

14 14 Eclipse – Basic terms §Files Comparable to files as you see them in the file system. §Folders Comparable to directories on a file system. In the Workbench, folders are contained in projects or other folders. Folders can contain files and other folders. §Projects Contain folders and files. Projects are used for builds, sharing, and resource organization. Like folders, projects map to directories in the file system. (When you create a project, you specify a location for it in the file system.)

15 15 Eclipse – Basic terms §A project is either open or closed. §When a project is closed, it cannot be changed in the Workbench. The resources of a closed project will not appear in the Workbench, but the resources still reside on the local file system. Closed projects require less memory. Since they are not examined during builds, closing a project can improve build time. §When a project is open, the structure of the project can be changed and you will see the contents.

16 16 Eclipse – Basic terms §Resource hierarchies Resources are stored and displayed in the Workbench in hierarchies. Described below are the terms used when referring to resources that are stored and displayed in a hierarchical structure.

17 17 Eclipse – Basic terms §Resource hierarchies §Root l The top level of the Workbench contents (in the file system). §Parent resource l Any resource that contains another resource. Only projects and folders can be parent resources. §Child resource l Any resource that is contained within another resource. Only files and folders can be child resources. §Resource hierarchies are displayed in the Project Explorer view, which is one of the default views in the Resource perspective.

18 18 Eclipse §Project Explorer view §The Project Explorer view provides a hierarchical view of the resources in the Workbench. From here, you can open files for editing or select resources for operations such as exporting. §Right-click on any resource in the Project Explorer view to open a pop-up menu that allows you to perform operations such as copying, moving, creating new resources, comparing resources with each other, or performing team operations. To see a description of what each menu item does, move selection highlight to that menu item and press the context-sensitive help key (e.g., F1 on Microsoft Windows). §By default, the Project Explorer view is included in the Resources perspective. To add it to the current perspective, click Window > Show View > Other... > General > Project Explorer.

19 19 Eclipse – Basic terms §Perspective §Each Workbench window contains one or more perspectives. §A perspective defines the initial set and layout of views in the Workbench window. Within the window, each perspective shares the same set of editors.

20 20 Perspectives §Perspectives show all functionality associated with a large task, for example the Java Perspective is associated with creating a Java application, while the Debug perspective contains the views that you would use while debugging Java programs. § Each perspective has a default layout with views and editors appropriate for that task. If the views and editors are moved within a perspective, Eclipse will remember the new layout.

21 21 Workbench with Java perspective

22 22 Workbench with Resource perspective

23 23 Workbench with Java Browsing perspective

24 24 Workbench with Debug perspective

25 25 Perspectives §Opening a Perspective A perspective is opened by selecting Window > Open Perspective.. > Other.. for a complete list of perspectives, or the icon can be selected in the tab located in the upper right of the screen. In Eclipse there are 8 perspectives, but other perspectives may be listed when plug-ins are added. A description of the 8 perspectives are listed below:

26 26 Perspectives §5.1.1 CVS Repository Exploring : provides tools for the user to connect to and explore a CVS repository. §5.1.2 Debug : provides tools for the user to create breakpoints in code, and step through the code to view values of variables at a given point in time in order to debug mistakes in the code base. §5.1.3 Java : provides tools for the user to easily create and explore a Java project §5.1.4 Java Browsing : provides tools for the user to quickly move between Java projects, packages, types, and members of all Java projects open in the workbench. §5.1.5 Java Type Hierarchy : provides tools for the user to quickly view the Java type hierarchy of files in a Java project §5.1.6 Plug-in Development : provides tools for a user to create an Eclipse plug-in §5.1.7 Resource : provides general editing tools for the user to create a basic project. This is the default perspective. §5.1.8 Team Synchronizing : provides tools for teams to synchronize their code base through a CVS repository or other means.

27 27 Perspectives §Extra way to open a Perspective §You can use the General > Perspectives preference page to open perspectives in the same window or in a new window. How? Click Window > Preference > General > Perspectives

28 28 Perspectives §Views in a Perspective §Each perspective has a default layout of views that are most commonly used for the task that the perspective supports; however, each perspective has other views that may provide helpful functionality to the perspective.

29 29

30 30 Perspectives §Switching Between Perspectives §All perspectives that have been opened, remain easily accessible through the perspective tab at the upper right of the workbench. A user can change perspective by clicking on the icon associated with the perspective they wish to change too.

31 31 Perspectives §Closing Perspectives §To close a perspective, right click on the icon associated with the perspective that you wish to close and select Close from the context menu.

32 32 Editors and Views §Eclipse has two main components for displaying information about a project. §These are: § editors, and § views.

33 33 Editors §Editors are a way for a user to change information in a project. An editor may contain text or objects that can be changed and manipulated, but usually editors contain the code being developed during a project (such as.java files). A different editor may be opened depending on the file type selected. The editor or application that is opened when a file is selected can be modified in Window > Preferences > General > Editors > File Associations

34 34 Views §Views show a representation of a single task in the Eclipse environment. For example the Navigator view shows the hierarchal file structure of every project open in the Eclipse workbench, and allows a file to be opened. Any number of views can be opened in the workbench at one time. To open a view that is not displayed in the workbench select § Window > Show View.. > Other.. for a complete list of views.

35 35 Moving Editors and Views §Editors and Views can be moved around on the workbench to create a custom layout. To move an editor or a view, select the tab with the name of the file or view being moved. If you can add the file or view to a stack of files or views an icon is displayed. If you can move the file or view beside an editor or view a black arrow is shown with the new location of the file or view outlined in the workspace. A view may not be stacked in an editor location and an editor may not be stacked in a view location.

36 36 Starting Eclipse §:§:

37 37 Starting Eclipse §Eclipse creates applications exploring projects. §Eclipse stores projects in a folder called a workspace. §A dialog box opens asking user to choose a workspace folder to use for the current session.

38 38 Getting Started Using Eclipse §Source: §Eclipse Kepler, §Help >Welcome, §Start page, l Tutorials, Create a Hello World application

39 39

40 40 Create a Hello World application §It is a 5 steps process:

41 41 Create a Hello World application §Open the Java perspective: §In the main menu select §Window > Open Perspective > Java §Window > l Open Perspective > Java

42 42 Create a Hello World application §Create a Java project: §Before creating a class, we need a project to put it in. In the main toolbar, click on the New Java Project button. Enter HelloWorld for the project name, then click Finish.

43 43 Create a Hello World application §Create your HelloWorld class: §The next step is to create a new class. In the main toolbar again, click on the New Java Class button. If not already specified, select HelloWorld/src as the source folder. Enter HelloWorld for the class name, select the checkbox to create the main() method, then click Finish. §The Java editor will automatically open showing your new class.

44 44 Create a Hello World application §Add a print statement: §Now that you have your HelloWorld class, in the main() method, add the following statement: System.out.println("Hello world!"); §Then save your changes; the class will automatically compile upon saving.

45 45 Create a Hello World application §Run your Java application: §To run your application, right-click on your class in the Package Explorer and select Run As > Java Application. §The Console view should appear at the bottom and display the "Hello, world!" output.

46 46 More Details on Eclipse – functionality §.§.

47 47 Creating a Java Project There are four ways to create a Java project: 6.1.1 Select File > New > Project 6.1.2 Click the black arrow of the left most button of the Icons tool bar. Select Project, 6.1.3 Right click on the Package Explorer view in the Java Perspective, then click New and select Project. 6.1.4 Click the leftmost icon on the Icons tool bar.

48 48 Creating a Java Project 6.3 Give the project a name. If you would like to create src and bin folders for your source and class files respectively select the Create separate source and output folders radio button under the Project layout area of the New Java Project dialog. The default source folder is src/ and the default output folder is bin/. You can change these defaults by clicking on the Configure default... link. Click the Next button.

49 49 Creating a Java Project 6.4 The next screen has four tabs: Source, Projects, Libraries, Order and Export.

50 50 Creating a Java Project

51 51 Creating a Java Project 6.4.1 The Source tab sets the source and output folders for Java files and class files. 6.4.2 The Projects tab allows you to connect your new Java project to any other Java projects that are needed on the new Java project's build path. 6.4.3 The Libraries tab allows you to attach jar files of and Java libraries that you may need. 6.4.4 The Order and Export tab determines the build order and how a project can be exported. Make any changes needed here, and then click the Finish button. If you are not in the Java perspective, Eclipse will ask if you would like to switch to the Java perspective. The project will show up in the Package Explorer view.

52 52 Creating a Java Package There are four ways to create a Java Package. First, select the project you wish to create a package in. 7.1.1 Select File > New > Package, 7.1.2 Click the black arrow of the left most button of the Icons tool bar. Select Package, 7.1.3 Right click on the Package Explorer view in the Java Perspective, then click New and select Package, or 7.1.4 Click the leftmost icon on the Icons tool bar. 7.2 Check to make sure that you are creating the package in the proper project and source folder. Give the package a name. Click Finish.

53 53 Creating a Java Interface There are four ways to create a Java Interface. First, select the package you wish to create the interface in. 8.1.1 Select File > New > Interface 8.1.2 Click the black arrow of the left most button of the Icons tool bar. Select Interface, 8.1.3 Right click on a package in the Package Explorer view in the Java Perspective, and select Interface, or 8.1.4 Click on the arrow of the icon in the toolbar. Select Interface.

54 54 Creating a Java Interface 8.2 Check to make sure that you are creating the interface in the proper package. Give the interface a name. Use the Add button to add interfaces that the new interface needs to extend. You may also select if you want generated comments added to the interface. All generated comments are configurable under Window > Preferences > Java > Code Style > Code Templates. Click Finish. The new Interface will be open in the editor.

55 55 Creating a Java Class There are four ways to create a Java Class. First, select the package you wish to create the class in. 9.1.1 Select File > New > Class 9.1.2 Select the arrow of the button in the upper left of the toolbar. Select Class, 9.1.3 Right click on a package in the Package Explorer view in the Java Perspective, and select Class, 9.1.4 Click on the arrow of the icon in the toolbar. Select Class.

56 56 Creating a Java Class 9.2 Check to make sure that you are creating the Class in the proper package. Give the class a name. 9.2.1 Use the Browse button to search for a super class if your new class should inherit from another class. 9.2.2 Use the Add button to add interfaces the new class should extend. 9.2.3 Check the public static void main(String [] args) checkbox if the class you are creating starts the application. 9.2.4 Check the Inherit abstract methods checkbox if you would like to inherit abstract methods from a super class or interface. 9.3 Click Finish. The new class will be open in the editor.

57 57 History Eclipse maintains a history of changes made to all files open in the workbench. If you need to revert a file to a previous version, or you just wish to find a line of code that you deleted, you can look up the local history of the file. This history is only persistent for the life of the Eclipse session. To look up the local history of a specific file, right click on the file and select: Compare With > Local History.. or Replace With > Local Hi story.. depending on the operation you wish to do.

58 58 11.0 Running the Program There are several ways to run a program. 11.1 If the program has never been run before, you need to create run configuration for the program. 11.1.1 Select Run > Run.. 11.1.2 Click the arrow on the icon in the tool bar and select Run.. 11.1.3 Right click on the project you wish to run. Select Run > Java Application or Run > Run.. 11.2 Select Java Application, then click the New button at the bottom left of the screen. This creates a new run configuration. Give the setting a name. If the project is not specified, you can Browse for it. To find the main class in the project, select the Search button. 11.3 If there are any command line arguments, enter them in the Program arguments text box under the Arguments tab. 11.4 You can add jar files to the classpath under the Classpath tab. 11.5 Click Run to run the program.

59 59 11.0 Running the Program There are several ways to run a program. 11.6 If you have already created a run configuration, you can select the configuration by name by selecting the arrow on the icon in the tool bar. Just pressing the green button will run the last configuration launched by Eclipse.

60 60 12.0 Exercise Following computer science tradition, you will now write a simple HelloWorld application using Eclipse. We will call our application Greeter, and it will be able to say hello in several different languages. The diagram below describes the classes and their relationships in this example. Language Greeting German guten Morgen Spanish hola French bonjour Italian ciao For this exercise create a Greeter program that can say hello in three different languages. You can just print the hello statements to System.out.

61 61 Eclipse – configuration §.§.

62 62 Exercises/tasks §Write a Java Greeter program to display a greeting message in English, German, French, Spanish, Italian and your native language. §The output should look like: English: Good Morning/Good Afternoon German: Guten Tag French: Bonjour Spanish: Hola Italian: Ciao ……

63 63 Exercises/tasks §Build and run the Greeter project with different perspectives open: §Java §Java Browsing §Resource ……

64 64 Exercises/tasks §Write a Java CmdLnArguments program to display its command line arguments. l To set arguments click Run > Run Configuration, then select tab Arguments l To display command line arguments you have to display the contents of the array String[] args l Run the program with cmd line arguments and without cmd line arguments

65 65 Exercises/tasks §Close the Greeter project and the CmdLnArguments project §Click Project > Close project §Click project > Open project §Look at the contents of the Project explorer view or the Package explorer and register the differences in case of open project or closed project

66 66 Exercises/tasks §Remove the Greeter project from the Eclipse workspace. §Delete the project contents on disk.

67 67 Thank You For Your Attention!


Download ppt "1 Development Environments AUBG, COS dept Lecture Title: Dev Env: Eclipse (Extract from Syllabus) Reference: www.eclipse.org."

Similar presentations


Ads by Google