Tutorial 5: Developing Java applications



Similar documents
For Introduction to Java Programming, 5E By Y. Daniel Liang

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Introduction to Eclipse

Code::Blocks Student Manual

EMC Documentum Composer

Eclipse installation, configuration and operation

Department of Veterans Affairs. Open Source Electronic Health Record Services

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

Jenkins on Windows with StreamBase

Debugging Java Applications

Creating Web Services Applications with IntelliJ IDEA

Installing (1.8.7) 9/2/ Installing jgrasp

Beginning with SubclipseSVN

Informatics for Integrating Biology & the Bedside. i2b2 Workbench Developer s Guide. Document Version: 1.0 i2b2 Software Release: 1.3.

SDK Code Examples Version 2.4.2

IBM Tivoli Workload Scheduler Integration Workbench V8.6.: How to customize your automation environment by creating a custom Job Type plug-in

Hadoop Tutorial. General Instructions

NetBeans IDE Field Guide

EPIC - User s Guide i. EPIC - User s Guide

Lab 0 (Setting up your Development Environment) Week 1

Creating a Java application using Perfect Developer and the Java Develo...

Practice Fusion API Client Installation Guide for Windows

A Tutorial on installing and using Eclipse

POOSL IDE User Manual

Building and Using Web Services With JDeveloper 11g

Smooks Dev Tools Reference Guide. Version: GA

Oracle SOA Suite 11g Oracle SOA Suite 11g HL7 Inbound Example

Building Applications with JBuilder

IDS 561 Big data analytics Assignment 1

Using Microsoft Visual Studio API Reference

Code Estimation Tools Directions for a Services Engagement

<Insert Picture Here> What's New in NetBeans IDE 7.2

PTC Integrity Eclipse and IBM Rational Development Platform Guide

TIPS & TRICKS JOHN STEVENSON

POOSL IDE Installation Manual

Netbeans IDE Tutorial for using the Weka API

Getting Started using the SQuirreL SQL Client

Using the Query Analyzer

Q N X S O F T W A R E D E V E L O P M E N T P L A T F O R M v Steps to Developing a QNX Program Quickstart Guide

Tutorial: setting up a web application

Database Studio is the new tool to administrate SAP MaxDB database instances as of version 7.5.

IDE s for Java, C, C++ David Rey - DREAM

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

Java with Eclipse: Setup & Getting Started

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3 SP02

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

10 STEPS TO YOUR FIRST QNX PROGRAM. QUICKSTART GUIDE Second Edition

ADT Plugin for Eclipse


Getting started with 2c8 plugin for Microsoft Sharepoint Server 2010

Oracle Universal Content Management

Developing In Eclipse, with ADT

Workshop for WebLogic introduces new tools in support of Java EE 5.0 standards. The support for Java EE5 includes the following technologies:

How to test and debug an ASP.NET application

SimbaEngine SDK 9.4. Build a C++ ODBC Driver for SQL-Based Data Sources in 5 Days. Last Revised: October Simba Technologies Inc.

Content. Development Tools 2(63)

Tutorial: BlackBerry Object API Application Development. Sybase Unwired Platform 2.2 SP04

IBM FileNet eforms Designer

Microsoft Visual Studio Integration Guide

Hudson configuration manual

Tutorial: BlackBerry Application Development. Sybase Unwired Platform 2.0

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

TUTORIAL ECLIPSE CLASSIC VERSION: ON SETTING UP OPENERP 6.1 SOURCE CODE UNDER WINDOWS PLATFORM. by Pir Khurram Rashdi

creating a text-based editor for eclipse

Introduction to the use of the environment of Microsoft Visual Studio 2008

Embarcadero DB Change Manager 6.0 and DB Change Manager XE2

BlueJ Teamwork Tutorial

Deploying Microsoft Operations Manager with the BIG-IP system and icontrol

Using SQL Developer. Copyright 2008, Oracle. All rights reserved.

Desktop, Web and Mobile Testing Tutorials

Sonatype CLM Enforcement Points - Continuous Integration (CI) Sonatype CLM Enforcement Points - Continuous Integration (CI)

Work. MATLAB Source Control Using Git

Application. 1.1 About This Tutorial Tutorial Requirements Provided Files

Developing with Android Studio

IBM VisualAge for Java,Version3.5. Remote Access to Tool API

Hypercosm. Studio.

Oracle Service Bus Examples and Tutorials

Setting up VMware ESXi for 2X VirtualDesktopServer Manual

Running a Program on an AVD

Monitoring Oracle Enterprise Performance Management System Release Deployments from Oracle Enterprise Manager 12c

DEPLOYING A VISUAL BASIC.NET APPLICATION

Building OWASP ZAP Using Eclipse IDE

Kony MobileFabric. Sync Windows Installation Manual - WebSphere. On-Premises. Release 6.5. Document Relevance and Accuracy

IBM TRIRIGA Anywhere Version 10 Release 4. Installing a development environment

JBoss Portal 2.4. Quickstart User Guide

IBM WebSphere Application Server V8.5 lab Basic Liberty profile administration using the job manager

WebSphere Business Monitor V7.0: Clustering Single cluster deployment environment pattern

Hadoop Basics with InfoSphere BigInsights

DAVE Usage with SVN. Presentation and Tutorial v 2.0. May, 2014

Application Interface Services Server for Mobile Enterprise Applications Configuration Guide Tools Release 9.2

Installation Guidelines (MySQL database & Archivists Toolkit client)

Eclipse with Mac OSX Getting Started Selecting Your Workspace. Creating a Project.

Operational Decision Manager Worklight Integration

Building graphic-rich and better performing native applications. Pro. Android C++ with the NDK. Onur Cinar

A Quick Start Guide to DrJava

INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3

etoken Enterprise For: SSL SSL with etoken

Apache Directory Studio. User's Guide

Advantage Joe. Deployment Guide for WebLogic v8.1 Application Server

Transcription:

Tutorial 5: Developing Java applications p. 1 Tutorial 5: Developing Java applications Georgios Gousios gousiosg@aueb.gr Department of Management Science and Technology Athens University of Economics and Business Revision : 1117

Tutorial 5: Developing Java applications p. 2 Contents The Java Development Environment The classpath Invoking the compiler and the VM The Eclipse IDE

Java Bytecode VM Tutorial 5: Developing Java applications p. 3 The Java approach to software The compiler is relatively simple The source code is transformed to an intermediate representation (bytecode) suitable for transfer among different platforms Java Virtual Machine Interpreter Just-in-Time (JIT) compiler Javac C l a ss l o a d e r Verifier Intpr JIT

Tutorial 5: Developing Java applications p. 4 Main concepts of the Java platform Write once, run everywhere Classloader Security Bytecode verifier Array bounds checks, no pointers Security manager - Sandbox Internet centric Rich API s

Tutorial 5: Developing Java applications p. 5 The Classpath The classpath is a string that helps the Java language to find its libraries. Syntax CLASSPATH=path1:path2, e.g. CLASSPATH=$HOME/jarpeb.jar:$HOME/test/:. An environment variable in Unix and Windows or a command line argument. A classpath can contain both paths to.jar files and to directories containing.class files Default libraries in $JAVA_HOME/lib

Tutorial 5: Developing Java applications p. 6 The Classpath The package path is added to the classpath when searching for classses Examples: CLASSPATH=$HOME/java/:$HOME/jarpeb.jar:. java gr.aueb.dds.exercise1 CLASSPATH=: java -cp $HOME/jarpeb.jar gr.aueb.dds.exercise1

Tutorial 5: Developing Java applications p. 7 Important programs java: The execution environment javac: The source to bytecode compiler javadoc: Tool that generates sourcecode documentation from special comments in the source code jar: Tool that creates and manipulates Java archives ant: A Java oriented build system

Tutorial 5: Developing Java applications p. 8 javac Use the-classpath switch to specify where the compiler can find user libraries and source files Use the-verbose switch to see what classes are loaded by the compiler during compilation Use the-g switch to generate debugging information Ant task: <javac> avac -d classes Hello.java avac -classpath./src/java:./lib/ \ src/java/net/sf/jftp/*.java

Tutorial 5: Developing Java applications p. 9 javadoc avadoc [options] [packagenames] [sourcefiles] -d dir Output files todir -classpath Where to find source or class files to process -sourcepath Where to find source files to process -docletpath Which style to use for the output Ant task: <javadoc> avadoc -d doc -classpath src/java/ net.sf.jftp

Tutorial 5: Developing Java applications p. 10 hejar program distribution format A jar file contains class files and auxiliary resources The jar file can contain a META-INF/Manifest.mf file to: Define the default class to be executed Include cryptographic hashes of the jar to verify its integrity Version information The contents of a jar archive are compressed with the zip algorithm

Tutorial 5: Developing Java applications p. 11 hejar program distribution format The jar program is similar to the Unixtar program To create a JAR file: jar cf jar-file input-file(s) To view the contents of a JAR file: jar tf jar-file To extract the contents of a JAR file: jar xf jar-file Running jar-packaged Software: java -jar jar-file Ant task: <jar>

Theant build system Used to manage the build process for large (>5 source files) programs Uses an XML description file for information on what to do Basic concepts: Project: A collection of resources to be processed Target: A set of processing actions Task: A single action Common targets: compile, build, clean, test, run, javadoc ant [options] targets or ant [options] (executes the default target) Tutorial 5: Developing Java applications p. 12

Tutorial 5: Developing Java applications p. 13 Examplebuild.xml file project name="j-ftp" default="jars" basedir="."> <property name="compile.debug" value="true"/> <property name="compile.deprecation" value="false"/> [...] <target name="compile" depends="prepare" description="compile components"> <javac srcdir="src/java" destdir="build/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}" nowarn="true"> <classpath refid="compile.classpath"/> </javac> </target> /project>

Java IDEs IDE: Integrated Development Environment Usually a very competent editor along with an integrated build system Facilities offered by modern IDEs Editor with syntax highlighting, auto indentation and code folding Auto-completion of object and method names with integrated help system Visual editors for GUIs and debuggers Interfaces to servers and databases Automatic creation of a files Interfacing to version control systems Tutorial 5: Developing Java applications p. 14

Tutorial 5: Developing Java applications p. 15 The Eclipse IDE Open source version of the proprietary Sun Java Studio IDE Available at http://www.eclipse.org Should also download the Javadoc Java documentation zip file http://java.sun.com/javase/6/docs/api/ To run On Linux: From a console execute the eclipse command On Windows: Double-click the Eclipse icon

Tutorial 5: Developing Java applications p. 16 The Eclipse IDE - Basic principles Basic environment only supports Java, but plug-ins exist for all known languages (including PHP) Plug-ins are updated from central repositories Everything is organised around projects - several types of projects depending on the language Projects are automatically compiled each time you save Projects can be version controlled to support team development Each language contains editors with features such as auto completion, syntax highlighting and auto formatting Most languages also include a graphical debugger Projects can be viewed from different perspectives (ways of organising/presenting files)

Tutorial 5: Developing Java applications p. 17 Initial configuration Install necessary plug-ins (Subversion and PHP) From the Tools menu, choose the Software Updates option and click on Find and Install option Choose Search new features... From the dialog that opens, choose new remote site Add the following for PHP and SVN SVN http://subclipse.tigris.org/update_1.2.x/ PHP http://download.eclipse.org/tools/pdt/updates/ Some plug-ins might have dependencies, ask for help!

Tutorial 5: Developing Java applications p. 18 ecking out projects from a repository File->New->Project->SVN->Check out projects from SVN Create new repository and set the URL to your SVN URL Select your project directory from the list Click finish you will be presented with the New Project Wizard Select either Java Project or the corresponding project type if you are not using Java Enter a project name and click finish The checkout process begins

Tutorial 5: Developing Java applications p. 19 Configuring the project Menu Project->Properties Select the Java Build Path from the list on the left Set the directories where the source code in the Source tab dialogue In the same tab, click on Allow output folders for source folders Add the libraries (jar files) to the build path at the Libraries tab everything is OK, Eclipse should compile the project cleanly (no d markers in the Package Explorer)

Tutorial 5: Developing Java applications p. 20 Running and Debugging Before running the project, you must create a Run configuration Menu Run->Run Double click on Java application Choose a name for the configuration and set the project main class in the Main tab If your application is working in the command line, set the appropriate arguments in the Arguments tab Click on Apply and then on Run. Your program will start You can create as much Run configurations as you like, eg to test various command line options

Tutorial 5: Developing Java applications p. 21 Running and Debugging ebugging Set a breakpoint - Eclipse is smart, it won t allow you to set breakpoints to places not participating in execution, e.g. class member declarations Click on Run->Debug and in the dialogue that appears select the Run configuration you ve created before Eclipse will switch to the debug perspective, you will then able to see windows displaying local variables and executing threads. The program will execute up to the breakpoint. You can then execute the program line by line (F5 to go to next line)

Tutorial 5: Developing Java applications p. 22 The team synchronising perspective Menu Window->Open perspective->team Synchronizing. Once again, you have to create a synchronisation configuration Click on the synchronise button and select SVN from the sync types. Then, select your project and click finish Before committing or updating, you can inspect the changes that will be made per file by double-clicking on each file All actions are accessible by right clicking on files and directories Be sure not to commit the binary output file New files must be added to the repository before being committed to it

Tutorial 5: Developing Java applications p. 23 The Netbeans IDE Open source version of the proprietary Sun Java Studio IDE Available at http://www.netbeans.org Should also download the Javadoc Java documentation zip file To run On Linux: From a console execute the netbeans command On Windows: Double-click the Netbeans icon

Tutorial 5: Developing Java applications p. 24 Initial configuration Add the Javadoc archive From the Tools menu open the Java Platform Manager Select the Javadoc tab and click the Add ZIP/Folder button Choose a nice font for the editor From the Tools menu select Options Font can be changed under "Editing", "Java Editor", "Fonts and Colors"

Importing a project the project isant-based (it d better be!) Open "New Project" from the "File" menu Choose "General" and "Java project with Existing Ant Script" and click next Open the project s top level directory in the "Location" field Unless thebuild.xml file is not in the project s top dir, everything should be auto-filled. Else, select the build.xml file At the next screen, select from the dropdown menus the targets that are closer to the descriptions Tutorial 5: Developing Java applications p. 25

Tutorial 5: Developing Java applications p. 26 Importing a project At the next screen, select the directories that contain source files. Care should be taken to correctly import the package hierarchies. Open a random source file and use the following heuristic to find the top-level dir to include: package x.y.z --> dir hierarchy x.y.z Import the dir containing x If the project has atest directory, import it in the "Test Package Folders" field At the next screen, import the jar files present in thelib directory and other possible depedencies

Tutorial 5: Developing Java applications p. 27 Importing a project the project is notant-based: Open "New Project" from the "File" menu and choose "General" and "Java project with Existing sources" Select the input source and library directories Netbeans builds a simpleant build file automatically, which can then be edited. Knowledge ofant is a prerequisite

Tutorial 5: Developing Java applications p. 28 Practice Import your projects (Ask the demonstrator for help) In case you don t have a project yet: Try Jalopy

Tutorial 5: Developing Java applications p. 29 Running the project If the project contains a runant target, then F6 will execute the project If not, write a custom run target: Open the build.xml file from the project hierarchy Use the following template Add the new target to the project configuration (Project properties->run and Build) arget name="run" depends="build"> <java dir="build" <!--Compilation output dir--> classname=""<!--class to execute--> jar="" <!--Application main jar--> fork="true" <!--Only when jar is set--> classpath=""<!--where to find libraries--> /> target>

Tutorial 5: Developing Java applications p. 30 Browsing the project The project classes are displayed organised in packages Classes withmain methods are specially marked By clicking on a variable we can view its declaration (Ctrl+O), its source implementation (Ctrl+Shift+G) and its usage (Shift+F7) We can search either by text or by type names in both the currently open file or the whole project Auto-completion can help to view both functions and documentation for a class

Debugging Breakpoints: Used to stop a program at a certain line of code Watch: A variable whose value is constantly monitored The debugger runs the project until the first breakpoint is encountered Whenever the debugger stops, all local variable values are displayed along with running threads and watches Step over/into/out: Go over/into the declaration/out of the declaration of a function Run to cursor: Set the cursor to a line in code. The debugger stops execution when the line is reached Tutorial 5: Developing Java applications p. 31

Tutorial 5: Developing Java applications p. 32 Writting Javadoc comments Netbeans features Javadoc integration To add Javadoc to a class: Tools -> Autocomment Netbeans automatically parses Javadoc comments and adds them to popup class descriptions during autocompletion To search for Javadoc help: Todo -> Javadoc Index Search To generate Javadoc for project: Build -> Generate Javadoc

32-1

Tutorial 5: Developing Java applications p. 33 Writting tests Netbeans features JUnit integration To create a test suite for the project Unless it exists, create a test directory: Go to Project properties and add an empty folder to Test package folders Go to Tools -> JUnit tests -> Create tests to generate a test case for the currenlty open class. To run a test: Anant task must be present to run a test case

33-1