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.

Slides:



Advertisements
Similar presentations
Introduction to Programming Java Lab 1: My First Program 11 January JavaLab1.ppt Ping Brennan
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
IT151: Introduction to Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Chapter 1: Introduction
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Chapter 2: Introduction to C++.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 2 Software Tools and Assembly Language Syntax.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Comments are for people Header comments supply basic information about the artifact.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
The Java Programming Language
Sahar Mosleh California State University San MarcosPage 1 System.out.println for console output System.out is an object that is part of the Java language.
Slides prepared by Rose Williams, Binghamton University Chapter 2 Console Input and Output.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Problem of the Day  Why are manhole covers round?
Chapter 2: Java Fundamentals
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
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.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
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.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Sections 5.1 – 5.4 © Copyright by Pearson Education, Inc. All Rights Reserved.
Intro to. Contents These slides describe how one can obtain (download) and use eclipse to build, run, and debug basic Java programs.
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Simple Console Output. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
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.
Wrapper Classes Debugging Interlude 1
Introduction to Java Import Scanner class to use in our program
A variable is a name for a value stored in memory.
Dept of Computer Science University of Maryland College Park
Working with Java.
Class Definitions and Writing Methods
Dialogues and Wrapper Classes
Important terms Black-box testing White-box testing Regression testing
Java Programming: From Problem Analysis to Program Design, 4e
Important terms Black-box testing White-box testing Regression testing
Repetition Chapter 6 12/06/16 & 12/07/16 1 1
Debugging with Eclipse
Advanced Programming Lecture 02: Introduction to C# Apps
Debugging 9/22/15 & 9/23/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Chapter 1: Computer Systems
MSIS 655 Advanced Business Applications Programming
Anatomy of a Java Program
Instructor: Alexander Stoytchev
Debugging with Eclipse
Presentation transcript:

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

Exam I Next week  Th, 2/25/16  M, 2/29/16 Over Chapter 1, , 4.1 and 4.3, eclipse and linux Review material on my website

Class DecimalFormat Class DecimalFormat enables control of output  In java.text package.  Specify a string pattern to describe desired format double val = 1.23; DecimalFormat formatter = new DecimalFormat("0.000"); System.out.println(formatter.format(val)); Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Class DecimalFormat 0 – digit, leading and trailing zeros # -- digit, no leading and trailing zeros % -- percentage $ -- at beginning displays dollar sign Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Class DecimalFormat Figure 4-7 Examples of patterns used with class DecimalFormat Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010

Previous Style Conventions Class names begin with upper case Method names and variable names begin with lower case Braces  eclipse puts open brace on the line with the heading  Line up indentation of the closing brace with whatever it is ending.  End brace commented(optional) Lines within braces indented Skip lines for readability (white space)

More Conventions from 2.10 Each statement on its own line. A blank line can separate groups of statements, but related statements usually have no blank lines between them. Arithmetic operators and = separate by one space. No space precedes an ending semicolon or ( ). Variable/parameter names are descriptive, use at least two words.  exceptions for loop indices (i, j), or math items like point coordinates (x, y).

More Conventions from 2.10 Constants use upper case and underscores (and at least two words) Variables usually defined early (not within code), and initialized to be safe (if practical). Lines of code are typically less than 100 characters wide. Look at GramsToOuncesStyle.java

Questions In the following program give an example of something that is not properly named. Give an example of bad indentation. What is wrong with the println statement?

Copy This Program and Fix the Style public class ShippingCalculator { public static void main (String [] args) { int shipWeightPounds = 10; int shipCostCents; final int FLAT_FEE_CENTS = 75 ;final int centsPerPound=25 ; shipCostCents = FLAT_FEE_CENTS + shipWeightPounds * centsPerPound; System.out.println("Weight(lb): " + shipWeightPounds + ", Flat fee(cents): " + FLAT_FEE_CENTS + ", Cents per pound: " + centsPerPound + ", Shipping cost(cents): " + shipCostCents); return; }

Debugging in Eclipse 2.8 Syntax Errors  Caught by the Editor. Logic Errors  Bad Results  Can use diagnostic prints to examine variables  In eclipse you can exam the contents of variable

Debugging in Eclipse OuncesToGrams Example, 1.5 oz → g 1)Set a break point in the program near a possible bug. Right click in margin left of code Can right click again to untoggle 2)Run the program with “Debug as” Click yes when dialog box appears Gets you into Debug mode 3)Use box in upper right to examine variables.

Debugging in Eclipse 4)Use buttons to execute one statement at a time. Step-into Step-over for java methods 5)Click “Java” on top tool bar to get back to normal mode.

Questions How do you toggle a breakpoint in eclipse? How do you get into Debug mode? Why would you want to examine a variable's contents? What is the difference between step-into and step-over?

Java API 2.7 Google “Java API” Oracle owns the language. Use API to look up a class.  e.g. Scanner Can see what methods it has.

Lab Copy the program on slide #12 into eclipse. Fix style problems in the program. Set a break point in the above program. Use the debugger to examine the shipCostCents variable's contents while the program is executing. Get into a web browser and find the Java API. – Find the method in the String class that lets you know the length of a String.

Exam Next Week Don't forget your notes! Good Luck!