L AB #3. System.out.println(“if you have” +eggPerBasket + “egg per basket and” + numberOfBaskets +”baskets, then the total number off eggs is“+totalEggs);

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

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.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
How to Create a Java program CS115 Fall George Koutsogiannakis.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Scanner Pepper With credits to Dr. Siegfried. The Scanner Class Most programs will need some form of input. At the beginning, all of our input will come.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Copyright 2008 by Pearson Education Building Java Programs Chapter 4 Lecture 4-1: Scanner ; if/else reading: , 4.2, 4.6.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Java Overview CS2336: Computer Science II1. First Program public class HelloWorld { public static void main(String args[]) { System.out.println("Hello.
1 Scanner objects. 2 Interactive programs We have written programs that print console output. It is also possible to read input from the console.  The.
Chapter 2 Section 2.2 Console Input Using The Scanner CLASS Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska.
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
Chapter 2 Elementary Programming 1. Introducing Programming with an Example Listing 2.1 Computing the Area of a Circle This program computes the area.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
Console Input & Output CSS 161: Fundamentals of Computing Joe McCarthy 1.
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.
Object Oriented Programming Computer Engineering Department JAVA Programming Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
CPSC1301 Computer Science 1 Overview of Dr. Java.
C OMP 110/401 A PPENDIX : I NSTALLING AND U SING B ARE B ONES D EVELOPMENT E NVIRONMENT ON U NIX Instructor: Prasun Dewan (FB 150,
Debugging Dwight Deugo Nesa Matic
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Mixing integer and floating point numbers in an arithmetic operation.
CHAPTER 5 GC 101 Input & Output 1. INTERACTIVE PROGRAMS  We have written programs that print console output, but it is also possible to read input from.
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 2/4/20161.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
Building Java Programs Chapter 4 Lecture 4-1: Scanner ; cumulative algorithms reading: 3.3 – 3.4, 4.2.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
CompSci 230 S Programming Techniques
Building Java Programs
Chapter 2 Clarifications
Chapter 1 Introduction to Computers, Programs, and Java
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Debugging Dwight Deugo
Eclipse Navigation & Usage.
Building Java Programs
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
INPUT STATEMENTS GC 201.
MSIS 655 Advanced Business Applications Programming
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Building Java Programs
Building Java Programs
Building Java Programs
Debugging Dwight Deugo
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Optional Topic: User Input with Scanner
Presentation transcript:

L AB #3

System.out.println(“if you have” +eggPerBasket + “egg per basket and” + numberOfBaskets +”baskets, then the total number off eggs is“+totalEggs);

-P ROGRAMMING E RRORS

Syntax Errors Detected by the compiler Runtime Errors Causes the program to abort Logic Errors Produces incorrect result P ROGRAMMING E RRORS

public class ShowSyntaxErrors { public static void main(String[] args) { i = 30; System.out.println(i + 4); } S YNTAX E RRORS

public class ShowRuntimeErrors { public static void main(String[] args) { int i = 1 / 0; } R UNTIME E RRORS

L OGIC E RRORS public class ShowLogicErrors { // Determine if a number is between 1 and 100 public static void main(String[] args) { // Prompt the user to enter a number String input = JOptionPane.showInputDialog(null, "Please enter an integer:", "ShowLogicErrors", JOptionPane.QUESTION_MESSAGE); int number = Integer.parseInt(input); // Display the result System.out.println("The number is between 1 and 100, " + "inclusively? " + ((1 <= number) && (100 <=number ))); System.exit(0); }

-C REATING AND E DITING U SING N OTE P AD -C OMPILING AND R UNNING J AVA FROM THE C OMMAND W INDOW

10 C REATING, C OMPILING, AND R UNNING P ROGRAMS

To use NotePad, type notepad Welcome.java from the DOS prompt(from all programs -> Accessories). 11 C REATING AND E DITING U SING N OTE P AD Open NotePad, write your code, save it as Welcome.java directly on c.

Set path to JDK bin directory set path=c:\ProgramFiles\java\jdk1.6.0\bin Set classpath to include the current directory classpath=c:\ProgramFiles\java\jdk1.6.0\bin 12 C OMPILING AND R UNNING J AVA FROM THE C OMMAND W INDOW

Open Dos then: Compile javac Welcome.java Run java Welcome

R EADING STATEMENT

1-R EADING STATEMENT 1. Write a program to read a name and then display the name with the existing greeting. The output should be "Welcome to Computer Programming Name!" where name is the value entered by the user. To read input from the command line, a Scanner object must he used. To use a Scanner object, the Java package java.util must be imported. Add the following line to the beginning of PersonalHello.java: import java.util.*;

public class PersonalHello { public static void main(String[] args) { String name; Scanner keyboard = new Scanner(System.in); System.out.print("What is your name?"); name = keyboard.next( ); System.out.println(" Welcome to Computer Programming! "); System.out.println(name + "!"); } Enter your first name only. Run code again then enter your full name with spaces. What happen?? Now: nextLine( ) Try nextLine( ) method instadeof next( ) compile and run again with your full name. What happen??

Exercise (1): Now try this code: public class PersonalHello { public static void main(String[] args) { String nameF,nameL; Scanner keyboard = new Scanner(System.in); System.out.print("What is your first name?"); nameF = keyboard.next( ); System.out.print("What is your last name?"); nameL = keyboard.next( ); System.out.println(" Welcome to Computer Programming "); System.out.println(nameF+” “+nameL + "!"); } try this: 1- type your first name then press enter, then type your last name 2- type your first name then space then type your last name What is the deference ?

E XERCISE (2): 1. Write a program to read a weight and height from user then calculate his body mass (bodyMass=weight/height 2 ). The output should be “your bodymass= bodyMass",where bodyMass is the result of the equation. nextDouble( );

public class PersonalHello { public static void main(String[] args) { double wieght, height; Scanner keyboard = new Scanner(System.in); System.out.print("What is your weight?"); weight = keyboard.nextDouble(); System.out.print("What is your height?"); height = keyboard.nextDouble(); System.out.println("your bodymass="+ (weight/(height*height))); } 3. Compile and run your modified program using the steps outlined above in the section entitled "Compiling and Executing a Program." 4. Show your lab instructor or assistant your working program.

D EBUGGING

Debugging Step-1 Activate the Line Numbers Go to Windows Preferences General Editor TextEditor Show line Numbers Prepared by Uzma Hashmi

Step-2 Setting Breakpoints To set breakpoints right click in the small left column in your source editor and select toggle break Or, you can double click on the particular place It indicates that we enter the break point It tells the debugger to stop at this point in the code When we do ‘RunAs’ it remains ineffective But when we run ‘DebugAs’ it tells the debugger to stop at the first point and suspends the program before this point Prepared by Uzma Hashmi

Step-3 Start Debugger You can debug your application by selecting your file, which contains a main method Right click it DebugAs Or, Select Run DebugAs Prepared by Uzma Hashmi

Debug Perspective Prepared by Uzma Hashmi

Terminate Ctrl+F2 Resume F8 Step Into F5 F6 Step Over F7 Step Return Prepared by Uzma Hashmi

The Current Stack is displayed in the debug view Stack In the debug mode it keeps the track of how many times debugger use on different intervals In the stack frame with pause symbol, shows where we are in the program in the main body. Initially Stack frame tells where we applied break Prepared by Uzma Hashmi

The editor highlights the first executable line. Prepared by Uzma Hashmi

The outline option on the RHS of the screen in debug mode tells us about the methods in our file and also highlights the method which is active in this case it is main Prepared by Uzma Hashmi

Variables and Breakpoints Views Variables listed with the value and the names and Breakpoints list where the breaks are applied Prepared by Uzma Hashmi

Variables values could be changed to see the effect in execution Changing Variable values Prepared by Uzma Hashmi