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

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

Guided Tour (Version 3.3) By Steven Castellucci as Modified by Brandon Haworth

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

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

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Guided Tour (Version 3.4) By Steven Castellucci

Instructions PLEASE READ (notice bold and underlined phrases)

Getting Started (1.8.7) 9/2/2009

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

Engr 123 Spring 2018 Notes on Visual Studio

Software Installation for CS121

The Command Shell. Fundamentals of Computer Science

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

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.

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

Using the Dev C++ Compiler to Create a Program

CS 201 Software Development Methods Spring Tutorial #1. Eclipse

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

Lab 11-1 Lab User Profiles and Tracking

Lesson 04: Our First Java Program (W01D4

AP Computer Science National Day School

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

You should see something like this, called the prompt :

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

Using Eclipse Europa - A Tutorial

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

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

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

Task-Oriented Solutions to Over 175 Common Problems. Covers. Eclipse 3.0. Eclipse CookbookTM. Steve Holzner

In the first class, you'll learn how to create a simple single-view app, following a 3-step process:

RTMS - Software Setup

Eclipse Environment Setup

Lab #1: A Quick Introduction to the Eclipse IDE

CSCI 201 Lab 1 Environment Setup

NetBeans IDE Java Quick Start Tutorial

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Download and Installation Instructions. Java JDK Software for Windows

Lec 3. Compilers, Debugging, Hello World, and Variables

Optimal Browser Settings Disable File Caching:

CMPSCI 120 Fall 2017 Lab #1 Professor William T. Verts

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

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

Getting Started with Python and the PyCharm IDE

Tutorial 1: Unix Basics

A short guide to learning more technology This week s topic: Windows 10 Tips

CMPS 12A Introduction to Programming Lab Assignment 7

CMPSCI 120 Fall 2013 Lab #2 Professor William T. Verts

Configuring Ubuntu to Code for the OmniFlash or OmniEP

CENG 334 Computer Networks. Laboratory I Linux Tutorial

MEDIA COMPUTATION DRJAVA. Lecture 11.3 November 7, 2008

IBM WebSphere Java Batch Lab

Hadoop Tutorial. General Instructions

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

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

Setting up your Computer

CIS 231 Windows 10 Install Lab # 3

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Eng. Mohammed S. Abdualal

'phred dist acd.tar.z'

Your password is: firstpw

15-122: Principles of Imperative Computation

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

ECE QNX Real-time Lab

CS 209 Section 52 Lab 1-A: Getting Started with NetBeans Instructor: J.G. Neal Objectives: Lab Instructions: Log in Create folder CS209

GeographyPortal Instructor Quick Start World Regional Geography Without Subregions, Fifth Edition Pulsipher

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

Lab 2. CSE 3, Summer 2010 In this lab you will learn about file structures and advanced features of Microsoft Word.

Javac and Eclipse tutorial

Prerequisites for Eclipse

Introduction to Unix - Lab Exercise 0

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

Module 3: Working with C/C++

You will need to download the Java software development kit from

Step 1: Use StudyMate to Publish files

At the shell prompt, enter idlde

Connection Tests for the ReadyTech environment

1 Installation (briefly)

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

emeasures 2.0 USERS MANUAL

COMP 110 Project 1 Programming Project Warm-Up Exercise

Helsinki 19 Jan Practical course in genome bioinformatics DAY 0

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

How to set up a Default Printer

Lab # 2. For today s lab:

CS Fundamentals of Programming II Fall Very Basic UNIX

Table of Contents HOL-SDC-1422

Mail Merge. To Use Mail Merge: Selecting Step by Step Mail Merge Wizard. Step 1:

1) Log on to the computer using your PU net ID and password.

Contents. Signing In... 3 Answering Your Personal Security Question... 4 Forgetting Your Password... 4 Exploring the Learning Center Interface...

Moodle The Basics of Editing a Content Management Course

WA1937 WebSphere Portal 7.0 Programming. Classroom Setup Guide. Web Age Solutions Inc. Copyright 2012 Web Age Solutions Inc. 1

2. Click on the Launch button and select Terminal. A window will appear which looks like:

Lab: Supplying Inputs to Programs

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

Code::Blocks Student Manual

Word - Basics. Course Description. Getting Started. Objectives. Editing a Document. Proofing a Document. Formatting Characters. Formatting Paragraphs

There are six main steps in creating web pages in FrontPage98:

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Transcription:

Goals - to learn how to compile and execute a Java program - to modify a program to enhance it Overview This activity will introduce you to the Java programming language. You will type in the Java program shown, compile it, and execute it. You will submit your project. Creating a Java program (Hello.java) CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java) /* Hello.java: traditional first program * Author: your name * Date: today's date */ public class Hello { /** * @param args */ } public static void main(string[] args) { // TODO Auto-generated method stub } // Console input and output System.out.println("Hello, world!"); You should still have a terminal window and Eclipse open. If not, open a terminal window and change your working directory to be your ~/161 directory (type cd 161). Now open Eclipse by typing 'eclipse &' (be careful not to omit the ampersand), or just click on the Eclipse icon on the tool bar at the left of the desktop (Not there? Click on the Applications button in the upper left corner of the desktop.). Create a new project by clicking on File New Java Project. o This may pop up a Select a wizard window, as shown in Figure 1. If it does, Click on the arrow to the left of where it says Java, then click on Java Project. Click the Finish button. 1

Figure 1 o A Create a Java Project dialog box should open. For the Project name type in Lab1a (the fourth character is a one; without the quotes, and with no spaces). o Under Project layout, Click on the radio button that says Use project folder as root for sources and class files. Click on Configure default Click on the Project radio button. Click on the OK button. o Click on the Finish button. 2

o A new dialog box should appear as shown in Figure 2. Click on the Remember my decision checkbox (so that you never get this dialog box again in the future), and then click on Yes. Figure 2 If all goes well, you should now see the following screen (you can close the Outline pane on the right side of the window, since we won t be using it): Figure 3 3

Make sure that Lab1a is selected under the Package Explorer pane on the left side of the window (it would be highlighted). Create a new Java class file by clicking on the New Java Class button (it is a green circle with a C and a little +). If by mistake you click the arrow next to the New Java Class button (which causes a drop-down menu to appear), you need to select Class (the top entry). A new dialog box will appear. Make sure that Lab1a is the source folder name (make it so, if it isn t). Type Hello as the Name. Under Which method stubs would you like to create?, click on the box to create public static void main(string[ ] args) so that a check mark appears. Now click the Finish button. In the editor pane, you will see a new tab entitled Hello.java. This file automatically has focus, i.e. it s where things that you type will show up. This file contains the basic outline or stub of a Java class called Hello the first line should read public class Hello {. You will fill in this stub with the rest of the code shown above. Begin typing in the Java program shown above. Include your name in the comments, along with today s date. As you type statements, pay close attention to capitalization (some letters must be capitalized) and spacing, both within a line and between lines. You want your code to look exactly like that shown above. Get into the habit of indenting the program as shown above. The Eclipse editor makes it easy to use consistent indentation by automatically indenting the next line after the enter key is pressed. If you press 'CONTROL-SHIFT-F', Eclipse will automatically indent all of your code. This program has minimal comments. We will expect more on later assignments. Comments and indenting are essential to the readability of your program. Type in the program logic just below the // TODO Auto-generated method stub comment line. Note that Eclipse will attempt to assist you as you are typing in the code by suggesting possible completions to what you have typed so far. You may ignore these suggestions for now. Once you ve typed in the entire program as shown above, Click the Run button (the green circle with the white triangle that looks like a play button). (If you accidently click the down arrow beside the Run button instead, you will need to select Run ). If Eclipse cannot automatically create a launch configuration, a dialog box will appear. Highlight Java Application and click the new button (a page with a plus sign if you hover, it says New launch configuration ). Hello is added below the Java Application and it will be highlighted. The Name should default to Hello, the project to Lab1, and the Main class (which is the name of the class containing the method or function main ) to Hello. Click the Run button to launch your application! If you have not saved the Hello.java file, you will be prompted to save your files you should click the box for Always save resources before launching to avoid being prompted to save in the future. 4

This program is a very simple example of console output. When you run it, the phrase Hello, world! will appear in the console window (located at the bottom of the workbench window in the Console tab). Debugging your program: If Eclipse detects a mistake in your code as you are typing in your program, the line will be marked with a red wavy underscore. You should attempt to correct the error before running your program. If you do run a program and run-time errors occur, error messages will be shown in the Console pane. Continue to debug (correct) your program until you are able to run it without exceptions. Submit your Project as Lab1a: In the terminal window, use submit to submit your updated project. Make sure that you are in your Lab1a directory. If not, use the cd command to get there. Type the command submit When the dialog asks you to enter the name of the grader account, type in liffick161 The file being submitted should be Hello.java. If it isn t, you are probably still in the wrong directory. Reposition the directory using the cd command and try again. Modifying an existing program (Hello2.java) For this next activity, you will modify the program you created above. You don't want to replace your previous program, so you will copy it and modify the copy. Create a New Project: Use the same process as above by clicking on File New Java Project. Name the new project Lab1b. Create a New Class from an Existing Program: Follow the same process as above to create a new class called Hello2 for the Lab1b project. You can copy and paste the Hello program from Lab1a into Lab1b to avoid retyping most of the code for this new project. Make a Few Small Changes: First change the class name to Hello2 (as in public class Hello2 { ). Edit Hello2.java so that the console output greets you by first name, for example, Hello, Jane! instead of Hello, world! Run the Program: This time, you can just click the Run button. When you are done, submit your modified project again as "Lab1b". Congratulations! You ve survived your first 161 lab! 5

Practice Some Terminal Commands: Learning a few terminal (Unix bash shell) commands will make it easier for you to use the system. You'll learn these commands as time goes by. If you are connecting to these machines from outside the lab, you will get a terminal when you connect. In the terminal, type the commands in the left column. The right column describes what you are doing. When you complete that series of commands, you should be back at your 161 folder. If not, figure out how to get there. Remember that you always need to move the terminal into ~/161 to work on files for this course. Command cd pwd ls ls -l cd 161 cd..!p cd 161!! man pwd Meaning move to your home folder (~sabeach) display the current directory name list files in home (161 should be there) list files, last time changed, size, and permissions move into 161 folder move one folder up file hierarchy repeat most recent command that started with p (pwd) move into 161 folder repeat previous command (this gives you an error message because there is no ~/161/161) display the manual for 'pwd' command; press spacebar to get next page if necessary; press 'q' to quit 6

This picture shows the file system for a student with userid sabeach. Her home directory is ~sabeach (or the full path, /home/students/sabeach) with two subdirectories, 140 and 161. Logging Out: From the menu at the top of the screen, choose System -> Log Out userid. You will be asked to confirm; click the Log Out button. You are logged out when you see the login panel on the screen. Normally, before you leave the lab, you should log out this way. Save any work before logging out. You'll log in again to start the next part of the lab activity. Further Exploration: There are many ways to learn about the system and get help. Explore these outside the lab time: - explore the Help menu - use Applications/Internet/Mozilla FireFox to get a web browser and visit Java sites on the Internet. 7