CS Programming I: Using Objects
|
|
- Garey Hodges
- 6 years ago
- Views:
Transcription
1 CS Programming I: Using Objects Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: TopHat Sec 4 (PM) Join Code:
2 Binary
3 1/25 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary.
4 1/25 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary. Decimal Binary 198 =
5 1/25 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary. Decimal Binary 198 =
6 1/25 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary. Decimal Binary 198 = =
7 1/25 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary. Decimal Binary 198 = = =
8 2/25 TopHat Question 1 What is 17 in binary? a b c d
9 3/25 TopHat Question 2 What is in decimal? a. 18 b. 20 c. 22 d. 24
10 4/25 Numbers in Bases of Powers of 2 Decimal Base : or 21.
11 4/25 Numbers in Bases of Powers of 2 Decimal Base : or 21. Unary Base 2 0 = 1:
12 4/25 Numbers in Bases of Powers of 2 Decimal Base : or 21. Unary Base 2 0 = 1: Binary Base 2 1 = 2: or 0b10101 (or when the base is clear from the context).
13 4/25 Numbers in Bases of Powers of 2 Decimal Base : or 21. Unary Base 2 0 = 1: Binary Base 2 1 = 2: or 0b10101 (or when the base is clear from the context). Quarternary Base 2 2 = 4:
14 4/25 Numbers in Bases of Powers of 2 Decimal Base : or 21. Unary Base 2 0 = 1: Binary Base 2 1 = 2: or 0b10101 (or when the base is clear from the context). Quarternary Base 2 2 = 4: Octal Base 2 3 = 8: 25 8 or 025 or 0o25.
15 4/25 Numbers in Bases of Powers of 2 Decimal Base : or 21. Unary Base 2 0 = 1: Binary Base 2 1 = 2: or 0b10101 (or when the base is clear from the context). Quarternary Base 2 2 = 4: Octal Base 2 3 = 8: 25 8 or 025 or 0o25. Hexadecimal Base 2 4 = 16: or 0x15. Need 16 characters to represent the 16 digits: c d a 14 e b 15 f
16 5/25 TopHat Question 3 Convert to hexadecimal. Type your answer in TopHat.
17 Reference Types
18 6/25 References for Primitives Reference Integer Long Double Primitive int long double Primitive Wrappers Objects that contain a primitive value. Allows primitives to be used in many of Java s built-in data structures like ArrayList. Provides some addition methods for conversions.
19 6/25 References for Primitives Reference Integer Long Double Primitive int long double E.g. Integer intwrap = 5; Long longwrap = new Long(15); Primitive Wrappers Objects that contain a primitive value. Allows primitives to be used in many of Java s built-in data structures like ArrayList. Provides some addition methods for conversions.
20 6/25 References for Primitives Reference Integer Long Double Primitive int long double E.g. Integer intwrap = 5; Long longwrap = new Long(15); Primitive Wrappers Objects that contain a primitive value. Allows primitives to be used in many of Java s built-in data structures like ArrayList. Provides some addition methods for conversions. typevalue() method for retrieving primitive. E.g. intwrap.intvalue();
21 7/25 What are References? Less Simple Memory Model Stack Heap
22 7/25 What are References? Less Simple Memory Model int i = 5; Stack Heap 5 i
23 7/25 What are References? Less Simple Memory Model int i = 5; Integer j = 6; Stack Heap 6 j 5 i
24 7/25 What are References? Less Simple Memory Model int i = 5; Integer j = 6; Double d = 2. 5; Stack Heap 6 d j 5 i 2.5
25 7/25 What are References? Less Simple Memory Model Stack 6 Heap int i = 5; Integer j = 6; Double d = 2. 5; Integer s = 6; s d j 5 i 2.5
26 What are References? Less Simple Memory Model Stack 6 Heap int i = 5; Integer j = 6; Double d = 2. 5; Integer s = 6; Scanner sc = new Scanner ( System.in ); sc s d j 5 i Scanner Obj 2.5 7/25
27 7/25 What are References? Less Simple Memory Model Stack 6 Heap int i = 5; Integer j = 6; Double d = 2. 5; Integer s = 6; Scanner sc = new Scanner ( System.in ); sc s d j 5 i References Scanner Obj Refer to an object. Value: referral 2.5 information.
28 8/25 What are References? A Party Analogy Party: 939 Some St
29 8/25 What are References? A Party Analogy Party: 939 Some St 939 Some St.
30 8/25 What are References? A Party Analogy Party: 939 Some St Party: 939 Some St 939 Some St.
31 Strings
32 9/25 Characters Primitive char c; Literal: a Note: single quotes ( ) not double quotes ("). Wrapper Object: Character
33 9/25 Characters Primitive char c; Literal: a Note: single quotes ( ) not double quotes ("). Wrapper Object: Character Escape Characters \: Escape metacharacter. \n Newline \ Single quote \t Tab \r Carriage return \" Double quote \b Backspace \f Line feed \\ Backslash
34 10/25 Character Encodings ASCII A 7-bit character encoding in 1 byte. ( UNICODE An ASCII extension using more bits. UTF-8: 1 to 4 bytes; most popular UNICODE. More popular than ASCII as encoding on the web since Currently, about 90% of the web. a UTF-16: 2 or 4 bytes; used by java internally to encode strings. a https: //w3techs.com/technologies/overview/character_encoding/all
35 11/25 TopHat Question 4 What is the output? System.out.print( m + r );
36 12/25 Strings astr h e l l o w o r l d! Declaration: String astr = " hello world!"; String A reference type. Refers to a sequence of characters.
37 Strings astr h e l l o w o r l d! Declaration: String astr = " hello world!"; String A reference type. Refers to a sequence of characters. Index starts at 0. 12/25
38 13/25 String Operations astr: h e l l o w o r l d! astr.length() is 12 Useful String Methods length() Number of characters
39 13/25 String Operations astr: h e l l o w o r l d! astr.charat(4) is o Useful String Methods length() Number of characters charat(index) Character at given index
40 13/25 String Operations astr: h e l l o w o r l d! astr.substring(1,7) is "ello w" Useful String Methods length() Number of characters charat(index) Character at given index substring(startindex,endindex) Sub-string from startindex to endindex - 1
41 13/25 String Operations astr: h e l l o w o r l d! astr.indexof( l ) is 2 Useful String Methods length() Number of characters charat(index) Character at given index substring(startindex,endindex) Sub-string from startindex to endindex - 1 indexof(item, startindex) Returns the first index of item from startindex
42 13/25 String Operations astr: h e l l o w o r l d! astr.indexof( l, 5) is 9 Useful String Methods length() Number of characters charat(index) Character at given index substring(startindex,endindex) Sub-string from startindex to endindex - 1 indexof(item, startindex) Returns the first index of item from startindex
43 13/25 String Operations astr: h e l l o w o r l d! astr.indexof(? ) is -1 Useful String Methods length() Number of characters charat(index) Character at given index substring(startindex,endindex) Sub-string from startindex to endindex - 1 indexof(item, startindex) Returns the first index of item from startindex
44 13/25 String Operations astr: h e l l o w o r l d! astr.indexof("ll") is 2 Useful String Methods length() Number of characters charat(index) Character at given index substring(startindex,endindex) Sub-string from startindex to endindex - 1 indexof(item, startindex) Returns the first index of item from startindex
45 13/25 String Operations astr: h e l l o w o r l d! astr.lastindexof( l ) is 9 Useful String Methods length() Number of characters charat(index) Character at given index substring(startindex,endindex) Sub-string from startindex to endindex - 1 indexof(item, startindex) Returns the first index of item from startindex lastindexof(item, startindex) Reverse of indexof
46 14/25 Strings and Scanner h e l l o w o r l d! \n Tokenizing delimiter Sequence of characters (1 or more) that separate the regions of interest. token Regions of interest. whitespace space, tab (\t), newline (\n), carriage return (\r), form feed (\f).
47 14/25 Strings and Scanner h e l l o w o r l d! \n Default delimiter: Any amount of whitespace Tokenizing delimiter Sequence of characters (1 or more) that separate the regions of interest. token Regions of interest. whitespace space, tab (\t), newline (\n), carriage return (\r), form feed (\f).
48 14/25 Strings and Scanner sc h e l l o w o r l d! \n Default delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter.
49 14/25 Strings and Scanner sc h e l l o w o r l d! \n sc.nextline() Default delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter.
50 14/25 Strings and Scanner sc h e l l o w o r l d! \n sc.nextline() Default delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter.
51 14/25 Strings and Scanner sc h e l l o w o r l d! \n sc.nextline() Default delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter.
52 14/25 Strings and Scanner sc h e l l o w o r l d! \n sc.next() Default delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter.
53 14/25 Strings and Scanner sc h e l l o w o r l d! \n sc.next() Default delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter.
54 14/25 Strings and Scanner sc h e l l o w o r l d! \n sc.next() Default delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter.
55 14/25 Strings and Scanner sc h e l l o w o r l d! \n sc.next() Default delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter.
56 15/25 TopHat Question 5 What is the output? Scanner sc = new Scanner (" Hello World!\ nhi!"); System. out. print (" Output :"); sc. next (); sc. next (); System. out. print (sc. nextline ());
57 Strings and Scanner h e l l o w o r l d! \n Delimiter: A single "l" Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default. 16/25
58 Strings and Scanner h e l l o w o r l d! \n Delimiter: A single "l" (TopHat Q6: How many tokens?) Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default. 16/25
59 Strings and Scanner h e l l o w o r l d! \n Delimiter: A single "l" (TopHat Q6: How many tokens?) Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line; position scanner after the end of line. sc.next() Skip delimiter; read until delimiter. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default. 16/25
60 17/25 Instance vs Static Method Instance Method A method (non-static) that requires an instance of the class. instancename.methodname(...) Ex. String s = "Hello World!" s = s.substring(0,3);
61 17/25 Instance vs Static Method Instance Method A method (non-static) that requires an instance of the class. instancename.methodname(...) Ex. String s = "Hello World!" s = s.substring(0,3); Static Method A (static) method that does not require an instance of the class to run. ClassName.methodName(...) Ex. Math.pow(2,5);
62 Back to References
63 18/25 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack Heap
64 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack Heap Integer i = 6; 6 i 18/25
65 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack 6 Heap Integer i = 6; Integer j = i; j i 18/25
66 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack 6 Heap Integer i = 6; Integer j = i; j = 5; j i 5 18/25
67 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack Heap Integer i = 6; Integer j = i; 6 j = 5; Integer k = new Integer (5); 5 k j i 5 18/25
68 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack Heap String s = " foobar "; foobar s 18/25
69 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack Heap String s = " foobar "; String t = " foobar "; foobar t s 18/25
70 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack Heap String s = " foobar "; String t = " foobar "; s = s. substring (0,3); foobar foo t s 18/25
71 Immutable Objects String and the primitive wrappers are immutable. Definition An immutable object is an object that cannot be modified after its creation. Stack Heap String s = " foobar "; String t = " foobar "; s = s. substring (0,3); foobar String u = new String (" foobar "); foo foobar u t s 18/25
72 Random Numbers
73 19/25 TopHat Question 7 Pick the random binary string:
74 20/25 What is randomness?
75 20/25 What is randomness? Anecdotally, humans are biased towards sequences without discernible patterns.
76 20/25 What is randomness? Anecdotally, humans are biased towards sequences without discernible patterns. Kolmogorov Complexity How succinctly can the sequence be described?
77 20/25 What is randomness? Anecdotally, humans are biased towards sequences without discernible patterns. Kolmogorov Complexity How succinctly can the sequence be described? : 48 1 s (Low)
78 20/25 What is randomness? Anecdotally, humans are biased towards sequences without discernible patterns. Kolmogorov Complexity How succinctly can the sequence be described? : 48 1 s (Low) : no clue (High)
79 20/25 What is randomness? Anecdotally, humans are biased towards sequences without discernible patterns. Kolmogorov Complexity How succinctly can the sequence be described? : 48 1 s (Low) : no clue (High) : π in binary to 46 floating-point digits (Low)
80 21/25 Sources of Randomness Lack of Knowledge We don t know the forces being applied.
81 21/25 Sources of Randomness Lack of Knowledge We don t know the forces being applied. Certified Random Bits It is possible to get truly random bits via the quantum world: Random numbers certified by Bell s theorem S. Pironio, A. Acín, S. Massar, A. Boyer de la Giroday, D. N. Matsukevich, P. Maunz, S. Olmschenk, D. Hayes, L. Luo, T. A. Manning & C. Monroe Nature 464, (15 April 2010)
82 21/25 Sources of Randomness in Java Pseudorandom Number Generator A pseudorandom number generator is able to produce a sequence of seemingly random numbers.
83 21/25 Sources of Randomness in Java Pseudorandom Number Generator A pseudorandom number generator is able to produce a sequence of seemingly random numbers. The first random value r 1 is calculated from a seed.
84 21/25 Sources of Randomness in Java Pseudorandom Number Generator A pseudorandom number generator is able to produce a sequence of seemingly random numbers. The first random value r 1 is calculated from a seed. Typically, the seed will be based on the current time.
85 21/25 Sources of Randomness in Java Pseudorandom Number Generator A pseudorandom number generator is able to produce a sequence of seemingly random numbers. The first random value r 1 is calculated from a seed. Typically, the seed will be based on the current time. All subsequent random numbers are calculated from the previous value. (I.e. r n = f (r n 1 ))
86 21/25 Sources of Randomness in Java Pseudorandom Number Generator A pseudorandom number generator is able to produce a sequence of seemingly random numbers. The first random value r 1 is calculated from a seed. Typically, the seed will be based on the current time. All subsequent random numbers are calculated from the previous value. (I.e. r n = f (r n 1 )) Pseudorandom because the seed fully determines the sequence of numbers.
87 22/25 Random Class Standard Java class: import java.util.random; Important Instance Methods Constructor: Random rand = new Random(); "Random" seed.
88 22/25 Random Class Standard Java class: import java.util.random; Important Instance Methods Constructor: Random rand = new Random(); "Random" seed. Constructor: Random rand = new Random(seed); Fixed seed.
89 22/25 Random Class Standard Java class: import java.util.random; Important Instance Methods Constructor: Random rand = new Random(); "Random" seed. Constructor: Random rand = new Random(seed); Fixed seed. setseed(seed) Resets the instance to a fixed seed.
90 22/25 Random Class Standard Java class: import java.util.random; Important Instance Methods Constructor: Random rand = new Random(); "Random" seed. Constructor: Random rand = new Random(seed); Fixed seed. setseed(seed) Resets the instance to a fixed seed. nextint(bound) Returns a pseudorandom number between 0 and bound - 1.
91 23/25 Using Random Random rand = new Random (); int randint = rand. nextint (10) + 1;
92 23/25 Using Random Random rand = new Random (); int randint = rand. nextint (10) + 1; Between 0 and 9
93 23/25 Using Random Random rand = new Random (); Shifts by 1 int randint = rand. nextint (10) + 1; Between 0 and 9
94 24/25 TopHat Question 8 Complete the following code snippet so that randint gets a pseudorandom number between 3 and 18 inclusive: Random rand = new Random(); int randint =
95 25/25 Further Reading COMP SCI 200: Programming I zybooks.com, zybook code: WISCCOMPSCI200Spring2018 Chapter 3. Using Objects
96 Appendix References Appendix
97 Appendix References References
98 Appendix References 26/25 Image Sources I http: //help.blackberry.com/en/category/devices/ clincapture/randomization.jpg
99 Appendix References 27/25 Image Sources II https: //
CS Programming I: Using Objects
CS 200 - Programming I: Using Objects Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Binary
More informationCS Programming I: Branches
CS 200 - Programming I: Branches Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2018 TopHat Sec 3 (AM) Join Code: 925964 TopHat Sec 4 (PM) Join Code: 259495 Boolean Statements
More informationCS Programming I: Primitives and Expressions
CS 200 - Programming I: Primitives and Expressions Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code:
More informationCS Programming I: Branches
CS 200 - Programming I: Branches Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Boolean Statements
More informationCS Programming I: ArrayList
CS 200 - Programming I: ArrayList Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455 ArrayLists
More informationCS Programming I: Programming Process
CS 200 - Programming I: Programming Process Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455
More informationCS Programming I: Programming Process
CS 200 - Programming I: Programming Process Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2019 TopHat Sec 3 (AM) Join Code: 560900 TopHat Sec 4 (PM) Join Code: 751425
More informationJava Basic Datatypees
Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,
More informationWelcome to the Using Objects lab!
Welcome to the Using Objects lab! Learning Outcomes By the end of this lab: 1. Be able to define chapter 3 terms. 2. Describe reference variables and compare with primitive data type variables. 3. Draw
More informationCS Programming I: File Input / Output
CS 200 - Programming I: File Input / Output Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624
More informationCS Programming I: File Input / Output
CS 200 - Programming I: File Input / Output Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455
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 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 informationCS Programming I: Arrays
CS 200 - Programming I: Arrays Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Array Basics
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 informationWelcome to the Using Objects lab!
Welcome to the Using Objects lab! Learning Outcomes By the end of this lab: 1. Be able to define chapter 3 terms. 2. Describe reference variables and compare with primitive data type variables. 3. Draw
More informationData and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:
Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions
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 informationCS Programming I: Inheritance
CS 200 - Programming I: Inheritance Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Inheritance
More informationCS Programming I: Exceptions
CS 200 - Programming I: Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455 Command-Line Arguments
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 informationVariables, Constants, and Data Types
Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types
More informationComputational Expression
Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name
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 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 informationObject oriented programming. Instructor: Masoud Asghari Web page: Ch: 3
Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning
More informationLecture Set 2: Starting Java
Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural
More informationCS 302: Introduction to Programming
CS 302: Introduction to Programming Lectures 2-3 CS302 Summer 2012 1 Review What is a computer? What is a computer program? Why do we have high-level programming languages? How does a high-level program
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 informationPrinceton University. Computer Science 217: Introduction to Programming Systems. Data Types in C
Princeton University Computer Science 217: Introduction to Programming Systems Data Types in C 1 Goals of C Designers wanted C to: Support system programming Be low-level Be easy for people to handle But
More informationCS Programming I: Programming Process
CS 200 - Programming I: Programming Process Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624
More informationChapter 6 Primitive types
Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question
More informationECE 122 Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions
More informationboolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while
CSCI 150 Fall 2007 Java Syntax The following notes are meant to be a quick cheat sheet for Java. It is not meant to be a means on its own to learn Java or this course. For that you should look at your
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 informationCS Programming I: Exceptions
CS 200 - Programming I: Exceptions Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Command-Line
More informationLecture Set 2: Starting Java
Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural
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 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 informationStrings, characters and character literals
Strings, characters and character literals Internally, computers only manipulate bits of data; every item of data input can be represented as a number encoded in base 2. However, when it comes to processing
More informationc) And last but not least, there are javadoc comments. See Weiss.
CSCI 151 Spring 2010 Java Bootcamp The following notes are meant to be a quick refresher on Java. It is not meant to be a means on its own to learn Java. For that you would need a lot more detail (for
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationChapter. Let's explore some other fundamental programming concepts
Data and Expressions 2 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Data and Expressions Let's explore some
More information4 Programming Fundamentals. Introduction to Programming 1 1
4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,
More informationFull file at
Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
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 informationH212 Introduction to Software Systems Honors
Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing
More informationPeer Instruction 1. Elementary Programming
Peer Instruction 1 Elementary Programming 0 Which of the following variable declarations will not compile? Please select the single correct answer. A. int i = 778899; B. double x = 5.43212345; C. char
More informationLecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value
Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to
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 informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics
Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional
More informationJava Notes. 10th ICSE. Saravanan Ganesh
Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses
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 informationProgramming with Java
Programming with Java String & Making Decision Lecture 05 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives By the end of this lecture you should be able to : Understand another
More informationPrinceton University Computer Science 217: Introduction to Programming Systems The C Programming Language Part 1
Princeton University Computer Science 217: Introduction to Programming Systems The C Programming Language Part 1 C is quirky, flawed, and an enormous success. While accidents of history surely helped,
More informationJAVA Programming Fundamentals
Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol
More informationTCL - STRINGS. Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.
http://www.tutorialspoint.com/tcl-tk/tcl_strings.htm TCL - STRINGS Copyright tutorialspoint.com The primitive data-type of Tcl is string and often we can find quotes on Tcl as string only language. These
More informationLanguage Fundamentals Summary
Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de
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 informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review
More informationReview. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale
Review Single Pixel Filters Thresholding Posterize Histogram Equalization Negative Sepia Grayscale Spatial Filters Smooth Blur Low Pass Filter Sharpen High Pass Filter Erosion Dilation Image Processing
More informationProgramming in C++ 4. The lexical basis of C++
Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++
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 information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:
More informationCS 200 Using Objects. Jim Williams, PhD
CS 200 Using Objects Jim Williams, PhD This Week Notes By Friday Exam Conflict and Accommodations Install Eclipse (version 8) Help Queue Team Lab 2 Chap 2 Programs (P2): Due Thursday Hours Spent Week?
More informationB.V. Patel Institute of BMC & IT, UTU 2014
BCA 3 rd Semester 030010301 - Java Programming Unit-1(Java Platform and Programming Elements) Q-1 Answer the following question in short. [1 Mark each] 1. Who is known as creator of JAVA? 2. Why do we
More information2/12/17. Goals of this Lecture. Historical context Princeton University Computer Science 217: Introduction to Programming Systems
Princeton University Computer Science 217: Introduction to Programming Systems The C Programming Language Part 1 For Your Amusement C is quirky, flawed, and an enormous success. While accidents of history
More informationLearning objectives: Objects and Primitive Data. Introduction to Objects. A Predefined Object. The print versus the println Methods
CSI1102 Introduction to Software Design Chapter 2: Objects and Primitive Data Learning objectives: Objects and Primitive Data Introducing objects and their properties Predefined objects: System.out Variables
More informationMobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02
Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.
More informationCOMP519 Web Programming Lecture 17: Python (Part 1) Handouts
COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents
More informationJava s String Class. in simplest form, just quoted text. used as parameters to. "This is a string" "So is this" "hi"
1 Java s String Class in simplest form, just quoted text "This is a string" "So is this" "hi" used as parameters to Text constructor System.out.println 2 The Empty String smallest possible string made
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationReading Input from Text File
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 5 Reading Input from Text File Eng. Mohammed Alokshiya November 2, 2014 The simplest
More informationGabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming
1 Literal Constants Definition A literal or a literal constant is a value, such as a number, character or string, which may be assigned to a variable or a constant. It may also be used directly as a function
More informationChapter 2: Using Data
Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that
More informationMATHEMATICAL FUNCTIONS CHARACTERS, AND STRINGS. INTRODUCTION IB DP Computer science Standard Level ICS3U
C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G MATHEMATICAL FUNCTIONS CHARACTERS, AND STRINGS P1 LESSON 4 P1 LESSON 4.1 INTRODUCTION P1 LESSON 4.2 COMMON MATH FUNCTIONS Java
More informationProgram Elements -- Introduction
Program Elements -- Introduction We can now examine the core elements of programming Chapter 3 focuses on: data types variable declaration and use operators and expressions decisions and loops input and
More informationCHAPTER 2 Java Fundamentals
CHAPTER 2 Java Fundamentals Copyright 2016 Pearson Education, Inc., Hoboken NJ Chapter Topics Chapter 2 discusses the following main topics: The Parts of a Java Program The print and println Methods, and
More informationChapter 4 Classes in the Java Class Libraries
Programming Fundamental I ACS-1903 Chapter 4 Classes in the Java Class Libraries 1 Random Random The Random class provides a capability to generate pseudorandom values pseudorandom because the stream of
More informationChapter 2 Elementary Programming
Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical
More informationExam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming
Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose
More informationLexical Structure (Chapter 3, JLS)
Lecture Notes CS 140 Winter 2006 Craig A. Rich Lexical Structure (Chapter 3, JLS) - A Java source code file is viewed as a string of unicode characters, including line separators. - A Java source code
More informationAP Computer Science Unit 1. Programs
AP Computer Science Unit 1. Programs Open DrJava. Under the File menu click on New Java Class and the window to the right should appear. Fill in the information as shown and click OK. This code is generated
More informationAP Computer Science A
AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive
More informationComputational Expression
Computational Expression Scanner, Increment/Decrement, Conversion Janyl Jumadinova 17 September, 2018 Janyl Jumadinova Computational Expression 17 September, 2018 1 / 11 Review: Scanner The Scanner class
More information2: Basics of Java Programming
2: Basics of Java Programming 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 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 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 informationCSC 1107: Structured Programming
CSC 1107: Structured Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: alt. office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1107
More informationVLC : Language Reference Manual
VLC : Language Reference Manual Table Of Contents 1. Introduction 2. Types and Declarations 2a. Primitives 2b. Non-primitives - Strings - Arrays 3. Lexical conventions 3a. Whitespace 3b. Comments 3c. Identifiers
More informationMidterm Exam 2 Thursday, November 15th, points (15% of final grade) Instructors: Jim Williams and Marc Renault
Computer Sciences 200 Midterm Exam 2 Thursday, November 15th, 2018 100 points (15% of final grade) Instructors: Jim Williams and Marc Renault (Family) Last Name: (Given) First Name: CS Login Name: NetID
More informationCHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS
These are sample pages from Kari Laitinen s book "A Natural Introduction to Computer Programming with Java". For more information, please visit http://www.naturalprogramming.com/javabook.html CHAPTER 5
More informationObjectives of CS 230. Java portability. Why ADTs? 8/18/14
http://cs.wellesley.edu/~cs230 Objectives of CS 230 Teach main ideas of programming Data abstraction Modularity Performance analysis Basic abstract data types (ADTs) Make you a more competent programmer
More informationLecture 3. More About C
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants
More information1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8
Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(
More informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More informationEng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 4 Characters
More informationCS Programming I: Classes
CS 200 - Programming I: Classes Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Classes 1/23
More information8/25/17. Demo: Create application. CS2110, Recita.on 1. Arguments to method main, Packages, Wrapper Classes, Characters, Strings.
CS2110, Recita.on 1 Arguments to method main, Packages, Wrapper Classes, Characters, Strings Demo: Create application To create a new project that has a method called main with a body that contains the
More information