Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Chapter 2 Review Questions
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Introduction to Computers and Programming Lecture 3: Variables and Input Professor: Evan Korth New York University.
Primitive Data Types byte, short, int, long float, double char boolean Are all primitive data types. Primitive data types always start with a small letter.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Begin Java having used Alice Pepper - Some slides from Alice in Action with Java.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
COMP 110 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.
COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Java Fundamentals Asserting Java Chapter 2: Introduction to Computer Science ©Rick Mercer.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 2: Java Fundamentals
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Introduction to Programming
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
More about Java Chapter 2 9/8 & 9/9 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
CSC 1051 M.A. Papalaskari, Villanova University Algorithms Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Chapter 1 09/04/13. Change Your Password  The command is: passwd In the lab first do : ssh -Y onyx  You will have to see me to change it, if you forget.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Chapter 2 Wrap Up 2/18/16 & 2/22/16. Topics Review for Exam I DecimalFormat More Style Conventions Debugging using eclipse The Java API.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Class Definitions and Writing Methods Chapter 3 3/31/16 & 4/4/16.
Class Definitions: The Fundamentals Chapter 6 3/30/15 & 4/2/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Foundations of Programming: Java
Wrapper Classes Debugging Interlude 1
Dept of Computer Science University of Maryland College Park
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Class Definitions and Writing Methods
Something about Java Introduction to Problem Solving and Programming 1.
INPUT STATEMENTS GC 201.
BIT115: Introduction to Programming
Repetition Chapter 6 12/06/16 & 12/07/16 1 1
Writing Methods.
Branching Chapter 5 11/14/16 & 11/15/
Introduction to Java Brief history of Java Sample Java Program
CSC 1051 – Data Structures and Algorithms I
Presentation transcript:

Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Check zyBooks Completion Click on the boxes for each section.

Assignment See my website for the new assignment.

Chapter Topics A Simple Java Program Output Comments Input Algorithms Errors and Warnings Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Output Two commands System.out.println outputs newline character after the output System.out.print leaves the cursor on the same line. Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Displaying Text System.out.print(“Black”); System.out.println(“bird”); System.out.println(“sings.”); Output? | Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Comments Documents the program Comments Begin line with double slash //  Ends with the end of the line. Span multiple lines between slash-star combination. /* */ Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

A Simple Java Program A program is needed to figure out how far a jet can travel in a given number of hours and the speed at which it is flying. Write a program to set the time in whole hours and the rate of travel in MPH. Output the distance traveled. Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

public class Flight { /* This program finds the distance a jet travels. */ public static void main(String[] args) { int timeHrs = 5; int speedMPH = 600; int distance = timeHrs * speedMPH; System.out.println(distance + " miles traveled."); }//end main method }//end Flight class

A Simple Java Program Note definition of a class Begins and ends with brace { … } Note declaration of main method Where the execution begins. public static void main(String[] args) Also begins and ends with brace { … } Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Assignment Statement int timeHrs = 5; int timeHrs declares a variable. o A variable is a memory location. timeHrs = 5; sets timeHrs to 5. int distance = timeHrs * speedMPH; o D oes the multiplication on the right first. o Assigns the answer to distance.

Notes on Output + operator in print statements  Add numbers (5+6)  Concatenate Strings. "to" + "day" --> "today" 15 + " inches" --> 15 inches Strings that span multiple lines Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

return statement The return statement is optional in the main method. I don't use it.

Questions What is the difference between a print and a println? Where do the statements in the main method belong? Give an example of an assignment statement.

Try a Program Today is John’s birthday. Write a program that sets a variable to his birth year and another variable to the current year. Output his age today. Sample output: John is 21 today.  Before writing the program, write an algorithm. o Algorithm is instruction in English-like code, pseudocode.

Input

Keyboard Input Use Scanner class from Java Class Library Must use import statement: import java.util.Scanner; Next, create Scanner object Scanner keyboard = new Scanner(System.in); Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010 Package nameClass name

Keyboard Input Keyboard is an object which can perform methods. Use method to receive data from keyboard, store in variable int x = keyboard.nextInt(); Let’s change the Age program so that it asks the user for the current year and the birth year. Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Find the Number of People Write a program to figure how many people are touring Yosemite Park today. Ask for the number of people one tour bus can hold and the number of buses in the park. Output the total number of passengers touring. Start here Wed.

Login and Password If you don't have a login, send me . Contact me if you forget your password. Change your password to something easy to remember.  ssh -Y onyx  Login again  passwd  Nothing shows while you are typing.

Number of Credits Earned Write a program to input the number of credits that a student earned during each of two semesters at Boise State. Add up the credits then output the total. Write an algorithm with a partner Along with your partner, code the program using eclipse. – Print it and hand in a copy with both names on it.

Questions What type of object is used to handle input? What package does the Scanner belong to?

Steps Figure 1-5 Steps involved in developing a Java program Imagine! Java: Programming Concepts in Context by Frank M. Carrano, © Pearson Education – Prentice Hall, 2010

Errors Syntax Error  Violation of programming language rules.  Caught by eclipse.  Program will not compile. Logic Error  Error while program runs.  For example, incorrect computation. distance = rate/time;

Errors and Warnings Error prevents program from compiling  Red x in margin Warning means something might be wrong.  Yellow icon in margin.  Try to get rid of it.

Questions What kind of error is it? 1.Eclipse shows a red x in the margin because a quotation isn’t closed. 2.A program to convert Fahrenheit to Celcius gives incorrect results. 3.Eclipse shows a yellow icon in the margin because a variable hasn’t been used yet.