CS Programming I: Using Objects
|
|
- Matilda Ross
- 6 years ago
- Views:
Transcription
1 CS Programming I: Using Objects Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: TopHat Sec 4 (AM) Join Code:
2 Binary
3 1/21 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary.
4 1/21 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary. Decimal Binary 198 =
5 1/21 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary. Decimal Binary 198 =
6 1/21 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary. Decimal Binary 198 = =
7 1/21 Binary Bits Binary digits: 0 or 1; base 2 numbers. Information in computers is encoded in binary. Decimal Binary 198 = = =
8 2/21 TopHat Question 1 What is 17 in binary? a b c d
9 3/21 TopHat Question 2 What is in decimal? a. 18 b. 20 c. 22 d. 24
10 4/21 Numbers in Bases of Powers of 2 Decimal Base : or 21.
11 4/21 Numbers in Bases of Powers of 2 Decimal Base : or 21. Unary Base 2 0 = 1:
12 4/21 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/21 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/21 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/21 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/21 TopHat Question 3 Convert to hexadecimal. Type your answer in TopHat.
17 Reference Types
18 6/21 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/21 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/21 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/21 What are References? Less Simple Memory Model Stack Heap
22 7/21 What are References? Less Simple Memory Model int i = 5; Stack Heap 5 i
23 7/21 What are References? Less Simple Memory Model int i = 5; Integer j = 6; Stack Heap 6 j 5 i
24 7/21 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/21 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/21
27 7/21 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 Strings
29 8/21 Characters Primitive char c; Literal: a Note: single quotes ( ) not double quotes ("). Wrapper Object: Character
30 8/21 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
31 9/21 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
32 10/21 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.
33 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. 10/21
34 11/21 String Operations astr: h e l l o w o r l d! astr.length() is 12 Useful String Methods length() Number of characters
35 11/21 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
36 11/21 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
37 11/21 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
38 11/21 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
39 11/21 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
40 11/21 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
41 11/21 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
42 12/21 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).
43 12/21 Strings and Scanner h e l l o w o r l d! \n 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).
44 12/21 Strings and Scanner sc h e l l o w o r l d! \n Delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line. sc.next() Default delimiter: Any amount of whitespace. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default.
45 12/21 Strings and Scanner sc h e l l o w o r l d! \n sc.nextline() Delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line. sc.next() Default delimiter: Any amount of whitespace. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default.
46 12/21 Strings and Scanner sc h e l l o w o r l d! \n sc.next() Delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line. sc.next() Default delimiter: Any amount of whitespace. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default.
47 12/21 Strings and Scanner sc h e l l o w o r l d! \n Delimiter: Any amount of whitespace Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line. sc.next() Default delimiter: Any amount of whitespace. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default.
48 12/21 Strings and Scanner sc h e l l o w o r l d! \n Delimiter: Any amount of whitespace sc.next() Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line. sc.next() Default delimiter: Any amount of whitespace. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default.
49 12/21 Strings and Scanner h e l l o w o r l d! \n Delimiter: A single "l" (TopHat Q4: How many tokens?) Some more Scanner Instance Methods Scanner sc = new Scanner(...); sc.nextline() Read until end of line. sc.next() Default delimiter: Any amount of whitespace. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default.
50 12/21 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. sc.next() Default delimiter: Any amount of whitespace. sc.usedelimiter(delim) Sets the delimiter to delim string. sc.reset() Reset the delimiter to the default.
51 13/21 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);
52 13/21 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);
53 Back to References
54 14/21 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
55 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 14/21
56 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 = 6; j i 14/21
57 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 = 6; j = 5; j i 5 14/21
58 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 = 6; 6 j = 5; Integer k = new Integer (5); 5 k j i 5 14/21
59 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 14/21
60 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 "; s = s. substring (0,3); foobar foo s 14/21
61 Random Numbers
62 15/21 TopHat Question 5 Pick the random binary string:
63 16/21 What is randomness?
64 16/21 What is randomness? Anecdotally, humans are biased towards sequences without discernible patterns.
65 16/21 What is randomness? Anecdotally, humans are biased towards sequences without discernible patterns. Kolmogorov Complexity How succinctly can the sequence be described?
66 16/21 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)
67 17/21 Sources of Randomness Lack of Knowledge We don t know the forces being applied.
68 17/21 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)
69 17/21 Sources of Randomness in Java Pseudorandom Number Generator A pseudorandom number generator is able to produce a sequence of seemingly random numbers.
70 17/21 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.
71 17/21 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.
72 17/21 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 ))
73 17/21 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.
74 18/21 Random Class Standard Java class: import java.util.random; Important Instance Methods Constructor: Random rand = new Random(); "Random" seed.
75 18/21 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.
76 18/21 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.
77 18/21 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.
78 19/21 Using Random Random rand = new Random (); int randint = rand. nextint (10) + 1;
79 19/21 Using Random Random rand = new Random (); int randint = rand. nextint (10) + 1; Between 0 and 9
80 19/21 Using Random Random rand = new Random (); Shifts by 1 int randint = rand. nextint (10) + 1; Between 0 and 9
81 20/21 TopHat Question 6 Complete the following code snippet so that randint gets a pseudorandom number between 3 and 18 inclusive: Random rand = new Random(); int randint =
82 21/21 Further Reading COMP SCI 200: Programming I zybooks.com, zybook code: WISCCOMPSCI200Fall2017 Chapter 3. Using Objects
83 Appendix References Appendix
84 Appendix References References
85 Appendix References 22/21 Image Sources I clincapture/randomization.jpg
CS Programming I: Using Objects
CS 200 - Programming I: Using Objects 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 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: 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: 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: 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: 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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. 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 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 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 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 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 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 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 informationOverview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program
Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of
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 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 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 informationContents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix
PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring
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 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 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 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 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 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 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 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 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 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 informationPrinceton University COS 217: Introduction to Programming Systems C Primitive Data Types
Princeton University COS 217: Introduction to Programming Systems C Primitive Data Types Type: int Size: System dependent. On FC010 with gcc217: 4 bytes. int ifirst; signed int isecond; 123 00000000 00000000
More informationTools : The Java Compiler. The Java Interpreter. The Java Debugger
Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,
More informationSprite an animation manipulation language Language Reference Manual
Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3
More informationOverview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O
Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.
More informationData Types Literals, Variables & Constants
C/C++ PROGRAMMING Data Types Literals, Variables & Constants Copyright 2013 Dan McElroy Under the Hood As a DRIVER of an automobile, you may not need to know everything that happens under the hood, although
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 informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationComputational Expression
Computational Expression, Math Class, Wrapper Classes Janyl Jumadinova 18 February, 2019 Janyl Jumadinova Computational Expression 18 February, 2019 1 / 8 The Random class is part of the java.util package
More informationIntroductory Mobile Application Development
Notes Quick Links Introductory Mobile Application Development 152-160 Java Syntax Part 2 - Activity String Class Add section on Parse ArrayList Class methods. Book page 95. Toast Page 129 240 242 String
More informationAn overview of Java, Data types and variables
An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public
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 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 informationVARIABLES AND TYPES CITS1001
VARIABLES AND TYPES CITS1001 Scope of this lecture Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Primitive types Every piece of data
More information