CS 121 Intro to Programming:Java - Lecture 11 Announcements
|
|
- Louise Holmes
- 7 years ago
- Views:
Transcription
1 CS 121 Intro to Programming:Java - Lecture 11 Announcements Next Owl assignment up, due Friday (it s short!) Programming assignment due next Monday morning Preregistration advice: More computing? Take 191B, or - if you re really thriving in this class (come see me about this) Final exam: 12/19, 8 AM
2 Topics for today: File IO - How to read from, write to external files Exceptions will also get some attention
3 import java.util.scanner; import java.io.*; public class DisplayFile{ public static void main(string[] args) throws IOException { String filename; Scanner namereader = new Scanner(System.in); System.out.println("Enter a file name"); filename = namereader.nextline(); Scanner scan = new Scanner(new FileReader(fileName)); while(scan.hasnext()){ System.out.println(scan.nextLine()); scan.close();
4 import java.util.scanner; import java.io.*; public class Echo{ String filename; // external file name Scanner scan; // reads from external file public Echo(String f) throws IOException { filename = f; scan = new Scanner(new FileReader(fileName));
5 public void readlines(){ while(scan.hasnext()){ processline(scan.nextline()); scan.close(); public void processline(string line){ System.out.println(line);
6 import java.util.scanner; import java.io.*; public class ReadDriver{ public static void main(string[] args) { throws IOException String filename; Scanner namereader = new Scanner(System.in); System.out.println("Enter a file name"); filename = namereader.nextline(); Echo e = new Echo(fileName); e.readlines();
7 import java.io.*; public class LineCount extends Echo{ private int count = 0; public LineCount(String f) throws IOException { super(f); public void processline(string line){count++; public void reportlinecount(){ System.out.println("Line count: " + count);
8 import java.io.*; import java.util.*; public class WriteFile{ public static void main(string[] args) throws IOException { String filename; System.out.println("Enter a file name. It will hold output"); Scanner namereader = new Scanner(System.in); filename = namereader.nextline(); PrintWriter writer = new PrintWriter(fileName); Scanner scan = new Scanner(System.in); String s = " "; // a String of length 1 System.out.println("Enter text, end with 2 returns"); while(s.length() > 0){ s = scan.nextline(); writer.println(s);
9 writer.close(); // now echo the file back to the console Echo e = new Echo(fileName); System.out.println("Here comes the echo"); System.out.println(); e.readlines();
10 Our next example ilatlstrues a bizzare anodecte that ciurctaled on the web seevral years ago, and casued wiesrpdead giglges among all who saw it. The story corecnns an exereipmnt by Brtiish reehrsaecrs that put forawrd the foiwlolng arguemnt: it turns out that if you take a seibsnle body of text, exartct each word, leave the first two and last two letters of every word unoctuhed, but then raondmly rernaarge the rest - that is, the mildde, then the enuisng text is colpmteely unbdasdearnlte.
11 import java.util.*; import java.io.*; public class ScrambleDriver{ public static void main(string[] args) throws IOException { Scanner scan = new Scanner(System.in); System.out.println("enter file name"); String filename = scan.next(); TextScramble scram = new TextScramble(fileName); scram.readlines();
12 import java.io.*; import java.util.*; public class TextScramble extends Echo{ Random r = new Random(); String blank = " "; public TextScramble(String f) throws IOException { super(f);
13 public void processline(string line){ String s = blank; String answer = ""; char[] mid; StringTokenizer str = new StringTokenizer(line); while(str.hasmoretokens()){ s = str.nexttoken(); if (s.length() < 6) answer = answer+ s + blank; else { // carve up the token.. String front = s.substring(0,2); String back = s.substring(s.length() - 2, s.length()); String middle = s.substring(2,s.length() -2); mid = middle.tochararray(); // make middle an array shuffle(mid); // shuffle middle = new String(mid); // transform back to a String answer = answer +front + middle + back + blank; // end loop processing all tokens in line System.out.println(answer);
14 Java has a shadow system for handling errors: Exceptions This is a system of classes and objects that employ special machinery for detectings errors and shifting responsibilites for handling these problems Java recognized two kinds of errors: Unchecked exceptions: errors that occur because of flaws in logical thinking on the part of the programmer (e.g. division by 0) Checked exceptions: errors that can be expected to occur, and may occur despite your best efforts to avoid them (trying to read from a file that doesn t exist)
15 public class Except0{ public static void main(string[] args){ int k; int a = 3; ; int b = 0; k = a/b; Java reports: Exception in thread "main" java.lang.arithmeticexception: / by zero ÏÏ Ï at Except0.main(Except0.java:7)
16 Java has special machinery, the try/catch construction, for dealing with exceptions (handling exceptions) An exception is handled if your code detects the error and takes some action in response -- as in the next example.
17 public static void main(string[] args){ int k; int a = 3; int b = 0; try{ k = a/b; catch(arithmeticexception e) { System.out.println( e); Java reports: Ïjava.lang.ArithmeticException: / by zero ÏÏ Ï
18 public class Except3{ public static void main(string[] args){ String s = "98.6"; int n; try{ n = Integer.parseInt(s); System.out.println(n*n); catch(exception e) { e.printstacktrace();
19 Ïjava.lang.NumberFormatException: For input string: "98.6" ÏÏ Ï at java.lang.numberformatexception.forinput String(NumberFormatException.java:48) ÏÏ Ï at java.lang.integer.parseint(integer.java:456) ÏÏ Ï at java.lang.integer.parseint(integer.java:497) ÏÏ Ï at Except3.main(Except3.java:8) ÏÏ Ï
20 A more realistic example - you are supposed to enter an integer, representing your name (the program then reports your age for next year..) Some interaction: Ïenter your age ¼¼ Ï39e ÏÏ ÏBad input. 39e is not an integer. You must input an integer Ïenter your age ¼¼ Ï39 ÏÏ Ïnext year you will be 40 ÏÏ Ï
21 import java.io.*; import java.util.*; public class IntegerInput{ public static void main(string[] args){ int n = -1; Scanner scan = new Scanner(System.in); while (n < 0) { System.out.println("enter your age"); try { if (scan.hasnextint()) n = scan.nextint(); else { // non integer submitted String userinput = scan.next(); throw new Exception("Bad input. "+ userinput + " is not an integer. You must input an integer");
22 catch (Exception e) { System.out.println(e.getMessage()); System.out.println("next year you will be " + (n + 1)); What does throw do: it presents an exception object of the indicated kind at a new location in the program..
23 What if you enter a negative number? Not handled very well (No message).. enter your age ¼¼ Ï-39 enter your age
24 One way to handle this: make a new kind of Exception.. public class NegativeException extends Exception{ public NegativeException() { ; public NegativeException(String msg){ super(msg); And then:
25 while (n < 0) { System.out.println("enter your age"); try { if (scan.hasnextint()) n = scan.nextint(); else { String userinput = scan.next(); throw new Exception("Bad input. "+ userinput + "is not an integer. You must input an integer"); if (n < 0) throw new NegativeException();
26 catch (NegativeException e) { System.out.println("age must be >= 0"); catch (Exception e) { System.out.println(e.getMessage()); // end while System.out.println("next year you will be " + (n + 1)); Notice: two kinds of exceptions, more specific one first
27 One more example: You have a data file of numerical data, integers, one per line It may contain errors (deep space information?) You want to compute the average value of the entries - but you re happy just to skip over the bad data
28 Here is nums.txt e 10 Here s the output: ÏBad Entry: 3e Ï40.0
29 import java.io.*; import java.util.*; public class NumberReader { String filename; int sum = 0; int count = 0; Scanner scan; Handle IOEX when I m called public NumberReader(String f) throws IOException { filename = f; scan = new Scanner(new FileReader(fileName)); public void readlines(){while(scan.hasnext()){ processline(scan.nextline()); scan.close();
30 public void processline(string line){ try{ int num = Integer.parseInt(line); sum += num; count++; catch(exception e) {System.out.println("Bad Entry: " + line); public void printresult(){ System.out.println((double)sum/count);
31 public class NumDriver{ public static void main(string[] args){ try{ NumberReader num = new NumberReader("nums.txt"); num.readlines(); num.printresult(); catch(exception e) {e.printstacktrace();
32 This is tacky: public class ReadDriver{ public static void main(string[] args) { throws IOException String filename; Scanner namereader = new Scanner(System.in); System.out.println("Enter a file name"); filename = namereader.nextline(); Echo e = new Echo(fileName); e.readlines();
33 public class ReadDriver{ public static void main(string[] args) { try{ String filename; Scanner namereader = new Scanner(System.in); System.out.println("Enter a file name"); filename = namereader.nextline(); Echo e = new Echo(fileName); e.readlines(); Catch(IOException e){system.out.println(e);
File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)
File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
More informationUsing Files as Input/Output in Java 5.0 Applications
Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead
More informationCourse Intro Instructor Intro Java Intro, Continued
Course Intro Instructor Intro Java Intro, Continued The syllabus Java etc. To submit your homework, do Team > Share Your repository name is csse220-200830-username Use your old SVN password. Note to assistants:
More information13 File Output and Input
SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to
More informationReading Input From A File
Reading Input From A File In addition to reading in values from the keyboard, the Scanner class also allows us to read in numeric values from a file. 1. Create and save a text file (.txt or.dat extension)
More information1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius
Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1
More informationLine-based file processing
Line-based file processing reading: 6.3 self-check: #7-11 exercises: #1-4, 8-11 Hours question Given a file hours.txt with the following contents: 123 Kim 12.5 8.1 7.6 3.2 456 Brad 4.0 11.6 6.5 2.7 12
More informationIntroduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
More informationBasics of Java Programming Input and the Scanner class
Basics of Java Programming Input and the Scanner class CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/
More informationIntroduction to Java. CS 3: Computer Programming in Java
Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods
More informationSystem.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :
Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class
More informationCS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
More informationChulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
More informationExplain the relationship between a class and an object. Which is general and which is specific?
A.1.1 What is the Java Virtual Machine? Is it hardware or software? How does its role differ from that of the Java compiler? The Java Virtual Machine (JVM) is software that simulates the execution of a
More informationChapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
More informationJAVA ARRAY EXAMPLE PDF
JAVA ARRAY EXAMPLE PDF Created By: Umar Farooque Khan 1 Java array example for interview pdf Program No: 01 Print Java Array Example using for loop package ptutorial; public class PrintArray { public static
More informationqwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
More informationTopic 11 Scanner object, conditional execution
Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright
More informationAP Computer Science File Input with Scanner
AP Computer Science File Input with Scanner Subset of the Supplement Lesson slides from: Building Java Programs, Chapter 6 by Stuart Reges and Marty Stepp (http://www.buildingjavaprograms.com/ ) Input/output
More informationPreet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75
Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship
More informationChapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
More informationInstall Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html
CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install
More informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
More informationObject-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
More informationPart I. Multiple Choice Questions (2 points each):
Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******
More informationSimple Java I/O. Streams
Simple Java I/O Streams All modern I/O is stream-based A stream is a connection to a source of data or to a destination for data (sometimes both) An input stream may be associated with the keyboard An
More informationSample CSE8A midterm Multiple Choice (circle one)
Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names
More informationpublic static void main(string[] args) { System.out.println("hello, world"); } }
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
More informationBuilding Java Programs
Building Java Programs Chapter 4 Lecture 4-1: Scanner; if/else reading: 3.3 3.4, 4.1 Interactive Programs with Scanner reading: 3.3-3.4 1 Interactive programs We have written programs that print console
More informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
More informationUsing Two-Dimensional Arrays
Using Two-Dimensional Arrays Great news! What used to be the old one-floor Java Motel has just been renovated! The new, five-floor Java Hotel features a free continental breakfast and, at absolutely no
More informationHomework/Program #5 Solutions
Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the
More informationAP Computer Science Java Mr. Clausen Program 9A, 9B
AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will
More informationScanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.
Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1-5.2 self-check: #8-17 exercises: #3-6, 10, 12 videos: Ch. 5 #1-2 1 The Random class A Random object generates pseudo-random* numbers.
More informationCreating a Simple, Multithreaded Chat System with Java
Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate
More informationTranslating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
More informationFirst Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
More informationCompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement
CompSci 125 Lecture 08 Chapter 5: Conditional Statements Chapter 4: return Statement Homework Update HW3 Due 9/20 HW4 Due 9/27 Exam-1 10/2 Programming Assignment Update p1: Traffic Applet due Sept 21 (Submit
More informationD06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch16 Files and Streams PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for
More informationLecture J - Exceptions
Lecture J - Exceptions Slide 1 of 107. Exceptions in Java Java uses the notion of exception for 3 related (but different) purposes: Errors: an internal Java implementation error was discovered E.g: out
More informationAP Computer Science Static Methods, Strings, User Input
AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because
More informationJDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I
More informationChapter 3. Input and output. 3.1 The System class
Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use
More informationThe following program is aiming to extract from a simple text file an analysis of the content such as:
Text Analyser Aim The following program is aiming to extract from a simple text file an analysis of the content such as: Number of printable characters Number of white spaces Number of vowels Number of
More informationBuilding a Multi-Threaded Web Server
Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous
More informationMULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
More informationD06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch15 Exception Handling PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for
More informationChapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output
Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used
More informationInteractive Applications (CLI) and Math
Interactive Applications (CLI) and Math Interactive Applications Command Line Interfaces The Math Class Example: Solving Quadratic Equations Example: Factoring the Solution Reading for this class: L&L,
More informationQuestion1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?
CSCI 312 - DATA COMMUNICATIONS AND NETWORKS FALL, 2014 Assignment 4 Working as a group. Working in small gruops of 2-4 students. When you work as a group, you have to return only one home assignment per
More informationLesson: All About Sockets
All About Sockets http://java.sun.com/docs/books/tutorial/networking/sockets/index.html Page 1 sur 1 The Java TM Tutorial Start of Tutorial > Start of Trail Trail: Custom Networking Lesson: All About Sockets
More informationCOSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19
Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4
More informationScanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard
INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard
More informationArrays. Introduction. Chapter 7
CH07 p375-436 1/30/07 1:02 PM Page 375 Chapter 7 Arrays Introduction The sequential nature of files severely limits the number of interesting things you can easily do with them.the algorithms we have examined
More informationCS 1302 Ch 19, Binary I/O
CS 1302 Ch 19, Binary I/O Sections Pages Review Questions Programming Exercises 19.1-19.4.1, 19.6-19.6 710-715, 724-729 Liang s Site any Sections 19.1 Introduction 1. An important part of programming is
More informationCSE 8B Midterm Fall 2015
Name Signature Tutor Student ID CSE 8B Midterm Fall 2015 Page 1 (XX points) Page 2 (XX points) Page 3 (XX points) Page 4 (XX points) Page 5 (XX points) Total (XX points) 1. What is the Big-O complexity
More informationIntroduction to Programming
Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck
More informationJ a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
More informationWA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.
WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25
More informationB.Sc (Honours) - Software Development
Galway-Mayo Institute of Technology B.Sc (Honours) - Software Development E-Commerce Development Technologies II Lab Session Using the Java URLConnection Class The purpose of this lab session is to: (i)
More informationProgramming Languages CIS 443
Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception
More informationProgramming Fundamentals I CS 110, Central Washington University. November 2015
Programming Fundamentals I CS 110, Central Washington University November 2015 Next homework, #4, was due tonight! Lab 6 is due on the 4 th of November Final project description + pseudocode are due 4th
More informationSection 6 Spring 2013
Print Your Name You may use one page of hand written notes (both sides) and a dictionary. No i-phones, calculators or any other type of non-organic computer. Do not take this exam if you are sick. Once
More informationFiles and input/output streams
Unit 9 Files and input/output streams Summary The concept of file Writing and reading text files Operations on files Input streams: keyboard, file, internet Output streams: file, video Generalized writing
More informationWHAT ARE PACKAGES? A package is a collection of related classes. This is similar to the notion that a class is a collection of related methods.
Java Packages KNOWLEDGE GOALS Understand what a package does. Organizes large collections of Java classes Provides access control for variables and methods using the modifier 'protected' Helps manage large
More informationMasters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
More informationOBJECT ORIENTED PROGRAMMING LANGUAGE
UNIT-6 (MULTI THREADING) Multi Threading: Java Language Classes The java.lang package contains the collection of base types (language types) that are always imported into any given compilation unit. This
More informationQuestion R11.3. R11.3 How do you open a file whose name contains a backslash, like c:\temp\output.dat?
Chapter 11 Question R11.1: R11.1 What happens if you try to open a file for reading that doesn t exist? What happens if you try to open a file for writing that doesn t exist? The system throws an IOException
More informationCS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
More informationThe Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)
Binary I/O streams (ascii, 8 bits) InputStream OutputStream The Java I/O System The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing Binary I/O to Character I/O
More informationWeek 1: Review of Java Programming Basics
Week 1: Review of Java Programming Basics Sources: Chapter 2 in Supplementary Book (Murach s Java Programming) Appendix A in Textbook (Carrano) Slide 1 Outline Objectives A simple Java Program Data-types
More informationHandout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
More informationjava.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner
java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources
More informationCS170 Lab 11 Abstract Data Types & Objects
CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the
More informationCS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: add adday. main.
CS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: happy appyhay want antway add adday two consonants: the ethay main translate translateword
More informationYou are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:
Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from
More informationEvent-Driven Programming
Event-Driven Programming Lecture 4 Jenny Walter Fall 2008 Simple Graphics Program import acm.graphics.*; import java.awt.*; import acm.program.*; public class Circle extends GraphicsProgram { public void
More informationWord Count Code using MR2 Classes and API
EDUREKA Word Count Code using MR2 Classes and API A Guide to Understand the Execution of Word Count edureka! A guide to understand the execution and flow of word count WRITE YOU FIRST MRV2 PROGRAM AND
More information(Eng. Hayam Reda Seireg) Sheet Java
(Eng. Hayam Reda Seireg) Sheet Java 1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long. What changes must be made to the program so it works for a rectangle
More informationwww.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk
CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling
More informationUnit 6. Loop statements
Unit 6 Loop statements Summary Repetition of statements The while statement Input loop Loop schemes The for statement The do statement Nested loops Flow control statements 6.1 Statements in Java Till now
More informationJava Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).
Java Network Programming The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol). The DatagramSocket class uses UDP (connectionless protocol). The java.net.socket
More informationProgramming and Data Structures with Java and JUnit. Rick Mercer
Programming and Data Structures with Java and JUnit Rick Mercer ii Chapter Title 1 Program Development 2 Java Fundamentals 3 Objects and JUnit 4 Methods 5 Selection (if- else) 6 Repetition (while and for
More informationChapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.
Chapter 20 Streams and Binary Input/Output Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved. 20.1 Readers, Writers, and Streams Two ways to store data: Text
More informationJAVA Program For Processing SMS Messages
JAVA Program For Processing SMS Messages Krishna Akkulu The paper describes the Java program implemented for the MultiModem GPRS wireless modem. The MultiModem offers standards-based quad-band GSM/GPRS
More informationCrash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
More informationLOOPS CHAPTER CHAPTER GOALS
jfe_ch04_7.fm Page 139 Friday, May 8, 2009 2:45 PM LOOPS CHAPTER 4 CHAPTER GOALS To learn about while, for, and do loops To become familiar with common loop algorithms To understand nested loops To implement
More informationAssignment 4 Solutions
CSCI 312 - DATA COMMUNICATIONS AND NETWORKS FALL, 2014 Assignment 4 Solutions Working as a pair Working in pairs. When you work as a pair you have to return only one home assignment per pair on a round.
More informationWRITING DATA TO A BINARY FILE
WRITING DATA TO A BINARY FILE TEXT FILES VS. BINARY FILES Up to now, we have looked at how to write and read characters to and from a text file. Text files are files that contain sequences of characters.
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationMIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION
MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION 1. Write a loop that computes (No need to write a complete program) 100 1 99 2 98 3 97... 4 3 98 2 99 1 100 Note: this is not the only solution; double sum
More informationRationale for Software Architecture
Rationale for Software Architecture Bedir Tekinerdoğan University of Twente Department of Computer Science Enschede, The Netherlands e:mail bedir@cs.utwente.nl http://www.cs.utwente.nl/~bedir/ http://trese.cs.utwente.nl/taosad/
More informationToken vs Line Based Processing
Token vs Line Based Processing Mixing token based processing and line based processing can be tricky particularly on the console Problems I saw in program 5: console.next()
More information6.1. Example: A Tip Calculator 6-1
Chapter 6. Transition to Java Not all programming languages are created equal. Each is designed by its creator to achieve a particular purpose, which can range from highly focused languages designed for
More informationComp 248 Introduction to Programming
Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been
More informationDivision of Informatics, University of Edinburgh
CS1Bh Lecture Note 20 Client/server computing A modern computing environment consists of not just one computer, but several. When designing such an arrangement of computers it might at first seem that
More informationDesigning with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219
Designing with Exceptions CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Testing vs. Debugging Testing Coding Does the code work properly YES NO 2 Debugging Testing
More information