Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.



Similar documents
LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Install Java Development Kit (JDK) 1.8

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

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

Using NetBeans to Compile and Run Java Programs

Installing Java. Table of contents

1001ICT Introduction To Programming Lecture Notes

Instructions for Configuring a SAS Metadata Server for Use with JMP Clinical

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

LAB4 Making Classes and Objects

Java is commonly used for deploying applications across a network. Compiled Java code

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

Hello World RESTful web service tutorial

6.1. Example: A Tip Calculator 6-1

How to Install Java onto your system


Introduction to Object-Oriented Programming

Appendix M: Introduction to Microsoft Visual C Express Edition

Appendix K Introduction to Microsoft Visual C++ 6.0

Visual Studio 2008 Express Editions

2 Getting Started with jgrasp 2.0

Creating Web Services Applications with IntelliJ IDEA

Manual For Using the NetBeans IDE

Chapter 1 Java Program Design and Development

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Virtual Office Remote Installation Guide

An Overview of Java. overview-1

Object-Oriented Programming in Java

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

How to use the Eclipse IDE for Java Application Development

Tutorial: Time Of Day Part 2 GUI Design in NetBeans

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

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

1. Tutorial Overview

Tool Tip. SyAM Management Utilities and Non-Admin Domain Users

Task Scheduler. Morgan N. Sandquist Developer: Gary Meyer Reviewer: Lauri Watts

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

Lecture 5: Java Fundamentals III

Java CPD (I) Frans Coenen Department of Computer Science

Building and Using Web Services With JDeveloper 11g

Getting Started with Command Prompts

Using Eclipse to Run Java Programs

UML Class Diagrams (1.8.7) 9/2/2009

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Appendix A How to create a data-sharing lab

Introduction to Eclipse

Programming with Java GUI components

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

Installing the ASP.NET VETtrak APIs onto IIS 5 or 6

Lab Experience 17. Programming Language Translation

Tutorial Build a simple IBM Rational Publishing Engine (RPE) template for IBM Rational DOORS


DEPLOYING A VISUAL BASIC.NET APPLICATION

Producing Standards Based Content with ToolBook

Java applets. SwIG Jing He

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Lab Manual: Using Rational Rose

Catalog Web service and catalog commerce management center customization

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

Part 1 Foundations of object orientation

Installing the Android SDK

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

How to test and debug an ASP.NET application

Statgraphics Getting started

Witango Application Server 6. Installation Guide for Windows

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

Sales Person Commission

This Skill Builder demonstrates how to define and place sketched symbols in drawings.

CS 106 Introduction to Computer Science I

SQL Server 2005: Report Builder

Eclipse installation, configuration and operation

TAMUS Terminal Server Setup BPP SQL/Alva

Visual C Tutorial

Reading and Understanding Java s API Documentation

William Paterson University Department of Computer Science. Microsoft Visual C++.NET Tutorial Spring 2006 Release 1.0

What is a Mail Merge?

Introduction to Java

From the list of Cooperative Extension applications, choose Contacts Extension Contact Management System.

University of Arkansas Libraries ArcGIS Desktop Tutorial. Section 4: Preparing Data for Analysis

Erie 1 BOCES/WNYRIC. Secure File Transfer. Upload/Download Wizard

Using SSH Secure Shell Client for FTP

Developing, Deploying, and Debugging Applications on Windows Embedded Standard 7

Netbeans IDE Tutorial for using the Weka API

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Advanced Outlook Tutorials

Outlook Web Access. PRECEDED by v\

HOW TO USE OIT VIA THE WEB

Week 2 Practical Objects and Turtles

Importing and Exporting With SPSS for Windows 17 TUT 117

Using an Automatic Back Up for Outlook 2003 and Outlook 2007 Personal Folders

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Primavera Unifier v9.14 / 2014 EPPM Day Hands On Session Exercise Document

Merak Outlook Connector User Guide

Interior Design Tutorial

Pharmacy Affairs Branch. Website Database Downloads PUBLIC ACCESS GUIDE

Transcription:

Lab 1A. Create a simple Java application using JBuilder In this lab exercise, we ll learn how to use a Java integrated development environment (IDE), Borland JBuilder 2005, to develop a simple Java application the hello world example from Jo Wood s book Java Programming for Spatial Sciences. The exercise has two parts: the first one is to make a program that prints out on the screen some messages. The second is to make a program that opens up a window and display some messages in that window. See appendix for Java source code provided by Jo Wood. (http://oldspice.soi.city.ac.uk/jpss/source/) Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2. Select File New You might want to look at all the options you have on this dialog. The Help button will give you more information about the selected option. 3. In the dialog box, select Project Project, click OK 4. In the following dialog box, type in the name of the project and path that you want to save your project. A JBuilder project contains all the resources you need to build, deploy, and document your Java application. You can, and in many cases should, explore and edit these resources. A folder with the application name will be created in the directory you designate.

5. In the next steps, review the fields and accept the defaults. Now you have a blank project. Now we will create a new class - class Hello1 6. Right-click on the project name HelloWorld.jpx, select New Class 7. Fill in class name Hello1, type in helloworld as package name. Select Generate main method, deselect Generate default constructor. Package is a container of classes. You can think of it as a folder, which contains Java class files.

Note: Java is case sensitive, so Hello1 is different from hello1 Now you can see the structure of the class At this point let s take a look at JBuilder s IDE: from top down, after menus and tool buttons, you see three panes: two on the left and one on the right. Upper left is the project explorer, which displays all project resources and you can access the functionalities of manipulating these resources by right-click on the item. Lower left is the structure view of the content displayed on the right pane, which is the working area you do the detailed editing. Now we can finish up Hello1.class:

8. Copy and paste the code found in Jo Wood s source code Hello1.java into the main() method of your class Hello1. Replace whatever exists in the body of main(). LEAVE the brackets and. System.out.println("Java Programming for Spatial Scientists"); System.out.println("==== =========== === ======= =========="); System.out.println(""); System.out.println("Program One: Hello World."); 9. Save your work. 10. Compile the class and run it: At the bottom you can see the output How Java program runs: When the interpreter executes a class, it looks for a particular method by the name of main, which will sound familiar to C programmers. The main method is passed as a parameter to an array of strings (similar to the argv[] of C), and is declared as a static method (more on this in a later tutorial). To output text from the program, we execute the ' println ' method of System.out, which is Java's output stream. Unix users will appreciate the theory behind such a stream, as it is actually standard output. For those who are instead used to the Wintel platform, it will write the string passed to it to the user's screen. Part 2. make an application with a window Now repeat from step 6 and make another class Hello2, this time copy all the code, except the package line, of Hello2.java from Jo Wood s sample code. Try to understand the code: - to open up a window, class Hello2 needs to extends JFrame ; - JFrame is a class that exists in package javax.swing, this why import javax.swing.* ; - super(windowtitle) creates a new instance of JFrame with the given title - Message Program two and Hello again is displayed as labels in the window - Class Container and BorderLayout come from package java.awt;

Complete Java API documentation can be found at Sun website: http://java.sun.com/j2se/1.4.2/docs/api/index.html Run this class, what do you get? Things to think about: 1. Files and folders Folders: what s in HelloWorld? What s in classes\helloworld? What s in src\helloworld? File types:.java.class.jpx.html Packages and classes Dependencies: import Common Java Libraries: java.awt java.swing Appendix: Source code Hello1.java /****************************************************************** * Hello1 - Program to display a simple text message on the screen. * Author Jo Wood. * Version 1.1, 14th September, 1999 * ******************************************************************/ public class Hello1 // All java applications have a main() method. // This one displays a simple message. public static void main(string args[]) System.out.println("Java Programming for Spatial Scientists"); System.out.println("==== =========== === ======= =========="); System.out.println(""); System.out.println("Program One: Hello World."); Hello2.java import java.awt.*; import javax.swing.*; // Needed to use graphics classes. /******************************************************************

* Hello2 - Program to create a graphics window and display a * simple text message on the screen. * Author Jo Wood. * Version 1.2, 25th August, 2001 * ******************************************************************/ public class Hello2 extends JFrame // All java applications have a main() method. // This one creates a graphics window. public static void main(string args[]) new Hello2("Java for Spatial Sciences"); // This method has the same name as the class (Hello2) and is // called a constructor. In this case it sets the window title. public Hello2(String windowtitle) // Initialise window. super(windowtitle); setdefaultcloseoperation(windowconstants.dispose_on_close); Container window = getcontentpane(); // Add two lines to the window. window.add(new JLabel(" Program two:"),borderlayout.north); window.add(new JLabel(" Hello again."),borderlayout.center); // Size window and make it visible. pack(); setvisible(true);

Lab 1B. Explore the Spatial Modeling Package using JBuilder In this lab exercise, you are asked to explore the spatial modeling package, which will be used throughout this course. The spatial modeling package contains five classes and one interface: public class Footprint public class Gazeteer public class GISVector public class SpatialObject public class VectorMap public interface SpatialModel In this exploration, you are asked to create a new project in JBuilder, and import the package, jwo.jpss.spatial, following the directions below: 1. Similar to Lab 1A, create a new project, using File New. Name your project, spatialtest_yourinitials. Designate the location of the new project folder within your student storage on the P:/ drive and accept all default settings. JBuilder creates a folder in your student storage, with the name you specified. 2. Open Windows Explorer and point to the new project folder you just created. Open the project folder and create a new folder called src. 3. Since we already have the source code for these six.java files, we do not need to create a new class. Using Windows Explorer copy the package folder called jwo from P:/geog465win05/lab1b into the spatialtest_yourinitials/src folder you designated in the P:/ drive. 4. Return to JBuilder, and on the project explorer (the left pane of the screen), click the refresh image at the top of the pane. The folder you imported in Windows Explorer should now be visible as a package, under the name: jwo.jpss.spatial. Expand the package using the + symbol to display the six.java files. 5. Begin exploring this package by double clicking on any of the.java files to view the source code. Try to identify the following items: a. Constructor methods b. Accessor methods c. Mutator methods d. Classes which extends other classes e. Classes which implements interfaces f. Classes versus instantiated objects g. Constants 6. After you feel comfortable with the source code, right click on the package in the project explorer pane, and select Make to compile the package.