Express Yourself. What is Eclipse?

Similar documents
Structured Programming

CS 170 Java Programming 1. Week 9: Learning about Loops

Express Yourself. Writing Your Own Classes

Slide 1 CS 170 Java Programming 1 Duration: 00:00:49 Advance mode: Auto

Slide 1 CS 170 Java Programming 1 The while Loop Duration: 00:00:60 Advance mode: Auto

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto

Slide 1 CS 170 Java Programming 1 Arrays and Loops Duration: 00:01:27 Advance mode: Auto

Slide 1 CS 170 Java Programming 1 Multidimensional Arrays Duration: 00:00:39 Advance mode: Auto

CS 170 Java Programming 1. Week 10: Loops and Arrays

Slide 1 CS 170 Java Programming 1 Loops, Jumps and Iterators Duration: 00:01:20 Advance mode: Auto

Week 3: Objects, Input and Processing

Slide 1 CS 170 Java Programming 1

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

Express Yourself. The Great Divide

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

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

Course Outline. Introduction to java

5.5.3 Lab: Managing Administrative Settings and Snap-ins in Windows XP

Week 2: Data and Output

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

Slide 1 CS 170 Java Programming 1 More on Strings Duration: 00:00:47 Advance mode: Auto

FrontPage Help Center. Topic: FrontPage Basics

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

Slide 1 CS 170 Java Programming 1 Testing Karel

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

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn

Eclipse Environment Setup

SDKs - Eclipse. SENG 403, Tutorial 2

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

At the shell prompt, enter idlde

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations

CS111: PROGRAMMING LANGUAGE II

Slide 1 Java Programming 1 Lecture 2D Java Mechanics Duration: 00:01:06 Advance mode: Auto

Mehran Sahami Handout #5 CS 106A September 27, 2017 Downloading Eclipse

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

CS 170 Java Programming 1. Week 5: Procedures and Functions

In this Tutorial we present tips and trick for the development enviroment eclipse and the extension MyEclipse.

MYGRAPHICSLAB: ADOBE INDESIGN CS6

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

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

WPS Workbench. user guide. "To help guide you through using the WPS user interface (Workbench) to create, edit and run programs"

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

Slide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 Advance mode: Auto

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

ECE QNX Real-time Lab

APCS Semester #1 Final Exam Practice Problems

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Computer Programming, I. Laboratory Manual. Experiment #6. Loops

3. Hello World! for IDEA. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Slide 1 CS 170 Java Programming 1 Real Numbers Duration: 00:00:54 Advance mode: Auto

CS 170 Java Programming 1. Week 12: Creating Your Own Types

3. NetBeans IDE 6.0. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

CS 170 Java Programming 1. Week 15: Interfaces and Exceptions

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

13 th Windsor Regional Secondary School Computer Programming Competition

Introduction to Software Development (ISD) Week 3

Building Java Programs

We are built to make mistakes, coded for error. Lewis Thomas

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

CS 170 Java Tools. Step 1: Got Java?

Lab #1: A Quick Introduction to the Eclipse IDE

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

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

The Road to CCSv4. Status Update

Smooks Developer Tools Reference Guide. Version: GA

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

Assignment 1. Application Development

CONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Laboratory 1: Eclipse and Karel the Robot

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

PART 1. Eclipse IDE Tutorial. 1. What is Eclipse? Eclipse Java IDE

Java Coding 3. Over & over again!

CS 201 Software Development Methods Spring Tutorial #1. Eclipse

Lab Exercise 1 Using EGit and JUnit

COMP-202 Unit 4: Programming with Iterations

with TestComplete 12 Desktop, Web, and Mobile Testing Tutorials

Basic Concepts. Launching MultiAd Creator. To Create an Alias. file://c:\documents and Settings\Gary Horrie\Local Settings\Temp\~hh81F9.

Introduction to IntelliJ

Warmup : Name that tune!

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

Content Author's Reference and Cookbook

A Quick Tour GETTING STARTED WHAT S IN THIS CHAPTER?

Excel 2010 Level 1: The Excel Environment

Corel Ventura 8 Introduction

Table of Contents. 1. Creating a Microsoft Excel Workbook...1 EVALUATION COPY

Tutorial 2 - Welcome Application Introducing, the Visual Studio.NET IDE

BlueJ Demo. Topic 1: Basic Java. 1. Sequencing. Features of Structured Programming Languages

Fundamentals: Expressions and Assignment

1.00 Lecture 2. What s an IDE?

Chapter Goals. Contents LOOPS

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Introduction to Java & Fundamental Data Types

In this lab, you will build and execute a simple message flow. A message flow is like a program but is developed using a visual paradigm.

Table of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited

Programming with Java

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Transcription:

CS 170 Java Programming 1 Eclipse and the for Loop A Professional Integrated Development Environment Introducing Iteration Express Yourself Use OpenOffice or Word to create a new document Save the file as LastFirst_ic13 Replace LastFirst with your actual name Put your name and today's date at the top of the sheet Title it "CS 170 In-class Exercise 13" Exercise 1: As we start working with Eclipse, you'll create a customized workspace to store your preferences and programs. Copy the starter workspace folder from Q: and drop it in cs170home. Shoot a screen-shot in Windows Explorer. What is Eclipse? A full-featured professional development environment Originally developed by IBM, now open-source Platform and framework: plug-ins for different features Written in Java, so it runs on Unix, Mac and the PC Free and open-source so you can modify it Editor, compiler, debugger and many different features Exercise 2: Start Eclipse from the Programming folder on the desktop. Shoot a screen-shot of the window. Stephen Gilbert, 2007-2075 1

The Workspace The Eclipse workspace contains your files, projects, IDE customizations and preferences Default lab workspace configuration is U:\eclipse At home, though, you'll see this dialog at first Switch Workspaces Switch workspaces with File->Switch Workspace Can put on a thumb drive and carry around with you The Java Perspective Close the Welcome screen (first item on Help menu) Stephen Gilbert, 2007-2075 2

Perspectives Combination of windows and layout devoted to a specific task is called a perspective Exercise 3: click Open Perspective button, choose Other from drop-down. Choose Resource and then Dr. Java. Shoot a screen-shot of each. Switch back to Java perspective. Views Individual windows in a perspective are called views. You can add or remove a view from any perspective. Arranging Views You can also move, float and dock individual views Stephen Gilbert, 2007-2075 3

Working with Existing Code How do you use Eclipse to work with existing code? We'll see by importing some code from Chapter 6 Click New Java Project icon or from File menu Must be in Java Perspective Creating a Project Name ic13, Create new project in workspace Configure defaults in Project Layout (use Project root) Importing code allows you to copy existing code into the project Choose Import from File menu Choose File System, click Next Importing Code Stephen Gilbert, 2007-2075 4

Importing Files Locate Q:\faculty5\sgilbert\cs170\code\week09 Select invest2 folder Click OK Select 2 files Click Finish Exercise 4: snap a picture of window after importing files Package Explorer and Editor Files appear in Package Explorer window Open default package and double-click source files Tabbed windows Code folding Editor Features Exercise 5: Collapse All in Investment.java and snap a pic. Then restore. Stephen Gilbert, 2007-2075 5

Format the code in both files using Source menu Two outline views allow you to quickly navigate to methods, or fields Outline Views Use Run button menu on active editing window, or right-click file in Project Explorer, choose Run As Running Your Program Exercise 6: Run the program and snap a pic. What happens if you try to run Investment.java? Eclipse Features Other features of Eclipse we'll use Syntax errors caught as you type Kind of like auto-spell-check in your word processor Code is automatically compiled when saved Don't have to remember packages to import The Quick-Fix feature helps you fix problems Content-Assistant helps you write code Wizards walk you through common tasks Code is automatically formatted I'll introduce these as we go through the semester Stephen Gilbert, 2007-2075 6

Investment.java Calculates investment value over n years (or number of years to reach a particular value). Can't just multiply (or divide) by percentage Invest $ 1,000 @ 10% APR, compounded annually First year you earn $100 (10% of $1,000) Next year you earn $110 (10% of $1,100) Investment class Fields: balance, rate, years Constructor: initializes all fields Accessors: getbalance() and getyears() InvestmentRunner Create an investment, wait n years, get the balance The Future Value Using a for loop to calculate the value after n years Stephen Gilbert, 2007-2075 7

Introducing Loops What Is Iteration? A CS term that means repeating a set of actions Also called repetition or looping Statements used in iteration are called loops Loops are flow-of-control statements similar to if Like the if statement, a loop evaluates a condition If the condition is true, a group of actions are performed If the condition is false, the actions are skipped Iteration and Selection Iteration is not the same as selection, however A loop returns to its test after performing its actions If the test is still true, then the actions are performed again A selection statement only performs its actions once You cannot replace a loop with a selection statement Stephen Gilbert, 2007-2075 8

Java and Iteration Java has three loops: while, do-while, and for Each designed to work best in a particular situation One difference is where the test is made Test at the bottom Test at the top { } // // Loop Body Loop Test Loop Test { // // Loop Body } Loop Classification Where tested is not the best method of classification Doesn't provide any empirical guidance Better to ask how each loop is controlled Two basic methods of loop control Simplest method relies on a counter Called counting or counted loops "Repeat these actions 10 times" More complex loops test the occurrence of a particular event, or combination of events. These are called indefinite or indeterminate loops Counted Loops A counted loop is simplest kind of loop The loop bounds is controlled by a counter Use it to for "perform this action 10 times" Java's for loop specializes in this for (int count = 0; count < 10; count++) { System.out.println( count= +count); } Stephen Gilbert, 2007-2075 9

The for Loop Syntax The for loop has both a header and body (like if) Header has 3 expressions: initialize, test, and update Initialization Expression The initialization expression Executed once, before the loop is entered Always executed, regardless of the test Usually used to declare your counter variable for (int counter = 0; ; ) { // Can use counter here } // Cannot use counter here The Test Expression Works just like the test in an if statement If true, loop body is entered. If false, it is not. Always evaluated at least once Also ends with a semicolon (like initialization) for (int counter = 0; counter < 10; ) { // Can use counter here } // Cannot use counter here Stephen Gilbert, 2007-2075 10

The Update Expression Executed after the body of the loop is finished Always executed one fewer times than test Usually used to update your counter Not followed by a semicolon for (int counter = 0; counter < 10; counter++) { // Can use counter here } // Cannot use counter here Express Yourself Exercise 7: import EX_13_7 and EX_13_7Test Open EX_13_7 and complete the code for the doublechar() method. The method takes one String parameter and returns a new String with every character in the first doubled. Questions you should ask? Can we figure out how many times we need to loop? If so, then we can use a counter-controlled for loop What output is needed? What do we do inside the loop? Testing your Code Open EX_13_7Test and use Quick Fix to configure Exercise 7: Run tests and snap a pic of all tests passing Stephen Gilbert, 2007-2075 11

Loops and Strings Some tips to help you process Strings with loops Use the length() method to visit every character Use the charat() or substring() method to extract The indexof() method is also useful int len = str.length(); for (int i = 0; i < len; i++) { char ch = str.charat(i); String strch = str.substring(i, i+1); } Another Exercise Exercise 8: import EX_13_8 and EX_13_8Test Open EX_13_8 and complete the code for the counthi() method. The method takes one String parameter and returns the number of times that the String "hi" appears inside the first String. Use substring(i, i+2) and the equals() method Don't want to go through entire string Can end up looking "past end" which causes a crash No need for special case Right-click EX_13_8Test and run tests. Shoot a pic. Writing New Code Real power of Eclipse comes with code from scratch We'll see how to create several kinds of programs Start with a simple console program that uses a counted loop to produce this output when run: Enter a positive integer: 3 1 I love Java programming!! 2 I love Java programming!! 3 I love Java programming!! Printed this message 3 times. The sum of the numbers from 1 to 3 is 6. Stephen Gilbert, 2007-2075 12

Code Templates You can configure "custom comments" Apply to types, classes, specific kinds of methods, etc. Let's modify the "file", "type" and "method" comments The Comments Exercise 9: Snap a pic Here's the code I've added. Customize of the completed yours. File code template Click the New Java Class toolbar button Name: LoveJava Main method checked Generate comments checked Finish A New Class Stephen Gilbert, 2007-2075 13

Generated File Exercise 10: Snap a pic of the generated comments. Then, update and show me another. Using Quick-Fix In the main() method, create a Scanner, like this: Scanner keyboard = new Scanner(System.in); Code Templates Next we need to ask the user to enter a number. Eclipse lets us create snippets or templates to reduce our typing. Let's create one for System.out.print Stephen Gilbert, 2007-2075 14

Fill out the dialog like this: The sop Template Using sop Type sop and then Control + Space together Inserts template snippet into your code Exercise 11: Create a code template named sopl for System.out.println(). Method Help Use the Scanner to find out how many times to loop int num = keyboard. Typing a dot after an object name brings up a list of instance methods that you can use Use arrows, mouse, continue typing, Enter to select Stephen Gilbert, 2007-2075 15

Exercise 12: Fix the error below by creating a variable sum, and adding up the numbers in the loop. Snap a pic. Finishing Up Now, add a for loop that goes from 1 to n Print your message inside the loop body After the loop print the two "summary" lines The for loop is a general purpose loop Don't have to use a simple, incrementing counter You don't have to count up: for (int i = 10; i > 0; i--) { } Counting Down Exercise 13: Open the file StringReverse.java and use a for loop to reverse the characters in the input String. Run and shoot a screenshot. Remember Strings are numbered starting with 0 You don't have to count by one: for (int i = 0; i < 50; i += 5) { } Counting by Steps Works like BASIC's STEP command Not restricted to a constant step, like BASIC for (int i = 2; i < 10000 ; i * = 2 ) { System.out.println(i); } Stephen Gilbert, 2007-2075 16