You are on page 1of 137

Introduction to Eclipse & NetBeans for

developing Java Applications

Confidential © 2008, Infosys


ER/CORP/CRS/ERJEEML800/003
Technologies Ltd.
Confidential Information

• This Document is confidential to Infosys Technologies Limited. This document contains information and data
that Infosys considers confidential and proprietary (“Confidential Information”).
• Confidential Information includes, but is not limited to, the following:
– Corporate and Infrastructure information about Infosys;
– Infosys’ project management and quality processes;
– Project experiences provided included as illustrative case studies.
– < Please list any/all other that is relevant>
• Any disclosure of Confidential Information to, or use of it by a third party, will be damaging to Infosys.
• Ownership of all Infosys Confidential Information, no matter in what media it resides, remains with Infosys.
• Confidential information in this document shall not be disclosed, duplicated or used – in whole or in part – for
any purpose other than _(Please insert as applicable)__ without specific written permission of an authorized
representative of Infosys.
• <Please include this point if applicable> This document also contains third party confidential and proprietary
information. Such third party information has been© Infosys
includedTechnologies Ltd.
by Infosys after receiving due written permissions
and authorizations from the party/ies. Such third party confidential and proprietary information shall not be
disclosed, duplicated or used – in whole or in part – for any purpose other than _(Please insert as
applicable)__ without specific written permission of an authorized representative of Infosys.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 2
anytime, anywhere!
Objectives
• To introduce different IDEs for Java project development
• To introduce usage of different tools in Eclipse and
NetBeans
• To introduce project creation wizards in Eclipse and
NetBeans
• To introduce Archive creation and unit testing using
Eclipse and NetBeans
• To introduce different plug-ins and their usages
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Introduction to Eclipse for developing Java
Applications

Confidential © 2008, Infosys


Technologies Ltd.
Part – I
IDEs for Java Project development
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
IDEs for Java Project development
• Many IDEs exists for developing java project
• Following is a brief list

IDE Name From Current Open Source


Version
Eclipse www.eclipse.org Galileo Yes

NetBeans www.netbeans.co NetBeans 6.7 Yes


m
Visual J++ Microsoft ©Visual J++
Infosys Technologies No
Ltd.
2.0
MyEclipse Genuitec MyEclipse 7.5 No

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Part – II
Introduction to Eclipse IDE workbench for developing
Java Applications
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Eclipse Workspace

Perspectiv
e Bar

Tasks
View

Text Editor

Marker Bar

Project
© Infosys Technologies Ltd. Explorer

Overview
Ruler

Problems
View

Fast View
bar
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Eclipse Workspace
• Workspace is a location on the underline OS whish
stores the projects, their resources and other information
about them
• Eclipse keeps a local change history of Eclipse
resources in workspace, this allows the developer to do
undo, redo operations on resources
• Switching between workspaces is possible by selecting
File-> Switch Workspace option
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Eclipse Perspective
• Perspective in Eclipse defines a set of Editors, and views
arranged in an initial layout for a particular task or role
• For e.g. debugging perspective is designed for the task
of debugging code, which comprises of different views
like breakpoint, variables, watch etc
• Eclipse has a set of predefined perspectives, one among
them can be selected by accessing perspective bar

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Eclipse Views
• A view in the Eclipse presents a way to the developer to
navigate through resources or other information in
Eclipse
• Views are usually used to access resources easily or to
make the changes
• For e.g. using outline view shows the structure of the
Java file in Java Perspective, i.e. Variables, function,
blocks etc
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Eclipse Views ..2

Outline
View

Task List

Detached
Problems
View

© Infosys Technologies Ltd.

View stack

Fast view
bar

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Part – III
Project Creation Wizard
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Projects
• Developer can create different types of Java projects in
Eclipse
• The support for creating specific type of the project
depends on the version of Eclipse
• The type of the project to be created also depends on the
software's / plug-ins installed
• Following is the list of some of Java flavor projects that
can be created using Eclipse Ganymede
– Simple Java Project © Infosys Technologies Ltd.
– Static and Dynamic web Projects
– Enterprise Java Projects
– EJB Project

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Java Project ..1
• To create the Java project follow the steps :
1. From the menu, select File-> New->Project
2. You will see a new project wizard
3. Expand the Java category, click on Java Project and
then click on Next button
4. Provide appropriate name to the project
5. Developer may configure the other options viz, JRE
version, project layout©and
Infosysthen click
Technologies Ltd. on Next

6. Accept the default setting and click on finish.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Java Project ..2
Step 3 : Accept the
other default settings
Step 1 : Select Step 2 : Specify
Java Project the name for
type Java Project

© Infosys Technologies Ltd.

Step 4 : Project is
ready.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating a Java Class ..1
• Creating a Java Class
1. Select the project in the project explorer or package
explorer
2. Select File->New->Class or right click the project in
project explorer and select New->class
3. A dialog box for New Java Class will appear, select
the source folder and provide the package name
4. In the next text box provide the name for Java class,
© Infosys Technologies Ltd.
select the modifier radio button
5. Optionally select he super class and interfaces for
the new class and click on the finish button

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating a Java Class ..2

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Dynamic Web Project
• To create the dynamic web project follow the below steps :
1. From the menu, select File-> New->Project
2. You will see a new project wizard, expand the web
category and then select Dynamic web project and Click
on Next button
3. In the next step, give the appropriate name to the project
and select the target runtime to deploy and run the
project. Accept other default settings and click on next
4. In the next step once again accept
© Infosys theLtd.
Technologies default setting and
click on finish button.
5. The dynamic web project is created and is ready to add
another files.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Dynamic Web Project ..2
Step 2 : Give the name for
the project and select target
Step 1 : Select Web-> runtime
Dynamic web
Project type
Step 3 : Accept the default
setting and click on finish

© Infosys Technologies Ltd.

Step 4 : The project is ready


and new files can be added

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating EJB Project
• EJB is the server side business tier component
• Eclipse helps to create EJB components for all of its
versions including EJB 1.0, 2.x and 3.0
• To create the EJB component start creating the EJB
Project
1. Select file->New->Other->EJB ->EJB Project, a new wizard to
create the EJB Project will start
2. Provide appropriate name for the project, select the run time on
which EJBs should be deployed
© Infosysand selectLtd.
Technologies the version of the
EJB to be developed.
3. Accept the default configuration and click on Next button
4. In the next step give the source folder name or accept the
default one and click on Finish

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating EJB Project ..2

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Session Bean ..2

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Session Bean ..1
• To create the session bean, you must have EJB project
created, following steps explains how to create it
– Select the EJB project in the Project explorer, and
select File->New->Session Bean
– A Session bean creation wizard will start, accept the
default EJB Project and source folder. Provide the
Java package name and class name
– From the next drop-down select the type of session
© Infosys Technologies Ltd.
bean as Stateless (other option Stateful), make this
bean as a local bean by checking Local check box
and then click on Next button
– In the next step of wizard accept all the defaults and
click on Finish
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Session Bean ..2

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Part- IV
Creating Archives

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Archive Creation
• Archive files are meant for building group of classes and
associated resources together.
• Following are the types of archives
– Java Archive (JAR): For Java projects
– Web Archive (WAR) :For Web projects
– Enterprise Archive (EAR) : For Enterprise projects

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating JAR
• Java archives are created for Java projects
• Following are the steps to create JAR for Java project
– In Project or Package view, right click on the project node
– Select the menu option Export, a dialog box will appear
– In the dialog box select JAR file option and click on Next
– In the next dialog accept the defaults for resources to
export and check “Export generated class files and
resources”
– Check other check boxes ©based
Infosys Technologies Ltd.
on resources to export
– Select the Export Destination and click on Next button
– Accept the default settings in current dialog and click on
Finish button

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating WAR

• Web archives represent archived Java Web project


• The war file for these web project can be deployed on web or
application server
• To create the war file follow the steps
– In Project or Package view, right click on the project node
of the web project
– Select the menu option Export WAR File, a dialog box will
appear
– Accept the default name of© Infosys
the war file and in next text box
Technologies Ltd.
select the destination file
– Select the target run time if you want to optimize for a
specific server
– Accept other default settings and click on Finish button

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating EAR
• Enterprise Archive represents an archived enterprise
project
• EAR may contain other WAR or JAR files
• As in case of WAR file, EAR file can be deployed on
application server
• Follow the steps to create EAR
– Right click on the node for enterprise project and
select the export menu option
– Select EAR File © Infosys Technologies Ltd.

– In the next dialog, give the name and destination for


the EAR file
– Accept the default settings and click on Finish button.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Part- V
Unit Testing
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
JUnit Testing- Test Case ..1
• Eclipse support both Junit 3 and Junit 4
• Following steps illustrate Junit -3
1 Select File->New -> Junit TestCase
2 Select Junit 3 test and enter the name of class as
“TestAreaCalculation”
3 Select class under test as “AreaCalculation” and
click on Next button
4 Select the methods to be unit tested
5 Click on Finish to create test
© Infosys classLtd.
Technologies

6 You will get a warning message asking you to add


the junit library to the build path, click on OK
button.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
JUnit Testing- Test Case ..2

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Running JUnit Test Class ..1
• Following steps illustrates how to run test class
– Enable Junit view by selecting Window->Show View->
Junit
– Right click on the TestAreaCalculation class in the
project explorer, select Run As->Junit Test
– The Junit view shows the list of test cases executed.

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Running JUnit Test Class ..2

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
JUnit Testing- Test Suite
• Junit test suite wizard helps you to create a test suite
• Test suite is the collection of one or more TestCases
– Select New->Junit-> Junit Test Suite and click on next
– Select the source folder containing the test case
classes
– Check the classes to be included in the test suite and
click on Finish button
• To run the test suite, follow©the
Infosyssteps similar
Technologies Ltd. to that of
running one test case

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Part- V
Eclipse Plugins
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Extending Eclipse
• Eclipse is a collection of loosely bound but
interconnected pieces of code
• Each such functional unit is called as plug-in
• These plug-ins are type of Java programs which can be
developed or are available at open source community
• These plug-ins can be downloaded from the following
site : http://www.eclipseplugincentral.com/
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Eclipse Plug-in
• To see the list of installed plug-ins select, window->show
View-> PDE Runtile-> Plug-in registry
• In the plug-in view, one can perform different operations
by right clicking on the plug-in
– Start
– Stop
– Disable
– Diagnose
• A new plug-in can be installed byTechnologies
© Infosys copying Ltd. plug-in JAR in

plugin directory
• This directory can be located in Eclipse installation home
directory

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Eclipse Ant
• Ant is an open source tool from Apache
• Ant enables to automate the build process – i.e.
operations viz. compile, move, copy and delete
• By default Ant understands the build.xml file
• To run different commands in the this build file
1. Right click build.xml in package explorer or project
explorer
2. Choose Run as-> Ant build, a separate dialog will
open © Infosys Technologies Ltd.

3. In the target’s tab choose the target to execute by


checking the required targets
4. then by clicking Run button

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Run build.xml file

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Selecting targets

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Using different build file

• Ant by default understands the build.xml file


• To specify different file select window-> Preferences->ant
and enter the name(s) of your build file(s)

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Debugging in Eclipse

• To start the debugging session, follow any one of the


following steps
– Run-> Debug History
– Run-> Debug
– Run->Debug As-> Java Application
• When an application will start in debug mode, eclipse
opens debug perspective
© Infosys Technologies Ltd.
• Debug perspective can also be enabled by clicking debug
perspective button on perspective bar

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Debug Perspective

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Debug operations
• Setting a Breakpoint
– Double-click the marker bar next to the line of executable
code to which you want to add a break point
– Alternatively, highlight the line and select Run->Toggle
BreakPoint
• Step Into (short key- F 5)
– Steps into selected statement, if the statement is the
method, execution continues from inside the method
• Step Over (short key- F 6)
– Steps over the selected statement, if the statement is a
method does not step into©method
Infosys Technologies Ltd.

• Step Return (short key- F7)


– Executes until the end of the current method and then
returns. Stop after method returns or when a breakpoint
occurs

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Part- V
Java Development Tools
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Overriding Java Method
• Developer can override the method in source code
• Also she can see which method being overridden
• To override the method select source-> Override /
Implements methods
• Check the methods to override /implement and click OK

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating getter/setter methods

• Consider a class having


number of fields, and you
want to generate
getter/setter methods them
• In the source code select
Source->Generate Getters
and setters
© Infosys Technologies Ltd.
• Alternatively right click and
select Source->Generate
getters and Setters

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Delegate Methods
• Delegate methods can be
generated for all the fields
except for primitive type fields
• To generate delegate methods,
select Source->Generate
Delegate methods
• Alternatively right click in the
editor and select Source-
>Generate Delegate Methods© Infosys Technologies Ltd.
• In generate delegate method
dialog box select the methods
to delegates for

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Surround code with do/for/if/try/while blocks
• If you want to surround the code with try/catch block or
do/for/if/while construct
• Then highlight the lines to surround, right click and select
Surrounds with->[construct to surround]

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Creating Constructor
• To add a constructor which will assign values to one or
more fields to the class right click in editor and select
Source->Generate Constructor using fields
• To add the constructor including call to super class
constructor right click in the editor select Source-
>Generate Constructor from super class

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Profiling in Eclipse
• The Eclipse Test & Performance Tools Platform (TPTP)
project provides a flexible and extensible framework for
profiling
• This plug-in can be used for profiling Eclipse plug-ins,
local Java applications or complex web applications
running on multiple hosts and different platforms
• To use the profiling tool in eclipse, enable the
profiling/logging perspective by selecting Window->Open
Perspective->Profiling and ©Logging
Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Profiling and Logging Perspective

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Profiling Configuration ..1
• To configure the Profiling toll follow the steps
– Right click the project to be profiled in the navigator
view and select Profile As->Profile Configurations; a
dialog window will appear
– If you want to profile the Java application, then select
the file for which profiling configuration is to be done
– For profiling the Java application on local machine
following profiling options can be enabled
© Infosys Technologies Ltd.
• Execution Time Analysis
• Memory Analysis
• Thread Analysis
• Probe Insertion
– Select the appropriate configuration and click on
profile button.
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential
– The application is profiled and the data be viewed anytime, anywhere!
Profiling Configuration ..2

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Execution Time Analysis

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Working with VSS from Eclipse
• Keeping track of version of individual or team project is
easy with eclipse using VSS plug-in for Eclipse
• One or more projects can be mounted to VSS database
in Eclipse using VSS plug-in
• To mount different VSS database one need to have
separate Eclipse projects
• Following steps can be followed to work with VSS
– Configure VSS for a Eclipse project
© Infosys Technologies Ltd.
– Perform different operations viz, check-in, check-out,
delete, refresh etc on different resources in your
project
– Deconfigure VSS once job is done

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Configuring VSS
• To configure the VSS right click on the project in the
package explorer, click on Team->Share Project
• A wizard for configuring VSS will be open
• Enter the details about the VSS viz location, username,
password etc and click on Finish

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Check-in / Check-out operations ..1
• Right click on the project resource in the Package
explorer, select Team->Add to VSS to check-in the
resource in the VSS
• Right click on the project resource in the Package
explorer, select Team->Check-out to check-out the
resource from the VSS

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Check-in / Check-out operations ..2

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
Summery – Eclipse Tools
• Following is the list of tools available with Eclipse
Ganymede.
– Project Creation (Java, Web, Enterprise)
– Ant, Maven,
– Unit Testing using JUnit
– Profiling
– Debugging
– Versioning and Archiving using
© Infosys VSS Ltd.
Technologies

– Plug-in development and deployment

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential
anytime, anywhere!
© Infosys Technologies Ltd.

NetBeans IDE -6.7.1


We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 63
anytime, anywhere!
Course Objectives
• Introduction
• Different Project creation (Java, Web, Enterprise)
• Tool Usage (Ant, CVS, Refractor)
• Debugging
• Services(Database, Servers)
• Archive Creation (JAR, WAR, EAR)
• Unit testing support
© Infosys Technologies Ltd.
• Plug-ins
• Profiling

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 64
anytime, anywhere!
© Infosys Technologies Ltd.

Introduction…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 65
anytime, anywhere!
Introduction
• Netbeans Integrated Development Environment is an
Open source tool from Sun Microsystems.
• It is built using Java Programming Language.
• It has lot of features that increases productivity.
• It is the first IDE that supports the complete Java 6.0
features.
• Netbeans IDE supports various Kinds(JSE, JME, JEE,
Ruby, etc) of applications development.
© Infosys Technologies Ltd.
• Netbeans IDE is built on open standards which makes
the application development process portable.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 66
anytime, anywhere!
NetBeans IDE

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 67
anytime, anywhere!
Netbeans and Web connectivity
• Netbeans IDE is built in modular fashion.
• Its modules are automatically upgradable over internet
connection.
• For connectivity the IDE uses the system’s proxy
settings.
• The proxy can also be set manually by selecting Tools 
Options  General  Manual Proxy Settings
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 68
anytime, anywhere!
© Infosys Technologies Ltd.

Project creation…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 69
anytime, anywhere!
Creating a simple Java Application
• Java Application can be created in few steps.
• Steps involved are
– Select File  New Project
– In the wizard that opens, select Java from categories
and Java Application from Projects and select Next.
– It the wizard that opens, provide the project details
such as Project Name, Location, Project Folder Name
and specify the main class details.
© Infosys Technologies Ltd.
• For Example: let the Main class be
com.infosys.calculator. CalculatorDemo. Where
CalculatorDemo represents the class name and
com.infosys.calculator represents package
– Click on Finish
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 70
anytime, anywhere!
Project Window

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 71
anytime, anywhere!
Source Editor

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 72
anytime, anywhere!
Files Window

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 73
anytime, anywhere!
Project and Ant Scripts
• When the project is created the IDE will add the Ant
Script for compiling the project, Running the project,
debugging, creating archives and testing.
• When the required command is fired(compile)
appropriate Ant script will get executed and the output
will be shown in the Output Window.

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 74
anytime, anywhere!
Compiling and Running the project
• Compilation
– Press F11 or Select Run  Build Main Project
• Execution
– Press F8 or Select Run  Run Main Project

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 75
anytime, anywhere!
Creating a simple web application
• Select File  New Project
• Select Java Web from Categories and Web Application
from projects and select Next
• Project the Project Name and Location details and select
Next
• Select the Server to be used, Java EE version and the
context root to access the application and click on Next
• Select the Framework if it needs to be used in the web
© Infosys Technologies Ltd.
application and provide the framework specific details.
• Select Finish.
• This creates a Web application

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 76
anytime, anywhere!
Project View – Web application

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 77
anytime, anywhere!
Files View – Web application

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 78
anytime, anywhere!
Creating an EJB module and a Bean..
• Select File  New Project
• Select Java EE  EJB Module and select Next
• Project the Project Name and Location details and select
Next
• Select the Server to be used, Java EE version and click
on Finish
• This will create an EJB Module.
• Right click source packages, select
© Infosys NewLtd.<<Type of
Technologies
Bean>>
• Provide the required details
• Click on Finish.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 79
anytime, anywhere!
Creating an Enterprise application
• Select File  New Project
• Select Java EE  Enterprise Application
• Prove the project name and location details and click on
Next.
• Select the server to be used, Java EE version to be
used and modules (Web module, EJB module,
Application client module)
• Click on Finish. © Infosys Technologies Ltd.
• This will create an enterprise application

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 80
anytime, anywhere!
© Infosys Technologies Ltd.

Tool Usage(Refactor, ANT, CVS)…


We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 81
anytime, anywhere!
© Infosys Technologies Ltd.

Refactor…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 82
anytime, anywhere!
Refactoring
• It is the process of changing the structure of the code so
that the code becomes easy to read and understand.
• Refactoring does not change the functionality of the
code.
• To Refactor
– Right click on the class in the source editor
– Select the required sub menu.
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 83
anytime, anywhere!
Refactoring Commands

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 84
anytime, anywhere!
Refactoring commands [Contd..]
Commands Purpose
Rename This helps in providing new name to class, variable or
method and the same will be reflected at all the required
places in the project.
Copy Creates a copy of the class
Safely Delete This will delete a class if it is not having any references. If
there are references it will show the references to fix and
delete.
Change Method This helps in changing method arguments and access
Parameters modifiers and change same will be reflected at all the
© Infosys Technologies Ltd.
required places in the project. Example: If the order of the
arguments are changed, the input values in the method
call in the calling method will also change.
Pull Up This helps in moving method definition of a class to its
super class or method declaration to the super interface

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 85
anytime, anywhere!
Refactoring commands [Contd..]
Commands Purpose
Push Down Reverse of Pull up
Extract Interface Creates a Super Interface for a class.
Extract Super Create a super class for c class
Class
User Supertype This helps in making the instance of the class referenced
Where Possible by super type reference
Move Inner to Moves and inner class one level up.
Outer Level
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 86
anytime, anywhere!
Refactoring commands [Contd..]
Commands Purpose
Introduce Variable Introduce an expression as a variable
Introduce Method Encapsulate statements in a method
Encapsulate Fields Generates getter and setter methods for a field
Undo To undo the changes made by Refactor command
Redo To Redo the Refactor command

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 87
anytime, anywhere!
© Infosys Technologies Ltd.

ANT…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 88
anytime, anywhere!
Build scripts
• For all the IDE generated projects the build scripts will be
in build.xml and build-impl.xml.
• The build.xml is the master file. This imports the build
scripts from build-impl.xml
• The build scripts are defined as targets
• The targets corresponds to IDE operations such as
compilation, running etc.
• The build file has a simple ©structure with root project tag
Infosys Technologies Ltd.
with set of target tags. Each target tag depends on other
target tags.
• When a target tag is executed, it executes all the targets
that the target depends first and then the target.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 89
anytime, anywhere!
build-impl.xml and build.xml

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 90
anytime, anywhere!
build-impl.xml (targets)

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 91
anytime, anywhere!
Customizing the build file
• If any custom targets have to be added then it has to be
added in the build.xml(recommended).
• If there is a duplicate the version available in build.xml
takes precedence over buil-impl.xml

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 92
anytime, anywhere!
Adding and Running Ant Scripts
• Create a new Java Project with a main class
• Open Files Window and select build.xml
• Open it in the source editor
• Add the required target after import statement
• Observe the target added in build.xml
• Right click on it and Select Run Target

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 93
anytime, anywhere!
© Infosys Technologies Ltd.

CVS…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 94
anytime, anywhere!
CVS(Concurrent Versions System)
• It is a version control system.
• In a collaborative software development environment
CVS helps in keeping track of changes, conflicts etc in
the project files.

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 95
anytime, anywhere!
CVS Connection Methods
Method Description
pserver This connects to repository on a remote server
ext This connects to repository on a remote server
using SSH (Secure Shell)
Local This connects to local repository

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 96
anytime, anywhere!
Adding the project to repository
• Right click on the project in the project window select
Versioning  Import into CVS repository
• Select the appropriate root and provide the details
according to the root and click on next
• In the folder to import window provide the folder to be
imported details and Repository details and select finish
• This will add the project files to the repository.
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 97
anytime, anywhere!
Tasks that can be done on a CVS project
• Color encodings in the margin of the source file editor
instructing the change in the code compared to the earlier
version
• Badges and Color coding to indentify the modifications,
additions, deletions, conflicting versions, etc
• The same information can be provided in the textual format
by File Status Labels
• Listing all the changes made to the source file
© Infosys Technologies Ltd.
• Committing the changes to the repository
• Excluding some files from commit
• Comparing the file in the local directory and repository
• Tags for Roll back changes
• Branching of repository to have parallel activities. We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 98
anytime, anywhere!
© Infosys Technologies Ltd.

Debugging…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 99
anytime, anywhere!
Debugging
• It is the process of identifying the problems in the
application.
• Debugging console and Debugging Windows:
– While debugging the application the status of the
debugging program will be displayed in the debugging
console. This will be displayed in the lower window.
– In addition to provide various specific debugging
details. For example: Variables window shows the
© Infosys Technologies Ltd.
values of all the local variables and fields.
– To open Debugging window select Window 
Debugging  Respective window.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 100
anytime, anywhere!
Debugging Windows

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 101
anytime, anywhere!
Debugging Commands

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 102
anytime, anywhere!
Debugging Commands
Commands Purpose
Debug Main Project Executed the project till the first break point is
encounters and it will display the status
Step Into This will execute single line of code. If the line of
code is a method call, the control will be transferred
to the first line of the method, which can be
executed on another step into command.
Step Over This will execute single line of code. If the line of
code is a method call, this will result in the
execution of the method.
© Infosys Technologies Ltd.
Finish Debugger Stop the current debugger session
Session
Continue Continue program execution until the next
breakpoint is reached

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 103
anytime, anywhere!
Breakpoint
• By introducing break points we can stop the application
execution at a particular point.
• Break point at a line can be set by clicking at the left
margin of that line.
• Conditional Breakpoints:
– Conditional break points stop execution when some
conditions are true.
– This can be set by selecting Debug  New
© Infosys Technologies Ltd.
Breakpoint
• Types of Break points:
– Class, Exception, method, thread, field, line

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 104
anytime, anywhere!
© Infosys Technologies Ltd.

Services(Databases and Servers)…


We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 105
anytime, anywhere!
Services Window

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 106
anytime, anywhere!
Databases
• NetBeans IDE6.7.1 can work with any database server
provided there is a JDBC driver.
• While installing IDE the default data base server Derby
Database server is also configured. Whenever the
glassfish server starts up it will also run.
• Other Database servers can also be installed with the
IDE.
• Using Derby Database Server:
© Infosys Technologies Ltd.
– Open Services window
– Select Java DB
– Right Click on it and Start Server
• Then new Database and Tables can be created.
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 107
anytime, anywhere!
Setting connections to a Database Server
(HSQLDB)
• Select Services window
• Right click data bases and select New Connection.
• Drop down then Name Dropdown and select New Driver
option
• Provide HSQLDB Driver details and select ok
• Provide the connection details and select ok
• This will open a new connection with the Database.
• On the connection SQL statements canLtd.
© Infosys Technologies be fired using
Execute Command.
• The connection can be disconnected by selecting
Disconnect.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 108
anytime, anywhere!
Servers

• NetBeans IDE installation comes with GlassFish Server


• GlassFish is an Application Server, which can be used
for developing J2EE application.
• The IDE provides support for starting the server, Un
deploying applications , starting server admin console
etc.
• New Servers can also be added to the IDE.
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 109
anytime, anywhere!
Adding Servers to IDE
• Select Services window
• Right click Server  Add Server
• Select Tomcat 6 and Select Next
• Provide the installation folder details.
• Click on Finish.
• This will add the server. Right click on the server and
start the server.
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 110
anytime, anywhere!
© Infosys Technologies Ltd.

Achieves…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 111
anytime, anywhere!
JAR – Java Archive Files
• These files are meant for bundling group of classes and
the associated resources together.
• Bundling JARs helps in
– Downloading group of classes in a single shot
– Porting application as a single file
– Creating extension libraries
– Signing for Security
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 112
anytime, anywhere!
JAR File Structure (For a sample Java
Application)
• META-INF
– MANIFEST.MF
• Discount
– DiscountCalculator.class
– Main.class
– PriceCalculator.class

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 113
anytime, anywhere!
Types of Archives
• JAR – Java Archive Files
• WAR – Web application Archive Files
• EAR – Enterprise Archive Files

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 114
anytime, anywhere!
Creation of JAR files
• In Net Beans IDE the JAR files are created automatically
on cleaning and building an application.
• The same will be available in the dist folder of the
application

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 115
anytime, anywhere!
© Infosys Technologies Ltd.

Unit testing…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 116
anytime, anywhere!
Unit Testing in NetBeans IDE
• Using NetBeans IDE, JUnit tests can be performed in a
simplified way.
• NetBeans IDE 6.7.1 supports JUnit versions 3.x and 4.x
• IDE support
– Creating and Running JUnit Tests
– Creating and Running JUnit Test Suites

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 117
anytime, anywhere!
Creating and Running JUnit Tests
Creation
• Create the required class to be tested.
• In the project window, select the class, right click on it
and select Tools and Create JUnit Tests.
• Select the JUnit version to be used.
• Provide the Test Class Name. Click on “Ok”.
• It will generate the test class.
• Add/Modify the required tests.
© Infosys Technologies Ltd.

Running Tests
• Right Click on the Test Class and Select Test File.
• Observe the test results in the Test Result Window.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 118
anytime, anywhere!
Test Result Window

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 119
anytime, anywhere!
Creating and Running Test Suites for
Application
Creation
• Right Click the project, Select New, Other
• Under JUnit category select Test Suite and click on Next
• Provide the required details and click on Finish
• It will create the Test Suite Class
Running Test Suite
• Right click the Test Suite class and select Test File
• Observe the test results in ©the
Infosys Technologies Ltd.
Test Result Window.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 120
anytime, anywhere!
© Infosys Technologies Ltd.

Plug-ins…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 121
anytime, anywhere!
NetBeans Plugins
• NetBeans IDE is built in modular fashion.
• At the core is the NetBeans platform, which itself has lot
of plugin modules, to provide support for various
technologies and tools.
• The support for new technologies by IDE can further be
extended by adding the appropriate plugin modules
• The plugin modules are available as *.nbm (NetBeans
Modules) files.
© Infosys Technologies Ltd.
• The plugins can be downloaded from the NetBeans
plugins Portal http://plugins.netbeans.org/PluginPortal/

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 122
anytime, anywhere!
Adding Plugins to IDE
• Steps involved
– Select Tools  Plugins
– Select “Download Tab” and click on “Add Plugins…”
– Select the required *.nbm file and click on “Open”. It
will add the nbm files.
– Click on “Install” and Proceed with the installation.
– Restart the IDE.
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 123
anytime, anywhere!
Adding Plugins to IDE [Contd..]

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 124
anytime, anywhere!
© Infosys Technologies Ltd.

Profiling…
We enable you to leverage knowledge
© 2008, Infosys Technologies Ltd. Confidential 125
anytime, anywhere!
Need for profiler
• Any application should have ability to scale up as the
number of users increases.
• The performance of the application should not degrade,
as the load increases.
• The application can’t be scalable if it consumes more
resources such as CPU cycles and memory.
• Profilers helps in detecting memory and CPU utilization
issues
© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 126
anytime, anywhere!
Calibration
• While profiling, the profiling methods will be inserted into
application byte codes. This will be removed once the
profiling process is stopped. This process is called
instrumentation.
• Instrumentation process has some additional overhead.
• To get accurate results on profiling, the time spent in
instrumentation has to be excluded out.
• For that the profiler need the calibration data.
© Infosys Technologies Ltd.
• To get the Calibration Data,
– Select Profile  Advanced Commands Run Profiler
Calibration
– Select the Java platform to calibrate and Select “ok”.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 127
anytime, anywhere!
Profiling a project – Build file modification
• If the project is profiled for the first time then IDE will
attempt to add appropriate targets to the projects Ant
Script.
• For that permission has to be given by the user.

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 128
anytime, anywhere!
Profiling Task - Monitor

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 129
anytime, anywhere!
Monitor Profiler Output

Threads Section

Profiler VM Telemetry
Control Overview
Panel Window

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 130
anytime, anywhere!
Profiling task -CPU

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 131
anytime, anywhere!
CPU Profiler output

Self time – Time Invocations –


consumed by a Number of times a
© Infosys
method in graph, Technologies Ltd.
method been
ms and % in one invoked
invocation

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 132
anytime, anywhere!
Profiling Task - Memory

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 133
anytime, anywhere!
Memory Profiler - Output

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 134
anytime, anywhere!
Summary
• Different Project creation (Java, Web, Enterprise)
• Tool Usage (Ant, CVS, Refractor)
• Debugging
• Services(Database, Servers)
• Archive Creation (JAR, WAR, EAR)
• Unit testing support
• Plug-ins
© Infosys Technologies Ltd.
• Profiling

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 135
anytime, anywhere!
References
• Patrick Keegan, Ludovic Champenois, Gregory Crawley,
Charlie Hunt, Christopher Webster, “NetBeans IDE Field
Guide”, Prentice Hall, Second Edition
• http://www.netbeans.org

© Infosys Technologies Ltd.

We enable you to leverage knowledge


© 2008, Infosys Technologies Ltd. Confidential 136
anytime, anywhere!
Thank You

Confidential © 2008, Infosys


ER/CORP/CRS/<CourseCode>/003
Technologies Ltd.

You might also like