Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

Similar documents
Just Enough Eclipse What is Eclipse(TM)? Why is it important? What is this tutorial about?

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

Eclipse Environment Setup

Eclipse CDT Tutorial. Eclipse CDT Homepage: Tutorial written by: James D Aniello

Manual Eclipse CDT Mac OS Snow Leopard

CS 201 Software Development Methods Spring Tutorial #1. Eclipse

Creating a new CDC policy using the Database Administration Console

Module 3: Working with C/C++

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

POOSL IDE Installation Manual

Introduction to Eclipse

Assignment 1. Application Development

Lab 0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Lab #1: A Quick Introduction to the Eclipse IDE

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Using Eclipse for C, MPI, and Suzaku

MEDIA COMPUTATION DRJAVA. Lecture 11.3 November 7, 2008

At the shell prompt, enter idlde

CSCI 161: Introduction to Programming I Lab 1a: Programming Environment: Linux and Eclipse

Moving From Studio to Atelier. Wouter Dupré Sales Engineer

Index. Symbols. /**, symbol, 73 >> symbol, 21

UNic Eclipse Mini Tutorial (Updated 06/09/2012) Prepared by Harald Gjermundrod

i2b2 Workbench Developer s Guide: Eclipse Neon & i2b2 Source Code

Imperative and Object Oriented Programming. Tutorial 1. Charlie Abela Department of Artificial Intelligence

SDKs - Eclipse. SENG 403, Tutorial 2

Prerequisites for Eclipse

Using Eclipse for Java. Using Eclipse for Java 1 / 1

Starting In Java With JPT in Eclipse

1.00 Lecture 2. What s an IDE?

Introduction to Computation and Problem Solving

An Introduction to Eclipse: Quick Guide. Part 1: Getting Started with Eclipse Part 2: Working with Eclipse Useful Online Guides

IBM C Rational Functional Tester for Java. Download Full Version :

Summer Assignment for AP Computer Science. Room 302

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

Test driven development Example

Hello World on the ATLYS Board. Building the Hardware

What s NetBeans? Like Eclipse:

Lab Android Development Environment

- 1 - Handout #33 March 14, 2014 JAR Files. CS106A Winter

Maintain an ILE RPG application using Remote System Explorer

Using Eclipse and Karel

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Setting Up the Development Environment

Instructions PLEASE READ (notice bold and underlined phrases)

Do this by creating on the m: drive (Accessed via start menu link Computer [The m: drive has your login id as name]) the subdirectory CI101.

Prototype User Guide Public Release Version 1

S D K Q U I C K S T A R T

Getting Started with Eclipse/Java

SVN_Eclipse_at_home. 1. Download Eclipse. a. Go to: and select Eclipse IDE for Java Developers

Drools Tools Reference Guide. Version: CR1

Your password is: firstpw

Laboratory 1: Eclipse and Karel the Robot

Monroe Township High School AP Computer Science A Summer Packet

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel

Mehran Sahami Handout #5 CS 106A September 26, 2018 Downloading Eclipse

Hadoop Tutorial. General Instructions

Step 1: Adding Darwin to your computer

Welcome To Account Manager 2.0

CST8152 Compilers Creating a C Language Console Project with Microsoft Visual Studio.Net 2010

Project 1a: Hello World!

Writing Code and Programming Microcontrollers

You have a PC with a USB interface, running Microsoft Windows XP (SP2 or greater) or Vista You have the Workshop Installation Software Flash Drive

Table of Contents. 1 Introduction Downloads Eclipse SDK Installation Eclipse Workspace Eclipse Preferences...

1 Build Your First App. The way to get started is to quit talking and begin doing. Walt Disney

Using Eclipse for C Programming

Debugging in AVR32 Studio

Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat

GNATbench for Eclipse User s Guide

The PALOMA Eclipse Plug-in User Manual

Custom Code Rules Deep Dive

The Road to CCSv4. Status Update

Basic Keywords Practice Session

CMPSCI 187 / Spring 2015 Hanoi

Using EnScript to Make Your Life Easier Session 1. Suzanne Widup, James Habben, Bill Taroli

Module 4: Working with MPI

Mend for Eclipse quick start guide local analysis

Installing Komplete 5 with Direct Install

Procedural Java. Procedures and Static Class Methods. Functions. COMP 210: Object-Oriented Programming Lecture Notes 2.

CHAPTER 6. Java Project Configuration

Website Development Komodo Editor and HTML Intro

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

CMPSCI 187 / Spring 2015 Sorting Kata

Using Eclipse Europa - A Tutorial

As CCS starts up, a splash screen similar to one shown below will appear.

Building and Running a Simple UML RT Model in RSARTE

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

The following steps will create an Eclipse project containing source code for Problem Set 1:

Certified Core Java Developer VS-1036

Mobile App:IT. Methods & Classes

CSCI 201 Lab 1 Environment Setup

Linux Tutorial #1. Introduction. Login to a remote Linux machine. Using vim to create and edit C++ programs

EMC Documentum Composer

Getting Started with Eclipse for Java

Getting Started (1.8.7) 9/2/2009

16.410: Jump Starting With Java

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

Developing Android applications in Windows

Installation Guide - Windows

Transcription:

COMP 210: Object-Oriented Programming Lecture Notes 1 Java Program Structure and Eclipse Robert Utterback In these notes we talk about the basic structure of Java-based OOP programs and how to setup and build them with the Eclipse IDE. We ll more or less ignore Java syntax for now as the code that s written in this process is written by the IDE. Overview All code in Java must be in a class or something similar 1. A source file can only contain one public class and the file name must match the class name. So, if programs are built from the interaction of many objects and we need multiple classes to define the types of those objects, then we re quickly going to be dealing with programs whose code is spread across many, many files. Classes are organized within packages. Just like we did with C++ namespaces, we ll always define our classes within packages. Not using packages is not good style. Package placement will also have an impact on the scope of the definition as well. We ll continue to use unit testing in the design and implementation of our programs. The go-to framework in Java is JUnit 2. You ll find it s very similar to GTest. Just like before we ll separate tests from code. Each class will get its own file of tests, which will also be a class of course. That class will typically get placed in the same package as the class its testing. To start out we ll work with programs composed of several classes that are defined in separate files and done so relative to a package. 1 You ll learn about some other classlike definitions 2 http://junit.org Eclipse Projects and Project Structure Eclipse is a programming IDE. It s written in Java and very well suited for Java development. Through plug-ins you can use it for a wide variety of other languages as well. As a batteries included IDE it includes a robust text editor, integrates with a compiler, and allows you to run and debug programs from within the IDE itself. Programs in Eclipse are represented as projects. Projects are organized within a workspace. The workspace corresponds to directory and the program to a sub-directory of the workspace directory. When you start Eclipse you ll be prompted to select a workspace. I recommend you create a class specific workspace, either way, make a fresh, new directory to act as your Eclipse workspace. You can also check the box to make this the default. You can always switch workspace from the File menu in Eclipse.

comp 210 notes 1: java program structure and eclipse 2 Figure 1: The Eclipse workspace selection window The first time you launch Eclipse you re greeted with a Welcome screen. Just click the icon to take you to the workbench, where we ll be working. Figure 2: The Eclipse Welcome Screen. Just go to the Workbench. You re now ready to create a Java Project you can do this in the usual ways, from File > New or the New Quick button. Once there, choose a project name and ensure your settings look like those in figure 3. Then click Next. Next we need to do some setup for using our unit-testing framework JUnit 5 3. There are two things to do: create a folder to hold all out test code and add the JUnit library to the project. The folder is optional, but it s nice to keep our tests separate from our actual code. To create the folder you ll hit the new source folder link. In the dialog that pops up, name the new folder tests and click Finish. You can see this in figure 4. 3 http://junit.org/

comp 210 notes 1: java program structure and eclipse 3 Figure 3: First Screen in New Project Dialog Figure 4: First Screen in New Project Dialog To add the JUnit library itself, you need to select the Libraries tab, then select ClassPath, then Add Library..., then select JUnit in the dialog that pops up. Then press the Next button. You can see this in figure 5. The last window ensures you have the right version of JUnit. It should look like figure 6. Once you ve setup the test folder and library, you re project is all setup.

comp 210 notes 1: java program structure and eclipse 4 Figure 5: Dialogs for Adding JUnit to a Project Figure 6: Dialog to Select version 5 of JUnit Packages Before we start creating classes we need to create a package or two for those classes. Packages are created within source folders and correspond to physical sub-directories within that folder. So, unlike C++ Namespaces, packages have a physical presence. If our tests and classes are going in the same package then we need to create that package twice, once in the src folder and once in the test folder. There are at least three ways to create a new package: File > New, the New quick button, and right clicking the folder in which the package is to be placed. In either case you end up at a

comp 210 notes 1: java program structure and eclipse 5 dialog like figure 7 that lets you specify the parent director and name of the new package. The name of your package should start with a lower case letter 4. This is a convention and not a syntax error. You should consider it an error though as you ll lose points for violating the convention. 4 Eclipse will warn you if you use Uppercase Figure 7: New Package Dialog When you re done your project should show the packages within their respective source folders as seen in figure 8. With packages in place, we re ready to start creating Classes, i.e. source files. Classes and Files To create a new Class you an use the usual options: File > New, the New quick button, or right click New on the package in which you want the Class placed. We ll always start by stubbing out the class. We can then use Eclipse to stub out the tests. You ll find that Eclipse can auto-generate a lot of boiler place code for you. This is good because it ll save time. It s bad because it s all too easy for you to ignore that code and not know how to write it yourself. This will undoubtedly lead to you losing points on quizzes and exams or botching an interview for an internship or job. So, just because the IDE

comp 210 notes 1: java program structure and eclipse 6 Figure 8: A Project with src and tests folders and a shared package writes the code for you doesn t mean you don t need to know how to do it yourself! The new Class dialog has lots of options. We ll deal with them on an as needed basis. The core options are specifying the location, package, and name of the class. The class name should start with an uppercase letter. This is, again, a convention that we ll follow as a rule. The class name becomes the file name. Java files have the unsurprising extension of java. Figure 9 points the core options and one extra option, stubbing out a main, that s discussed a bit below. The main procedure The other New Class dialog option I ll point out now is that this dialog give you the option to automatically generate a stub for main. Java, like C++, operates by executing a main procedure. It s the one procedure we ll write with any kind of regularity. Compile and Run In figure 10 you ll see a Hello World program in Java. We ll leave the details of the code itself for the next set of notes. For now you should notice a few things highlighted in the figure. The green play button compiles and runs the program. Console output 5 happens down at the bottom. In code, the inclusion of a file/class in a package 5 and input

comp 210 notes 1: java program structure and eclipse 7 Figure 9: New Class Dialog with core options highlighted. takes place with a simple package declaration. Files are opened and edited in the center of the window. IF you ve been following along, then you re encouraged to play around a bit. Go find some other Java tutorials and make a more interesting Hello World. In the next set of notes we ll design, document, implement, and test some procedures in order to get a better feel for the nuts and bolts of Java.

comp 210 notes 1: java program structure and eclipse 8 Figure 10: Hello World in Java