Eclipse - SPLessons

Eclipse Exploring Java Package/Project in Depth

Home > Lesson > Chapter 5
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Eclipse Exploring Java Package/Project in Depth

Eclipse Exploring Java Package/Project in Depth

 

shape Introduction

This chapter demonstrates about Eclipse Exploring Java Package/Project in Depth. The Eclipse workspace contains one or more top-level projects, where each and every project maps to a respective client indicated directory in the file framework. Different tools are designed in to the Eclipse Platform which work on consistent files in the client's workspace. Each project in a workspace may guide to various file system directories or drives. By default, all projects guide to sibling sub directories of a solitary workspace directory. Following are the concepts covered.
  • Creating simple Java Project
  • Importing Java Sample Files
  • Java Project overview in Depth
  • Java Navigator View
  • Iconography

Creating simple Java Project

shape Description

A project nature system permits a tool to tag a project with a specific end goal to give it a specific identity. For instance, the site nature tags a project that contains the static content for a site and the Java nature tags a project that contains the source code for a Java program. Plugins may declare new project natures and give code to designing activities with that nature. A solitary project may have the same number of natures as required. This bears a path for tools to share a project without knowing about each other. Every project contains files which are made and controlled by the client. All files in the workspace are straightforwardly available to the standard programs and tools of the hidden working framework. Tools incorporated with the Platform are given with API to manage with workspace resources like the collective term for projects, files, and folders.

Creating a Java Hello word project

shape Description

There are multiple ways in order to start a new project in eclipse, if using Eclipse for the first time follow the procedure as shown. Method 1 Go to File menu -> select New -> select Project, as shown in the image below. Now, a popup window appears know as New Project providing some Wizards for project, select Java Project from those wizards and click Next button as shown in the image below. The window now redirects to another page providing some options like creating Project name, and option for selecting the workspace location, after performing all the required changes proceed by clicking Finish button as shown in the image below. Method 2 A New Java project can be created in another quick and easy way as follows. Hover on Project Explorer -> right click on empty space -> select New -> click Project as shown in the image below. Now, a popup window appears know as New Project providing some Wizards for project, select Java Project from those wizards and click Next button as shown in the image below. The window now redirects to another page providing some options like creating Project name, and option for selecting the workspace location, after performing all the required changes proceed by clicking Finish button as shown in the image below. Now the project is created in the Project explorer window as shown in the image below.

Creating a package and class

shape Description

In order to create a package for the created project navigate down on the project and select source file below the project directory and follow the procedure as shown. Click on the Created Project -> Select Src -> Right click and select New -> select Package as shown in the image below. Now, a popup window appears know as New Java Package providing some options like Source folder and Name, give preferred name for the package and proceed by clicking Finish button as shown in the image below. Now, right click on the created package in order to create a class and follow the procedure as shown. Select the Package -> Right click and select New -> select class as shown in the image below. Now, a popup window appears know as New Java Class providing some options like Source folder, Package and Name, give preferred name for the class and proceed by clicking Finish button as shown in the image below. And now a project with Source file, Package and Class is created as shown in the image below. Eclipse built with some plugins like user need not to type system out print line all the time in the code but can make use of some short cuts like type syso and hit Control+Space buttons in order to get the complete command line. Now, complete the code in Class file, save the file and run the code by using the default Run button, and the output can be viewed Console Window at the bottom as shown in the image below. This is how user can create a Java Project in Eclipse.

Importing Java Sample Files

shape Description

Importing Java file is quite easy task in Eclipse, in order to import some sample Java files first create a new project, user can also use default Tool bar option for creating a new project as shown in the image below. A popup window appears provided with some wizard’s select Java Project and click Next button as shown in the image below. Now select the created project, right click on the source file and Select Import Option as shown in the image below. A popup window appears provided with options for importing the files either by Archive Files or by File System, select the preferred mode of importing the files, proceed by clicking Next button as shown in the image below. Now, the window redirects to an another window providing some options for importing the files, select the Browse button locate the files in local drive, open the files to import. Proceed by clicking Finish button in order to import the files as shown in the image below. The imported files can be viewed under the Source file in the Project Explorer as shown in the image below.

Java Package/Project overview in Depth

shape Description

The Package Explorer in Eclipse have some standard things to do and have many features which are very helpful for users. In order to deal with Package Explorer open a project which contains some collection of files under source files which is actually a collection of packages as shown in the image below. In order link the files in Package Explorer with the editor select and open the files and click the button Link with Editor which sort of syncs the two views together, when the files are clicked in the editor window the selected files are highlighted in the Project Explorer navigation menu, the image below display a file highlighted when linked with editor. Now by selecting the other file in editor’s window only that file get highlighted as shown in the image below. When a bunch of things or files are opened in the Package explore can be minimized using the button known as Collapse All, the image below demonstrate the difference before and after effect of using Collapse All button. The files view can be changed to Hierarchical or Flat using the Drop Down Arrow, clicking the arrow will explore a window, select Package Presentation and select the option Flat or Hierarchical as shown in the image below. The image below display the difference between both the views I.e. Hierarchical and Flat.

shape Description

Eclipse have different menus for Project, Folder, Package and File. When compare to each other, menus have similar options but only a few options change. The following images display the menus for each level i.e. Project Level By right clicking on the Project in Package Explorer will explore the following menu as shown in the image below. Folder Level By right clicking on the Source files folder under the Project in Package Explorer will explore the following   menu as shown in the image below. Package Level By right clicking on the Package under the Source folder in package explorer will explore the following menu as shown in the image below. File Level By right clicking on the Files under the Packages in package menu will explore the following menu as shown in the image below.

Local History

shape Description

Local history is the main feature which is most preferred by many developers. Local History is a baked-in limited form of source code management. It's not a replacement for a full source code management, but it can come in handy in a pinch. It can automatically keep snapshots of the editing history. And again, it's available from varying levels, but it is typical to find and is most useful at the file level. In order to compare the previous and current edited history, make some changes to some selected file, save the changes and follow the procedure as mentioned. Right click on any file -> select Compare With option -> select Local History as shown in the image below. Now, a History view appears at the bottom of the window, on double clicking on the selected history date and time, will give a Compare window as shown in the image below. The history can be replaced with previous history by following procedure. Right click on the file -> select Replace With -> select Previous from Local History as shown in the image below. Now the modified date and time can be seen in the views at the bottom of the window as shown in the below image. In order to change the Local History settings follow the procedure as mentioned. Type Local history in Quick Access and select the General/Workspace as show in the image below. Now, a popup window appears providing some options for editing the history settings as shown in the image below.

Java Navigator View

shape Description

One view user to be aware of in the Java versions and can come in through Window, Show view, and there's a Navigator view. This view at first it looks like the Package Explorer, the Project Explorer, but it lets the user to get more files that are on the disk, so the settings files, it lets to see the bin directories, as well as the source, and it also lets user to have a quick look and see the .classpath and the .project data, which can even double-click and edit, although it is not recommend it unless but sometimes it can be useful and of course another way to get to it is through the Quick Access and can just go there and type nav, and can say Show View Navigator. The image below display the Navigator View. Now, the Navigator view appears on the left side of window as shown in the below image.

Iconography

shape Description

Icons are everywhere in Eclipse like Toolbar, Views etc. They are in the chrome for the views. If look over in Outline, user can see some icons. In order to see some icons open a file, and can find there are different icons over in the Outline view. Down at the bottom there are a lot more chrome and a lot more icons. Well, sometimes if user know what the icon means can quickly scan and find things to be looking for. Click the link below in order to check the icons list for Eclipse. http://help.eclipse.org/juno/index.jsp Now, in the page go to Java development user guide -> select Reference -> select Icons from Wizards and Dialogs, now some icons get displayed at the left side of the page as shown in the image below.

Summary

shape Points

  • Project can be created either by using File menu or by Right clicking on the empty space on the project explorer.
  • Importing can be done in eclipse using the import option provided in the file menu.
  • Each level i.e. project, package, file and source folder as different menus with few different options in Eclipse.