OBJECT ORIENTED PROGRAMMING. Course 3 Loredana STANCIU Room B616
|
|
- Hugh Jenkins
- 5 years ago
- Views:
Transcription
1 OBJECT ORIENTED PROGRAMMING Course 3 Loredana STANCIU loredana.stanciu@aut.upt.ro Room B616
2 Summary of course 2 Primitive data types Variables, arrays Operators Expressions Statements and blocks Control flow statements Classes and objects
3 The primitive data types Primitive types to define variables: int i = 2; float j; double d;
4 The Numbers classes Wrapper classes for each of the primitive data types Wrap the primitive type in an object Often, the wrapping is done by the compiler The compiler boxes a primitive type in its wrapper class (unboxes the object into a primitive type) Integer x, y; x = 12; y = 15; System.out.println(x+y);
5 Java.lang
6 The Numbers classes All of the numeric wrapper classes are subclasses of the abstract class Number
7 The Numbers classes All of the numeric wrapper classes are subclasses of the abstract class Number
8 The Numbers classes Why to use a Number object rather than a primitive? As an argument of a method that expects an object To use constants defined by the class, such as MIN_VALUE and MAX_VALUE, that provide the upper and lower bounds of the data type. To use class methods for various conversions
9 Methods Implemented by all Subclasses of Number Converts the value of this Number object to the primitive data type returned. byte bytevalue() short shortvalue() int intvalue() long longvalue() float floatvalue() double doublevalue()
10 Methods Implemented by all Subclasses of Number Compares this Number object to the argument. int compareto(byte anotherbyte) int compareto(double anotherdouble) int compareto(float anotherfloat) int compareto(integer anotherinteger) int compareto(long anotherlong) int compareto(short anothershort)
11 Methods Implemented by all Subclasses of Number boolean equals(object obj) Determines whether this number object is equal to the argument. The methods return true if the argument is not null and is an object of the same type and with the same numeric value.
12 Conversion Methods, Integer Class static int parseint(string s) Returns an integer (decimal only). String tostring() Returns a String object representing the value of this Integer. static String tostring(int i) Returns a String object representing the specified integer.
13 Conversion Methods, Integer Class static Integer valueof(int i) Returns an Integer object holding the value of the specified primitive. static Integer valueof(string s) Returns an Integer object holding the value of the specified string representation.
14 Formatting Numeric Print Output The java.io package includes a PrintStream class: the System.out object represents the standard output (the screen) can be used to invoke every printing method described in PrintStream
15 Formatting Numeric Print Output The java.io package includes a PrintStream class System.out.println(String s) System.out.format(String format, Object... args) System.out.printf(String format, Object... args) System.out.format(Locale l, String format, Object... args)
16 Formatting Numeric Print Output The conversion characters Conversion Argument Description category c, C character The result is a Unicode character s string The result is a string d integral The result is formatted as a decimal integer e, E floating point The result is formatted as a decimal number in computerized scientific notation f floating point The result is formatted as a decimal number g, G floating point The result is formatted using computerized scientific notation or decimal format, depending on the precision and the value after rounding n line separator The result is the platform-specific line separator
17 Formatting Numeric Print Output System.out.format("The value of the float variable is %f, " + " the value of the integer " + " variable is %d, and the " + "string is %s", floatvar, intvar, stringvar); matter.html
18 Formatting Numeric Print Output int i = ; System.out.format("The value of i is: %d%n", i); The output: The value of i is: float floatvar = 3.14; System.out.format(Locale.FRANCE, "The value of the float variable is %f%n", floatvar); The output: The value of the float variable is: 3,14
19 Formatting Numeric Print Output To use a Local constant the java.util package should be imported into your program Extra information regarding the subject: s/api/java/util/locale.html
20 Formatting Numeric Print Output long n = ; System.out.format("%d%n", n); System.out.format("%08d%n", n); System.out.format("%+8d%n", n); System.out.format("%,8d%n", n); 461,012 System.out.format("%+,8d%n", n); +461,012
21 Formatting Numeric Print Output double pi = Math.PI; System.out.format("%f%n", pi); System.out.format("%.3f%n", pi); System.out.format("%10.3f%n", pi); System.out.format("%-10.3f%n", pi); System.out.format(Locale.FRANCE, "%- 10.4f%n%n", pi); 3,1416 import java.util.*;
22 Advanced mathematical computation import java.lang.math.*; int abs(float f) int round(float f) int min(int arg1, int arg2) int max(int arg1, int arg2) double exp(double d) double log(double d) double pow(double base, double exponent) double sqrt(double d)
23 Advanced mathematical computation double sin(double d) double cos(double d) double tan(double d) double asin(double d) double acos(double d) double atan(double d) double todegrees(double d) double toradians(double d)
24 Advanced mathematical computation
25 Advanced mathematical computation Random Numbers random() method returns a pseudo-randomly selected number between 0.0 and 1.0 (exclusively) int number = (int)(math.random() * 10); Two defined constants E the base of natural logarithms PI the ratio of the circumference of a circle to its diameter
26 Summary of numbers Wrapper classes Byte, Double, Float, Integer, Long, or Short to wrap a number of primitive type in an object The Number classes include constants and useful class methods To format a string containing numbers for output, you can use the printf() or format() methods in the PrintStream class The Math class contains a variety of class methods for performing mathematical functions
27 Problem Compute the following expression: y 3x 2x 1 The value of x should be randomly generated as a number less than 100. x and y are floating point numbers. Print on the screen, formatted in Romanian style, the values of x and y using 8 digits out of which 2 are used to represent the floating point part
28 Solution import java.util.*; class Solution{ public static void main(string[] arg){ double x = (double)(math.random() * 100); double y = 3*Math.pow(x,2) + 2*x +1; System.out.format(Local.FRANCE, For x = %8.2f,y = %8.2f,x,y); } } Output: For x= 81,59 y= 20136,18
29 Characters char primitive type Character wrapper class The Character class is immutable, so that once it is created, a Character object cannot be changed. Creating an Character object: Character ch = new Character('a'); autoboxing or unboxing Character test(character c) {...} char c = test('x'); java.lang.character
30 Characters Usefull methods boolean isletter(char ch) boolean isdigit(char ch) boolean iswhitespace(char ch) boolean isuppercase(char ch) boolean islowercase(char ch) char touppercase(char ch) char tolowercase(char ch) tostring(char ch)
31 Characters Escape sequences (preceded by a \ ) Escape Description Sequance \t Insert a tab in the text at this point. \b Insert a backspace in the text at this point. \n Insert a newline in the text at this point. \r Insert a carriage return in the text at this point. \f Insert a formfeed in the text at this point. \ Insert a single quote character in the text at this point. \ Insert a double quote character in the text at this point. \\ Insert a backslash character in the text at this point.
32 Characters When do you need an escape sequences? If you want to print the following message: She said "Hello!" to me. You should write System.out.println("She said \"Hello!\" to me.");
33 Problem Consider an array of characters containing a sentence. Knowing that the words are separated by space, count how many words are there. Also count the names (starting with a capital letter). For simplicity, we consider all the characters being letters.
34 Solution public class SolutionChar{ public static void main(string[] arg){ int count=0, countname=0; char[] array = {'A','n','a',' ','i','s',' ','h','e','r','e'}; for(int i=0;i<array.length;i++) if((character.isspace(array[i])) (i==array.length-1)) count++; else if (Character.isUpperCase(array[i])) countname++; System.out.printf("There are %d words and %d Names %n", count, countname); }} Output: There are 3 words and 1 Names
35 Strings A sequence of characters objects in the Java programming language How to create a string? String greeting = "Hello world!"; String s = new String(greeting); char[] c={'h','e','l','l','o','.'}; String S = new String(c);
36 String
37 Strings The String class is immutable The methods used on strings creates other strings accessor methods methods used to obtain information about an object String palindrome = "Dot saw I was Tod"; int len = palindrome.length();
38 Strings Reverse a palindrome char[] tempchararray = new char[len]; char[] chararray = new char[len]; for (int i = 0; i < len; i++) { tempchararray[i] = palindrome.charat(i); } for (int j = 0; j < len; j++) { chararray[j] = tempchararray[len j]; } String reversepalindrome = new String(charArray); System.out.println(reversePalindrome); Output: dot saw I was tod
39 Strings Concatenate strings string1.concat(string2); "My name is ".concat("ana"); "Hello," + " world" + "!" to span lines in source files String s="now is the time + " of roses.";
40 Converting Between Numbers and Strings Converting Strings to Numbers Number.valueOf() float a = (Float.valueOf(args[0]) ).floatvalue(); float b = (Float.valueOf(args[1]) ).floatvalue(); Number.parsePrimitive() float a = Float.parseFloat(args[0]); float b = Float.parseFloat(args[1]);
41 Converting Between Numbers and Strings Converting Numbers to Strings int i; String s1 = "" + i; String s2 = String.valueOf(i); int i; double d; String s3 = Integer.toString(i); String s4 = Double.toString(d);
42 Converting Between Numbers and Strings The number of digits before and after the decimal point public class ToStringDemo { public static void main(string[] args) { } } double d = ; String s = Double.toString(d); int dot = s.indexof('.'); System.out.println(dot + " digits before decimal point."); System.out.println( (s.length() - dot - 1) + " digits after decimal point.");
43 Manipulating Characters in a String String apal = "Niagara. O roar again!"; char achar = apal.charat(9);
44 Manipulating Characters in a String String apal = "Niagara. O roar again!"; String r =apal.substring(11,15);
45 Manipulating Characters in a String Get the character from a certain index String charat(int index) Get the substring between two indexes String substring(int beginindex, int endindex) Get the substring from a certain index until the end of string String substring(int beginindex)
46 Searching for Characters and Substrings in a String Splits a string using a separator into an array of strings String[] split(string regex) Removes leading and trailing white space String trim() String tolowercase() String touppercase()
47 Searching for Characters and Substrings in a String int indexof(int ch) int lastindexof(int ch) int indexof(int ch, int fromindex) int lastindexof(int ch, int fromindex) int indexof(string str) int lastindexof(string str) int indexof(string str, int fromindex) int lastindexof(string str, int fromindex) boolean contains(charsequence s)
48 Searching for Characters and Substrings in a String public class Filename { private String fullpath; private char pathseparator, extensionseparator; public Filename(String str, char sep, char ext) { fullpath = str; pathseparator = sep; extensionseparator = ext; } public String extension() { int dot = fullpath.lastindexof(extensionseparator); return fullpath.substring(dot + 1); }
49 Searching for Characters and Substrings in a String public String filename() { int dot = fullpath.lastindexof(extensionseparator); int sep = fullpath.lastindexof(pathseparator); return fullpath.substring(sep + 1, dot); } public String path() { int sep = fullpath.lastindexof(pathseparator); return fullpath.substring(0, sep); } }
50 Searching for Characters and Substrings in a String String fpath = "/home/mem/index.html"; Filename myhomepage = new Filename(fpath, '/', '.'); Extension = html Filename = index
51 Replacing Characters and Substrings into a String String replace(char oldchar, char newchar) String replaceall(string regex, String replacement) String replacefirst(string regex, String replacement)
52 Comparing Strings and Portions of Strings boolean endswith(string suffix) boolean startswith(string prefix) int compareto(string anotherstring) int comparetoignorecase(string str) boolean equals(object anobject) boolean equalsignorecase(string anotherstring)
53 Problem Search into a string a substring, both received as arguments when running the program. Return the beginning position. Consider a string containing, separated through ;, the name, the price and the quantity of a product. Extract them and perform the necessary type transformations.
54 Solution P1 public class SolutionStr1{ public static void main(string[] arg){ if(arg.length>=2){ String s1=arg[0]; String s2=arg[1]; int i; if((i=s1.indexof(s2))==-1) System.out.printf("\"%s\" is not included in \"%s\" %n", s2, s1); else System.out.printf("\"%s\" is included in \"%s\" starting position %d%n", s2, s1, i); } else System.out.println("Not enough arguments"); }}
55 Solution P2 public class SolutionStr2{ public static void main(string[] arg){ String s1="bread;3.5;52"; String[] array=s1.split(";"); String name=array[0]; double price=double.valueof(array[1]); int quantity = Integer.valueOf(array[2]); }} System.out.printf("Product: %s, %f, %d", name, price, quantity);
56 The Java I/O System Applications need to process some input and produce some output based on that input In Java, java.io package allows the input and output of a program primarily focused on input and output to files, network streams, internal memory buffer import java.io.*;
57 The Java I/O System I/O operations based on streams flows of data you can either read from, or write to typically connected to a data source, or data destination has no concept of an index of the read or written data cannot typically move forth and back in a stream are typically byte based Input streams Output streams
58 The Java I/O System To process data from a stream you need: Open the stream Process the data until the end of the stream (while) Close the stream
59 The Java I/O System Standard I/O System.in is an InputStream object typically connected to keyboard input of console programs System.out is a PrintStream object outputs the data you write to it to the console System.err is a PrintStream object it is normally only used to output error texts
60 The Java I/O System Input and Output - Source and Destination The terms "input" and "output" can sometimes be a bit confusing Java's IO package concerns with: the reading of raw data from a source the writing of raw data to a destination The typical sources and destinations of data: Files Pipes Network Connections In-memory Buffers (e.g. arrays) System.in, System.out, System.error
61 The Java I/O System A program that needs to read data an input stream or reader A program that needs to write data an output stream or writer An InputStream or Reader is linked to a source of data. An OutputStream or Writer is linked to a destination of data.
62 The Java I/O System Java IO Purposes and Features File Access Network Access Internal Memory Buffer Access Inter-Thread Communication (Pipes) Buffering Filtering Parsing Reading and Writing Text (Readers / Writers) Reading and Writing Primitive Data (long, int etc.) Reading and Writing Objects
63 The Java I/O System
64 The Java I/O System Some Java IO classes
65 The Java I/O System Reading text lines BufferedReader readline() Reads from an input stream until the line end Returns a reference to a String without the line end or null IOException is throw if no reading done The constructor needs an object of InputStreamReader FileInputStream if reading from a file System.in if reading from the console
66 The Java I/O System BufferedReader r_in = new BufferedReader(new InputStreamReader(new FileInputStream(file_name))); BufferedReader r_in = new BufferedReader(new InputStreamReader (System.in)); line = r_in.readline(); while(line!= null) {Do something line = r_in.readline();} r_in.close();
67 The Java I/O System The PrintStream class: Enables the writing of formatted data to an underlying OutputStream Contains the print()/println() to print a string Contains the powerful format() and printf() methods The constructor needs an object of FileOutputStream (write a file as a stream of bytes)
68 The Java I/O System PrintStream w_out = new PrintStream (new FileOutputStream(file_name)); w_out.println( ); w_out.print(true); w_out.print((int) 123); w_out.print((float) ); w_out.printf(locale.uk, "Text + data: %1$", 123); w_out.close();
69 The Java I/O System Streams and Readers / Writers need to be closed properly r_in.close( ); w_out.close( ); public static void main (String[ ] arg) throws IOException { }
70 The Java I/O System
71 The Java I/O System Scanner Can parse primitive types and strings using regular expressions Breaks its input into tokens using a delimiter pattern, which by default matches whitespace Has various next methods to convert the tokens Scanner sc = new Scanner(System.in); int i = sc.nextint(); Scanner sc = new Scanner(System.in).useDelimiter( );
72 The Java I/O System Scanner Scanner sc = new Scanner(new File("myNumbers")); while (sc.hasnextlong()) { long along = sc.nextlong(); } System.out.println("Enter your username: "); Scanner scanner = new Scanner(System.in); String username = scanner.nextline(); System.out.println("Your username is " + username);
73 The Java I/O System Scanner Problems: a scanning operation may block waiting for input. is not safe for multithreaded use without external synchronization. doesn t work well reading strings and numbers with the same scanner Import java.util.scanner
74 References The Java Tutorials. Learning the Java Language. data/index.html Java IO Tutorial. Java Scanner /java/util/scanner.html
Strings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects.
Strings Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and
More informationCreating Strings. String Length
Strings Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and
More informationStrings, Strings and characters, String class methods. JAVA Standard Edition
Strings, Strings and characters, String class methods JAVA Standard Edition Java - Character Class Normally, when we work with characters, we use primitive data types char. char ch = 'a'; // Unicode for
More informationWe now start exploring some key elements of the Java programming language and ways of performing I/O
We now start exploring some key elements of the Java programming language and ways of performing I/O This week we focus on: Introduction to objects The String class String concatenation Creating objects
More informationOverloaded Methods. Sending Messages. Overloaded Constructors. Sending Parameters
Overloaded Methods Sending Messages Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Initialization & Cleanup 2 Overloaded Constructors Sending Parameters accessor method 3 4 Sending Parameters
More informationPrimitive Data Types: Intro
Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types
More informationObject-Oriented Programming
Data structures Object-Oriented Programming Outline Primitive data types String Math class Array Container classes Readings: HFJ: Ch. 13, 6. GT: Ch. 13, 6. Đại học Công nghệ - ĐHQG HN Data structures 2
More informationStrings. Strings and their methods. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics
Strings Strings and their methods Produced by: Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list Primitive Types: char Object Types: String Primitive vs Object Types
More information"Hello" " This " + "is String " + "concatenation"
Strings About Strings Strings are objects, but there is a special syntax for writing String literals: "Hello" Strings, unlike most other objects, have a defined operation (as opposed to a method): " This
More informationJAVA NUMBERS, CHARS AND STRINGS
JAVA NUMBERS, CHARS AND STRINGS It turned out that all Workstation in the classroom are NOT set equally. This is why I wil demonstrate all examples using an on line web tool http://www.browxy.com/ Please
More informationA variable is a name for a location in memory A variable must be declared
Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;
More informationUsing Java Classes Fall 2018 Margaret Reid-Miller
Using Java Classes 15-121 Fall 2018 Margaret Reid-Miller Today Strings I/O (using Scanner) Loops, Conditionals, Scope Math Class (random) Fall 2018 15-121 (Reid-Miller) 2 The Math Class The Math class
More informationLesson 4 Utility classes: Math, String, I/O
Lesson 4 Utility classes: Math, String, I/O Programming Grade in Computer Engineering Outline 1. Math class 2. Wrapper classes 3. String management 4. Input and output Printing on the screen Reading from
More informationClass Library java.lang Package. Bok, Jong Soon
Class Library java.lang Package Bok, Jong Soon javaexpert@nate.com www.javaexpert.co.kr Object class Is the root of the class hierarchy. Every class has Object as a superclass. If no inheritance is specified
More informationMathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University
Mathematical Functions, Characters, and Strings CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Static methods Remember the main method header? public static void
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination Wednesday, December 16, 2009 Examiners: Mathieu Petitpas
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination Thursday, December 11, 2008 Examiners: Mathieu Petitpas [Section 1] 14:00
More informationMathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University
Mathematical Functions, Characters, and Strings CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Static methods Remember the main method header? public static void
More informationCOMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string
COMP 202 Built in Libraries and objects CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Objects and Built in Libraries 1 Classes and Objects An object is an
More informationFaculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination Thursday, March 11, 2010 Examiners: Milena Scaccia
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Mathematical Functions Java provides many useful methods in the Math class for performing common mathematical
More informationMore on variables and methods
More on variables and methods Robots Learning to Program with Java Byron Weber Becker chapter 7 Announcements (Oct 12) Reading for Monday Ch 7.4-7.5 Program#5 out Character Data String is a java class
More informationSimple Java Input/Output
Simple Java Input/Output Prologue They say you can hold seven plus or minus two pieces of information in your mind. I can t remember how to open files in Java. I ve written chapters on it. I ve done it
More informationClasses and Objects Part 1
COMP-202 Classes and Objects Part 1 Lecture Outline Object Identity, State, Behaviour Class Libraries Import Statement, Packages Object Interface and Implementation Object Life Cycle Creation, Destruction
More informationCS 251 Intermediate Programming Java I/O Streams
CS 251 Intermediate Programming Java I/O Streams Brooke Chenoweth University of New Mexico Spring 2018 Basic Input/Output I/O Streams mostly in java.io package File I/O mostly in java.nio.file package
More informationChapter 3: Using Classes and Objects
Chapter 3: Using Classes and Objects CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 3: Using Classes and Objects CS 121 1 / 51 Chapter 3 Topics
More informationAny serious Java programmers should use the APIs to develop Java programs Best practices of using APIs
Ananda Gunawardena Java APIs Think Java API (Application Programming Interface) as a super dictionary of the Java language. It has a list of all Java packages, classes, and interfaces; along with all of
More informationLecture 11.1 I/O Streams
21/04/2014 Ebtsam AbdelHakam 1 OBJECT ORIENTED PROGRAMMING Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 2 Outline I/O Basics Streams Reading characters and string 21/04/2014 Ebtsam AbdelHakam
More informationChapter 4 Mathematical Functions, Characters, and Strings
Chapter 4 Mathematical Functions, Characters, and Strings Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited 2015 1 Motivations Suppose you need to estimate
More informationObjec&ves. Review. Standard Error Streams
Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 Review What are benefits of excep&ons What principle of Java do files break if we re not careful? What class
More informationJava characters Lecture 8
Java characters Lecture 8 Waterford Institute of Technology January 31, 2016 John Fitzgerald Waterford Institute of Technology, Java characters Lecture 8 1/33 Presentation outline Estimated duration presentation
More informationFaculty of Science COMP-202B - Introduction to Computing I (Winter 2009) - All Sections Final Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) - All Sections Final Examination Wednesday, April 29, 2009 Examiners: Mathieu Petitpas
More informationAppendix 3. Description: Syntax: Parameters: Return Value: Example: Java - String charat() Method
Appendix 3 Java - String charat() Method This method returns the character located at the String's specified index. The string indexes start from zero. public char charat(int index) index -- Index of the
More informationStrings, StringBuffer, StringBuilder
Strings, StringBuffer, StringBuilder STRINGS, STRINGBUFFER, STRINGBUILDER... 1 1. What is a string... 1 String() IMMUTABLE... 2 2. using the new operator to invoke the constructor in the String class...
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2010) - All Sections Final Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2010) - All Sections Final Examination Wednesday, December 8, 2010 Examiners: Maja Frydrychowicz
More informationToday s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO. Understanding Board
Ananda Gunawardena Today s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO Lab 1 Objectives Learn how to structure TicTacToeprogram as
More informationI/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O
I/O 10-7-2013 I/O in Java I/O streams vs. Reader/Writer HW#3 due today Reading Assignment: Java tutorial on Basic I/O public class Swimmer implements Cloneable { public Date geteventdate() { return (Date)
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination Tuesday, November 3, 2009 Examiners: Mathieu Petitpas
More informationJava Programming Lecture 10
Java Programming Lecture 10 Alice E. Fischer February 21 2012 Alice E. Fischer () Java Programming - L10... 1/19 February 21 2012 1 / 19 Outline 1 Encryption 2 Wrapper Classes 3 Unicode and the Character
More informationToday s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO
Today s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO Ananda Gunawardena Objects and Methods working together to solve a problem Object Oriented Programming Paradigm
More informationAssoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All This chapter discusses class String, from the java.lang package. These classes provide the foundation for string and character manipulation
More informationStrings. Strings and their methods. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics
Strings Strings and their methods Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list Primitive Types: char Object Types: String Primitive
More informationByte and Character Streams. Reading and Writing Console input and output
Byte and Character Streams Reading and Writing Console input and output 1 I/O basics The io package supports Java s basic I/O (input/output) Java does provide strong, flexible support for I/O as it relates
More informationSimple Java Reference
Simple Java Reference This document provides a reference to all the Java syntax used in the Computational Methods course. 1 Compiling and running... 2 2 The main() method... 3 3 Primitive variable types...
More informationAssoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All Advanced Java This chapter discusses class String, class StringBuilder and class Character from the java.lang package. These classes provide
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types
More informationSTUDENT LESSON A10 The String Class
STUDENT LESSON A10 The String Class Java Curriculum for AP Computer Science, Student Lesson A10 1 STUDENT LESSON A10 The String Class INTRODUCTION: Strings are needed in many programming tasks. Much of
More informationTEXT-BASED APPLICATIONS
Objectives 9 TEXT-BASED APPLICATIONS Write a program that uses command-line arguments and system properties Write a program that reads from standard input Write a program that can create, read, and write
More informationBuilding Strings and Exploring String Class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Lecture Notes K.Yellaswamy Assistant Professor CMR College of Engineering & Technology Building Strings and Exploring
More informationJava Input/Output. 11 April 2013 OSU CSE 1
Java Input/Output 11 April 2013 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter
More informationLecture Notes K.Yellaswamy Assistant Professor K L University
Lecture Notes K.Yellaswamy Assistant Professor K L University Building Strings and Exploring String Class: -------------------------------------------- The String class ------------------- String: A String
More informationFaculty of Science COMP-202A - Foundations of Computing (Fall 2012) - All Sections Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Foundations of Computing (Fall 2012) - All Sections Midterm Examination November 7th, 2012 Examiners: Daniel Pomerantz [Sections
More informationIT101. File Input and Output
IT101 File Input and Output IO Streams A stream is a communication channel that a program has with the outside world. It is used to transfer data items in succession. An Input/Output (I/O) Stream represents
More informationFormatted Output Pearson Education, Inc. All rights reserved.
1 29 Formatted Output 2 OBJECTIVES In this chapter you will learn: To understand input and output streams. To use printf formatting. To print with field widths and precisions. To use formatting flags in
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationCS-140 Fall Binghamton University. Methods. Sect. 3.3, 8.2. There s a method in my madness.
Methods There s a method in my madness. Sect. 3.3, 8.2 1 Example Class: Car How Cars are Described Make Model Year Color Owner Location Mileage Actions that can be applied to cars Create a new car Transfer
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationJava: Learning to Program with Robots
Java: Learning to Program with Robots Chapter 07: More on Variables and Methods Chapter Objectives After studying this chapter, you should be able to: Write queries to reflect the state of an object Use
More informationPIC 20A Number, Autoboxing, and Unboxing
PIC 20A Number, Autoboxing, and Unboxing Ernest Ryu UCLA Mathematics Last edited: October 27, 2017 Illustrative example Consider the function that can take in any object. public static void printclassandobj
More informationCOMP-202 Unit 8: Basics of Using Objects
COMP-202 Unit 8: Basics of Using Objects CONTENTS: Concepts: Classes and Objects Creating and Using Objects Introduction to Basic Java Classes (String, Scanner, ArrayList,...) Introduction (1) As we know,
More informationObject Oriented Software Design
Object Oriented Software Design I/O subsystem API Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 10, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction to Java
More informationObject Oriented Software Design
Object Oriented Software Design I/O subsystem API Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 10, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction to Java
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 EggBasketEnhanced { public static void main(string[]
More informationF1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept
F1 A Java program Ch 1 in PPIJ Introduction to the course The computer and its workings The algorithm concept The structure of a Java program Classes and methods Variables Program statements Comments Naming
More informationChapter 10. File I/O. Copyright 2016 Pearson Inc. All rights reserved.
Chapter 10 File I/O Copyright 2016 Pearson Inc. All rights reserved. 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,
More informationSOFTWARE DEVELOPMENT 1. Strings and Enumerations 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)
SOFTWARE DEVELOPMENT 1 Strings and Enumerations 2018W (Institute of Pervasive Computing, JKU Linz) CHARACTER ENCODING On digital systems, each character is represented by a specific number. The character
More informationFormatting Output & Enumerated Types & Wrapper Classes
Formatting Output & Enumerated Types & Wrapper Classes Quick review of last lecture September 8, 2006 ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev
More informationLab 14 & 15: String Handling
Lab 14 & 15: String Handling Prof. Navrati Saxena TA: Rochak Sachan String Handling 9/11/2012 22 String Handling Java implements strings as objects of type String. Once a String object has been created,
More informationתוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת
תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת A Typical Program Most applications need to process some input and produce some output based on that input The Java IO package (java.io) is to make that possible
More informationCHAPTER 4 MATHEMATICAL FUNCTIONS, CHARACTERS, STRINGS
CHAPTER 4 MATHEMATICAL FUNCTIONS, CHARACTERS, STRINGS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH INTRODUCTION TO JAVA PROGRAMMING, LIANG (PEARSON 2014) MATHEMATICAL FUNCTIONS Java
More informationMore on Strings. String methods and equality. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Compu<ng and Mathema<cs h=p://www.wit.
More on Strings String methods and equality Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Compu
More informationCSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI
CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are
More informationJava Intro 3. Java Intro 3. Class Libraries and the Java API. Outline
Java Intro 3 9/7/2007 1 Java Intro 3 Outline Java API Packages Access Rules, Class Visibility Strings as Objects Wrapper classes Static Attributes & Methods Hello World details 9/7/2007 2 Class Libraries
More informationWeek 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O
Week 12 Streams and File I/O Overview of Streams and File I/O Text File I/O 1 I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or a file
More informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationProgrammierpraktikum
Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 22 10/25/2012 09:08 AM Java - Basic Data Types 2 of 22 10/25/2012 09:08 AM primitive data
More informationEng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2124) Lab 2 String & Character Eng. Mohammed Abdualal String Class In this lab, you have
More informationAgenda & Reading. Python Vs Java. COMPSCI 230 S Software Construction
COMPSCI 230 S2 2016 Software Construction File Input/Output 2 Agenda & Reading Agenda: Introduction Byte Streams FileInputStream & FileOutputStream BufferedInputStream & BufferedOutputStream Character
More informationExperiment No: Group B_4
Experiment No: Group B_4 R (2) N (5) Oral (3) Total (10) Dated Sign Problem Definition: Write a web application using Scala/ Python/ Java /HTML5 to check the plagiarism in the given text paragraph written/
More informationMathematics for Computer Graphics - Lecture 12
Mathematics for Computer Graphics - Lecture 12 Dr. Philippe B. Laval Kennesaw State University October 6, 2003 Abstract This document is about creating Java Applets as they relate to the project we are
More informationUsing APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI
Outline Chapter 3 Using APIs 3.1 Anatomy of an API 3.1.1 Overall Layout 3.1.2 Fields 3.1.3 Methods 3.2 A Development Walkthrough 3.2.1 3.2.2 The Mortgage Application 3.2.3 Output Formatting 3.2.4 Relational
More informationPIC 20A Streams and I/O
PIC 20A Streams and I/O Ernest Ryu UCLA Mathematics Last edited: December 7, 2017 Why streams? Often, you want to do I/O without paying attention to where you are reading from or writing to. You can read
More informationLesson 3: Accepting User Input and Using Different Methods for Output
Lesson 3: Accepting User Input and Using Different Methods for Output Introduction So far, you have had an overview of the basics in Java. This document will discuss how to put some power in your program
More informationJava Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing
Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to
More informationJava Classes: Math, Integer A C S L E C T U R E 8
Java Classes: Math, Integer A C S - 1903 L E C T U R E 8 Math class Math class is a utility class You cannot create an instance of Math All references to constants and methods will use the prefix Math.
More informationString is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents
String is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents character strings. All string literals in Java programs,
More informationCS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II)
CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II) Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs How to generate
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 30 April 4, 2018 I/O & Histogram Demo Chapters 28 HW7: Chat Server Announcements No penalty for late submission by tomorrow (which is a HARD deadline!)
More information1/16/2013. Program Structure. Language Basics. Selection/Iteration Statements. Useful Java Classes. Text/File Input and Output.
Program Structure Language Basics Selection/Iteration Statements Useful Java Classes Text/File Input and Output Java Exceptions Program Structure 1 Packages Provide a mechanism for grouping related classes
More informationCSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY
CSC 1051 Algorithms and Data Structures I Midterm Examination October 11, 2018 Name: KEY Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make
More informationGetting Started in Java. Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park
Getting Started in Java Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park Hello, World In HelloWorld.java public class HelloWorld { public static void main(string [] args) { System.out.println(
More informationLecture 22. Java Input/Output (I/O) Streams. Dr. Martin O Connor CA166
Lecture 22 Java Input/Output (I/O) Streams Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics I/O Streams Writing to a Stream Byte Streams Character Streams Line-Oriented I/O Buffered I/O
More informationReview Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:
More informationJava Console Input/Output The Basics. CGS 3416 Spring 2018
Java Console Input/Output The Basics CGS 3416 Spring 2018 Console Output System.out out is a PrintStream object, a static data member of class System. This represents standard output Use this object to
More informationFile IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20
File IO Computer Science and Engineering College of Engineering The Ohio State University Lecture 20 I/O Package Overview Package java.io Core concept: streams Ordered sequences of data that have a source
More informationCOMP-202 Unit 5: Basics of Using Objects
COMP-202 Unit 5: Basics of Using Objects CONTENTS: Concepts: Classes, Objects, and Methods Creating and Using Objects Introduction to Basic Java Classes (String, Random, Scanner, Math...) Introduction
More information1.00 Lecture 30. Sending information to a Java program
1.00 Lecture 30 Input/Output Introduction to Streams Reading for next time: Big Java 15.5-15.7 Sending information to a Java program So far: use a GUI limited to specific interaction with user sometimes
More informationCSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A
CSC 1051 Algorithms and Data Structures I Midterm Examination March 1, 2018 Name: KEY A Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make
More informationChapter 4. Mathematical Functions, Characters, and Strings
Chapter 4 Mathematical Functions, Characters, and Strings 1 Outline 1. Java Class Library 2. Class Math 3. Character Data Type 4. Class String 5. printf Statement 2 1. Java Class Library A class library
More informationObject-Oriented Programming Design. Topic : Streams and Files
Electrical and Computer Engineering Object-Oriented Topic : Streams and Files Maj Joel Young Joel Young@afit.edu. 18-Sep-03 Maj Joel Young Java Input/Output Java implements input/output in terms of streams
More information