Variable Scope Brackets, brackets…. brackets. Variable Scope /** * HelloWorld --- program that prints something to the screen. Blanca Polo */

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
Simple Programs Simple Strings Writing some programs Only in Parameters? I/O Gadget.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Your First Java Program: HelloWorld.java
Loops For While Do While. Loops Used to repeat something Loop statement creates and controls the loop.
Using Processing Stream. Predefined Streams System.in InputStream used to read bytes from the keyboard System.out PrintStream used to write bytes to the.
1 Repetition structures Overview while statement for statement do while statement.
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.
Client/Server example. Server import java.io.*; import java.net.*; import java.util.*; public class PrimeServer { private ServerSocket sSoc; public static.
Reading Information From the User Making your Programs Interactive.
OOP&M - laboratory lectures1 OOP&M – LAB2 LABzwei: the Input.
SELECTION CSC 171 FALL 2004 LECTURE 8. Sequences start end.
1 Parameter Passing Revisited Overview l Parameter passing l Passing parameters by value l Passing parameters by reference l Some Examples l Preview: Introduction.
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
Java Review 2. The Agenda The following topics were highlighted to me as issues: –File IO (Rem) –Wrappers (Rem) –Interfaces (Rem) –Asymptotic Notation.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
1 Repetition structures [cont’d] Overview l Nested Loops l Sentinel-Controlled loop l Avoiding Number Format exception.
COMP 14: I/O and Boolean Expressions May 24, 2000 Nick Vallidis.
1 Lecture#8: EXCEPTION HANDLING Overview l What exceptions should be handled or thrown ? l The syntax of the try statement. l The semantics of the try.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
Saravanan.G.
Java Programming: I/O1 Java I/O Reference: java.sun.com/docs/books/tutorial/essential/io/
Introduction to Computer Programming Error Handling.
CS/IS 112 – Week 2 Logic Problem More Java background and basics Values Variables, and operations.
Example 1 :- Handling integer values public class Program1 { public static void main(String [] args) { int value1, value2, sum; value1 = Integer.parseInt(args[0]);
SOFTWARE TECHNOLOGY - I CONSTANTS VARIABLES DATA TYPES.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Program Statements Primitive Data Types and Strings.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/23/2012 and 10/24/2012 -Using Exceptions -Homework 4.
From C++ to Java A whirlwind tour of Java for C++ programmers.
CS61B L02 Using Objects (1)Garcia / Yelick Fall 2003 © UCB Kathy Yelick Handout for today: These lecture notes Computer Science 61B Lecture 2 – Using Objects.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
Java 1.5 The New Java Mike Orsega Central Carolina CC.
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Reading Parameters CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D.
Computer Programming Your First Java Program: HelloWorld.java.
Chapter 2 Clarifications
AKA the birth, life, and death of variables.
Exercise Java programming
Maha AlSaif Maryam AlQattan
Interactive Standard Input/output
Lecture Note Set 1 Thursday 12-May-05
Going from C++ to Java Jayden Navarro.
Java 24th sep /19/2018 CFILT.
Operators Laboratory /11/16.
Yong Choi School of Business CSU, Bakersfield
Tonga Institute of Higher Education
L3. Necessary Java Programming Techniques
L3. Necessary Java Programming Techniques
Exercise 11.1 Write a code fragment that performs the same function as the statement below without using the crash method Toolbox.crash(amount < 0,
CS 180 Assignment 6 Arrays.
class PrintOnetoTen { public static void main(String args[]) {
Scope of variables class scopeofvars {
CSE Module 1 A Programming Primer
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Introductory Java Programming
Exception Handling Contents
Debugging Exercise 00 Try compiling the code samples.
Exception Objects An exception is an abnormal condition that arises in a code sequence at rum time. Exception is a way of signaling serious problem.
Presentation transcript:

Variable Scope Brackets, brackets…. brackets

Variable Scope /** * HelloWorld --- program that prints something to the screen. Blanca Polo */ public class HelloWorld{ public static void main (String arg[ ]){ String s = “Hello World!!!”; System.out.println( s ); }

Variable Scope public class ParseI{ public static void main (String arg[ ])throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); int iNum = 0; String sUserInput = ""; System.out.println("Enter a number please "); sUserInput = br.readLine( ); System.out.println("You typed " + sUserInput); //risky code try{ iNum = Integer.parseInt(sUserInput); System.out.println("Thanks for the number!!! "); } catch(NumberFormatException nfe){ System.out.println("I asked for a number, dummy!!"); } System.out.println(" the end "); } //main } // class

Variable Scope public class ParseI{ public static void main (String arg[ ])throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr) //risky code try{ String sUserInput = ""; System.out.println("Enter a number please "); sUserInput = br.readLine( ); System.out.println("You typed " + sUserInput); int iNum = 0; iNum = Integer.parseInt(sUserInput); System.out.println("Thanks for the number!!! "); } catch(NumberFormatException nfe){ System.out.println("I asked for a number, dummy!!"); System.out.println(”and you typed “+ sUserInput); } System.out.println(" the end "); } //main } // class VarScope.java:22: cannot find symbol symbol : variable sUserInput location: class VarScope System.out.println("and you typed "+ sUserInput); ^ 1 error