User Interfaces File I/O and Exceptions (c) IDMS/SQL News

Slides:



Advertisements
Similar presentations
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Advertisements

INHERITANCE BASICS Reusability is achieved by INHERITANCE
Exceptions Don’t Frustrate Your User – Handle Errors KR – CS 1401 Spring 2005 Picture – sysprog.net.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Text File I/O. Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with an editor are called.
File I/O and Exceptions File I/O Exceptions Throwing Exceptions Try statement and catch / finally clauses Checked and unchecked exceptions Throws clause.
Lecture 27 Exceptions COMP1681 / SE15 Introduction to Programming.
Exception Handling.  What are errors?  What does exception handling allow us to do?  Where are exceptions handled?  What does exception handling facilitate?
1 Lecture 4 Exception Handling. 2 Exception-Handling Fundamentals An exception is an abnormal condition that arises in a code sequence at run time A Java.
©2004 Brooks/Cole Chapter 6 Methods. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Using Methods We've already seen examples of using methods.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Exceptions Problems with error reporting so far –Either ignored exceptions or terminated program on first error. –Error handling and regular code mixed.
Exceptions Problems with error reporting so far –Either ignored exceptions or terminated program on first error. –Error handling and regular code mixed.
Java Review 2. The Agenda The following topics were highlighted to me as issues: –File IO (Rem) –Wrappers (Rem) –Interfaces (Rem) –Asymptotic Notation.
Chapter 11: Handling Exceptions and Events J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Fourth.
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Week 14 - Monday.  What did we talk about last time?  Image manipulation  Inheritance.
Example 1 :- Handling integer values public class Program1 { public static void main(String [] args) { int value1, value2, sum; value1 = Integer.parseInt(args[0]);
Java and C++, The Difference An introduction Unit - 00.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
Exceptions. Exception Abnormal event occurring during program execution Examples –Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Java I/O Java I/O is based on input streams and output streams. All input and output are defined in the Java IO package. 1.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 11: Handling Errors; File Input/Output.
IBM TSpaces Lab 1 Introduction. Summary TSpaces Overview Basic Definitions Basic primitive operations Reading/writing tuples in tuplespace HelloWorld.
1 Web Based Programming Section 8 James King 12 August 2003.
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
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.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Introduction to Programming G50PRO University of Nottingham Unit 11 : Files Input/Ouput Paul Tennent
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Odds and Ends. CS 21a 09/18/05 L14: Odds & Ends Slide 2 Copyright © 2005, by the authors of these slides, and Ateneo de Manila University. All rights.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
Pengantar OOP Class-Java. 2 Software Development Tools Using Sun Java SDK alone Source File(s) (.java) Programmer Compiler (javac) Class File(s) (.class)
Java Programming: From Problem Analysis to Program Design, 4e Chapter 11 Handling Exceptions and Events.
Week 14 - Monday.  What did we talk about last time?  Inheritance.
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Exceptions. Exception  Abnormal event occurring during program execution  Examples Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
Files Review For output to a file: –FileOutputStream variable initialized to filename (String) and append/not append (boolean) –PrintWriter variable initialized.
OOP Basics Classes & Methods (c) IDMS/SQL News
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
Garbage Collection It Is A Way To Destroy The Unused Objects. To do so, we were using free() function in C language and delete() in C++. But, in java it.
Introduction to programming in java
A Java Program: // Fig. 2.1: Welcome1.java // Text-printing program.
Week 14 - Wednesday CS 121.
I/O Basics.
Accessing Files in Java
Testing and Exceptions
CS Week 10 Jim Williams, PhD.
An Introduction to Java – Part I, language basics
COMPUTER 2430 Object Oriented Programming and Data Structures I
L3. Necessary Java Programming Techniques
Web Design & Development Lecture 7
Exception Handling in Java
Lecture 11 Objectives Learn what an exception is.
Exceptions.
Exceptions.
CMSC 202 Exceptions.
Java Programming: From Problem Analysis to Program Design, 4e
Streams A stream is an object that enables the flow of data between a program and some I/O device or file If the data flows into a program, then the stream.
Presentation transcript:

User Interfaces File I/O and Exceptions (c) IDMS/SQL News

File I/O Simple Example (c) 2 User Interfaces 4 In Java one can create at least 3 types of programs Windows AppletServlet Java Class A fourth can be applications run from Command Prompt (=DOS)

File I/O Simple Example (c) 3 Different User Interfaces 4 User interface can vary depending upon code execution is at client or server side 4 Here we take the simplest case of File I/O at the client side 4 Programs will be run from the command prompt (=dos window)

File I/O Simple Example (c) 4 I/O - File Based in Java ð We have already seen one form of output – print statement ð System.out.print(“Hello Printer”); ð In reality we are using the print method of the class PrintStream ð System.out is an instance of the class PrintStream ð Note: see tream.html

File I/O Simple Example (c) 5 Output file  We can define a file using class called FileOutputStream and PrintStream of package java.io  FileOutputStream fout= new FileOutputStream ("Writef1.out");  PrintStream myOutput = new PrintStream(fout);  Now one can write to the file “Write1.out” using myOutput.print commands!

File I/O Simple Example (c) 6 import java.io.*; // Class definition and implementation. public class Writef1 { public static void main (String args[]) { try { FileOutputStream fout= new FileOutputStream ("Writef1.out"); PrintStream myOutput = new PrintStream(fout); if (args.length == 0) { myOutput.println("Hello Nobody "); myOutput.println("Try with some arguments ");} else { for (int i=0; i < args.length; i = i+1) { myOutput.println(args[i]);}} } // try ends here catch (IOException e) { System.out.println("Error=" + e); System.exit(1); } // end of catch }

File I/O Simple Example (c) 7 Exceptions  try and catch statements  Try { code} catch (exception_type xyz1) { code to process this...}  There can be multiple catch blocks  like our ”call IDMS-STATUS”!  When doing file I/O exception must be coded  Note: There are other ways to handle exceptions in Java like a method throws....xyzException etc

File I/O Simple Example (c) 8 Exception Example Code class Except1 { public static void main (String args[]) { int i = 0; String [] greetings = { " Merry Christmas", " God Jul ", " Hyvää Joulua"}; try{ for (i=0; i < 4; i = i+1) { System.out.println(greetings[i]);} } // end of try catch (ArrayIndexOutOfBoundsException e ) { System.out.println(" "); System.out.println(" Check Index Variable Value"); System.out.println(" ");} }}