Instructor s Notes Java - Beginning Built-In Classes. Java - Beginning Built-In Classes

Size: px
Start display at page:

Download "Instructor s Notes Java - Beginning Built-In Classes. Java - Beginning Built-In Classes"

Transcription

1 Java - Beginning Built-In Classes Notes Quick Links Vector Class Pages Wrapper Classes Pages String Class Pages Calendar Class Pages DecimalFormat Class Pages 269 Activity Vector Class The main drawback of arrays is they must be fixed size Vectors overcome this drawback vectors are resizable at runtime. Requires import of java.util.vector Vectors are pointers to instances of other classes Defining a vector: Vector vecstring = new Vector( ); Note Vector class name is capitalized ( ) used to define the capacity not [ ] Capacity of vector is a parameter If no capacity is specified (like the example above) the initial capacity is 10 Vectors have both a capacity and a size Capacity is number of elements the vector could hold before automatically expanding Size is the actual number of elements in the vector Can designate the capacity of the vector when instantiating it. Vector vecstring = new Vector(5); Capacity is 5, size is 0 Page 1 of 16

2 Notes Adding elements to a vector. vecstring.add( Volker ); or vecstring.add(new String( Java )); //Preferred or String coursename = Java ; vecstring.add(coursename); You can also add primitive types to a vector (see Wrapper Classes below) Note that vectors are NOT typed so you can add objects of different types to the same vector. This can be confusing unless you can determine the type (class) of each element. Normally, the elements are all of the same class If adding an element would exceed the current capacity of the vector, the size of the vector is doubled automatically. Retrieving an element of a vector vecstring.get(idx); The get method returns the element at index idx The return value can be assigned to an appropriate variable or used in an equation (or output statement) Determining the location of an element idx = vecstring.indexof(findme); Returns the index of the element that matches findme findme can be of any type though usually it is the same type as the elements in the vector If the item is not found, the method returns -1 contains method works in a similar way, returning either true or false if the vector contains the requested element Activity Page 2 of 16

3 Notes Activity Removing elements from a vector vecstring.remove(idx); vecstring.remove(findme); Can provide either the index of the item to be deleted or the item itself Capacity of the vector never changes. Wrapper Classes Some object methods (like vectors) require that objects be sent as parameters. This precludes sending the primitive types (int, double, etc.) to these methods Wrapper classes wrap themselves around the primitive types, allowing them to be used where objects are required. Each primitive type has a corresponding wrapper class Wrapper classes have the same names as the primitive except the first letter is capitalized Exception: int wrapper class is Integer Example: myvector.add(new Integer(15)); Integer objage = new Integer(15); It is possible to add a primitive type to a vector. myvector.add(15); I believe this statement actually wraps the integer in an Integer (wrapper) class (behind the scenes) before adding the value to the vector. Page 3 of 16

4 Notes Extracting a numeric vector element to a primitive data type. The Vector requires its elements be classes, but classes are harder to do math with. Use these techniques to convert a Wrapper to a primitive. Double salary = new Double(25.25); double sal; //Primitive version sal = salary; //Works fine sal = salary.doublevalue(); //Also works //Vector element sal = (Double) myvector.get(1); In the last example, the vector element cannot be converted to a double (primitive); however, it can be converted to a Double (wrapper) which then can be assigned to a double primitive. Personally, until I learn otherwise, I won t be using the Wrapper classes except to do the conversions required to extract a numeric value from a Vector as in the last example above. Primitive literals cannot be assigned to wrapper types Activity Double average; average = total / cnt; //Wrapper class //Error Because of this, I recommend you convert all Wrapper class data back to its primitive type before using it in calculations. Page 4 of 16

5 String Class Author suggests this is the best way to instantiate a String String mystring = Volker ; //OK String mystring = new String( Volker ); //Better Method types Instance methods (aka nonstatic methods) must be applied to an instance of a class Class methods (aka static methods) are applied by referencing the class name, not an instance name. String methods (s defined as String) s.tostring(someobject); Where possible, converts other types to String See example below s.charat(i) vecstring.get(1).tostring().charat(2); s.codepointat(i) Returns the ASCII (Unicode) value of the character in position i s.codepointbefore(i) Returns the ASCII (Unicode) value of the character in position i-1 S.codePointCount(startindex, endindex) Returns the number of ASCII (Unicode) characters between startindex and endindex, not counting endindex. s.compareto(anotherstring) Returns a negative number if string s is alphabetically (Unicode sequence) before anotherstring Returns a positive number if string s is alphabetically after anotherstring Returns zero if the strings are identical s.comparetoignorecase(anotherstring) Same as CompareTo, but case insensitive Page 5 of 16

6 s.concat(anotherstring) Never use it Same as s = s + anotherstring; s.contains(anotherstring) Returns true if anotherstring exists anywhere in string s. Returns false otherwise. Note, no case insensitive version s.contentequals(anotherstring) Same as equals method (see below) and = = No Ignore Case alternative available s.endswith(anotherstring) Returns true if the last characters in string s are the same as anotherstring Returns false otherwise s.equals(anotherstring) Returns true if two strings have exactly the same characters Same as s == anotherstring s.equalsignorecase(anotherstring) Same as equals, except character by character comparison is case insensitive s.getbytes( ) Returns an array of bytes. Each element of the array contains the ASCII (Unicode) value of the corresponding character in the string. s.indexof(anotherstring, startindex) Returns the index where anotherstring is located in string s, starting at position startindex If startindex is omitted, the search begins at the beginning of string s anotherstring could also be of type char If anotherstring is not found, the function returns -1 s.isempty( ) Returns true if the string contains no characters (length is 0) Same as s == Page 6 of 16

7 s.lastindexof(anotherstring, startindex) Returns the index of anotherstring within string s, searching backwards from the end of the string If startindex is not specified, the search begins from the end of the string. anothersting can also be of type char If anotherstring is not found, the function returns -1 s.length( ) Returns number of characters in a string s.startswith(anotherstring, startindex) Returns true is string s, (starting in character position startindex) starts with the letters in anotherstring startindex can be omitted. If it is, start index 0 is used s.matches(regularexpressionstring) Returns true if the string s matches the regular expression pattern provided. Still working on this one s.regionmatches(true/false, starts, anotherstring, starta, length) Returns true if the designated parts of two strings match True/false designates whether the comparison should ignore case (true to ignore case). If this parameter is omitted, the default is false. starts designates where in string s to start comparing starta designates where in anotherstring to start comparing length designates how many characters to compare s.replace(ministring, newstring) Replaces all occurrences of ministring with newstring in the string s Returns a new String with the changes ministring and newstring can also be of type char s.replaceall(regex, newstring) Replaces all occurrences of strings that match the regular expression provided with newstring. Not functioning yet Page 7 of 16

8 s.replacefirst(regex, newstring) Replaces the first occurrence of a string that matches the regular expression provided with newstring. Works OK if just use strings, but regular expressions not working yet. s.split(regex) Creates a array of strings that contain all the pieces of the original string split at a designated character string (regex). Example: String words[]; //Array of word strings words = s.split( ); //Split at spaces A second, optional integer parameter allows you to limit the number of times the string is split String firstthree[]; //1 st 3 words words = s.split(,3) ; The last split will always contain the remainder of the string. s.substring(start, end) Extract part of the string starting at start, ending at end Second parameter is not required. If it s not included, the substring includes all characters to the end of the string. Note: the end character is not included in the substring (see example) Note: unlike other languages, the second parameter is not the length of the desired substring. Example: myname = Volker F. Gaul ; mi = myname.substring(7,9); //Returns F. s.tochararray Similar to tobytearray. Might be more valuable because characters are more readily accessible. Coverts a string to an array of characters Example: char characters[]; //array of characters characters = s.tochararray(); Page 8 of 16

9 s.touppercase( ) s.tolowercase Converts a string to upper or lower case and returns another string Example: state = state.touppercase( ); s.trim( ) Removes all leading and trailing whitespace from a string White space includes spaces, carriage returns, tabs, backspaces Static String Methods Static methods are NOT associated with an instance of a String Instead, they are implemented by referencing the String class directly Example: String.methodName String.CopyValueOf(charArray) Converts an array of characters back into a String Reverse of tochararray Example: newstring = String.CopyValueOf(charArray); Second (overloaded) version allows you designate which character to start with and how many characters you want. newstring = String.CopyValueOf(charArray,10,15); //Starts at char 10, extracts 15 characters Page 9 of 16

10 String.format Allows you to control the display of just about any type Allows you to control the field width used to display a value Reference: a/util/formatter.html#syntax The format method s first parameter is the formatting string. Designates how the values should be formatted Each value gets its own format specifier (see below) After the formatting string you list the values (any types, any combination) Example: s = String.format(formatString, value1, value2, value3); Creating formatting specifiers Starts with % Next is the (parameter) number of the value you want to format (starts at 1, not 0) The parameter number must always be followed by a $ Next (optional) come flags that allow you to designate text alignment, whether signs are included, zero padding, etc (see reference) The flags are followed (optional) by a width specifier. This designates the minimum number of characters the field will take up. If the data contains decimal places, you can specified the number of decimal places to display by following the width with a period and the number of decimal places Finally, the width is followed by the conversion code. This code tells the format method what type of data to expect. See codes on the reference page. Any other text in the format string is displayed as entered Page 10 of 16

11 String.format Examples s = String.format( My name is %1$10s, Volker ); Volker is the text to be formatted My name is appears exactly as it is typed %1$ designates this as a format specifier for the first parameter (only parameter, Volker ) 10 designates the parameter should always take up a minimum of 10 characters s designates the parameter should be a string Result: My name is Volker (4 extra spaces before Volker) Adding a - (no quotes)(left-justify flag) before the 10 would have aligned Volker to the left in the field and the 4 extra spaces (to fill 10 characters) would have appeared after Volker s = String.format( Salary is $%1$8.2f Hours: $%2$4.1f, , 55.25); is the first parameter, is the second parameter Salary is $ appears exactly as it is typed %1$ designates this as a format specifier for the 1 st parameter ( ) 8 is the total width of the field (includes the decimal point and decimal places) 2 is the number of decimal places to display (will round as necessary) f designates the first parameter be treated as a floating point number Hours: appears exactly as it is typed %2$ designates this as a format specifier for the 2 nd parameter (55.25) 4 is the total width of the field 1 is the number of decimal places to display f designates the second parameter be treated as a floating point number There doesn t seem to be a way to include $, % or commas in values using the format method. See DecimalFormat below. String.valueOf(x) Converts a primitive to a string Static (class) method. Note the class name is used, not an instance name. Example: int age = 25; strage = String.valueOf(age); Page 11 of 16

12 Convert String to Primitive mydouble = Double.parseDouble(theString); Replace double with any primitive type Convert Wrapper to String astring = wrapvariable.tostring( ); Convert String to Wrapper wrapvariable = Double.valueOf(aString); Calendar Class Many of today s program manipulate date. Java comes with three Date classes that makes processing dates easier. Date class mostly replaced by Calendar class Calendar class has the ability to store dates and times DateFormat allows you to format dates for output Date and Calendar require java.util import Instantiating the Calendar class Calendar cal = Calendar.getInstance( ); new not available Assigning a value to a Calendar object cal.gettime( ); If instance has not been assigned a value, gettime sets its value to the current date and time. cal.set(year, Calendar.AUGUST, 16); Sets the date to 8/16/year (depending on the value in the variable year) Can also set individual calendar components cal.set(calendar.month, 4); Page 12 of 16

13 Retrieving Calendar components value = cal.get(calendar.component); Returns part of the date based on which component is requested. Components are Calendar class enumerations predefined values Common components: MONTH DATE YEAR DAY_OF_WEEK (1=Sunday) HOUR (12 hour day) HOUR_OF_DAY (24 hour day) MINUTE SECOND MILLISECOND AM_PM strvalue = cal.getdisplayname (component, style, Locale.US); Component must be one of the items listed above that has a named version (MONTH, DAY_OF_WEEK, AM_PM) Style is another Calendar enumeration that includes LONG and SHORT Doing calendar calculations cal.add(calendar.month, 1); First parameter designates the units to be added Second parameter designates how many Use a negative number to subtract values Comparing calendar values if (cal.before(anotherdate) ) if (cal.after(anotherdate) ) Calendar values are not equal unless all components are the same including hours, minutes, seconds and milliseconds Use set to set all time components to zero if need to compare just dates. Page 13 of 16

14 Displaying Calendar values DateFormat class (java.text) allows you format dates for output Unformatted date System.out.println(cal.getTime()); Sun Sep 16 17:52:04 CDT 2007 First need to create an instance of the DateFormat class that defines what format you want. DateFormat longdate = DateFormat.getDateInstance(DateFormat.LONG); longdate is an instance of DateFormat LONG, MEDIUM, SHORT are available Need a separate instance variable for every format used. Then, use the instance to format an output System.out.println( Date is + longdate.format(cal.gettime() ); longdate is the instance created above format method used to format a date sent to it as a parameter Page 14 of 16

15 Custom Date Formats Use SimpleDateFormat class SimpleDateFormat fmt = new SimpleDateFormat(formatstring); formatstring can contain any combination of the following characters: yy, yyyy (07, 2007) M, MM, MMM, MMMM (9, 09, Sep, September) d, dd (7, 07) EEE, EEEE (Mon, Monday) Time formatting characters are also available To insert non-format string characters in the formatting string, surround them with apostrophes. Reference Usage is just like DateFormat System.out.println( Date is + fmt.format(cal.gettime()) ); DecimalFormat Class Similar to DateFormat and SimpleDateFormat but used to format numbers Other formatting classes are available, but this one covers most needs Create an instance and designate the format DecimalFormat fmtcurrency = new DecimalFormat(formatstring); Formatstring can contain combinations of the following characters: # optional digit 0 required digit $ dollar sign, commas where appropriate % (automatically multiplies value by 100) Page 15 of 16

16 Examples DecimalFormat fmtcurrency = new DecimalFormat( $#,##0.00 ); DecimalFormat fmtpercent = new DecimalFormat( #0.00% ); double cost = ; double discount = ; System.out.println( Cost is + fmtcurrency.format(cost) ); System.out.println( Discount is + fmtpercent.format(discount) ); Output Cost is $5, Discount is 5.25% Page 16 of 16

Introductory Mobile Application Development

Introductory 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 information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. 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 information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. 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 information

A variable is a name for a location in memory A variable must be declared

A 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 information

Basics of Java Programming

Basics 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 information

Class Library java.util Package. Bok, Jong Soon

Class Library java.util Package. Bok, Jong Soon Class Library java.util Package Bok, Jong Soon javaexpert@nate.com www.javaexpert.co.kr Enumeration interface An object that implements the Enumeration interface generates a series of elements, one

More information

CST242 Strings and Characters Page 1

CST242 Strings and Characters Page 1 CST242 Strings and Characters Page 1 1 2 3 4 5 6 Strings, Characters and Regular Expressions CST242 char and String Variables A char is a Java data type (a primitive numeric) that uses two bytes (16 bits)

More information

Working with Strings. Husni. "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc.

Working with Strings. Husni. The Practice of Computing Using Python, Punch & Enbody, Copyright 2013 Pearson Education, Inc. Working with Strings Husni "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc. Sequence of characters We've talked about strings being a sequence of characters.

More information

Sequence of Characters. Non-printing Characters. And Then There Is """ """ Subset of UTF-8. String Representation 6/5/2018.

Sequence of Characters. Non-printing Characters. And Then There Is   Subset of UTF-8. String Representation 6/5/2018. Chapter 4 Working with Strings Sequence of Characters we've talked about strings being a sequence of characters. a string is indicated between ' ' or " " the exact sequence of characters is maintained

More information

Final Exam. CSC 121 Fall 2015 TTH. Lecturer: Howard Rosenthal. Dec. 15, 2015

Final Exam. CSC 121 Fall 2015 TTH. Lecturer: Howard Rosenthal. Dec. 15, 2015 Final Exam. CSC 121 Fall 2015 TTH Lecturer: Howard Rosenthal Dec. 15, 2015 Your Name: Key The following questions (or parts of questions) in numbers 1-17 are all worth 2 points each. The programs have

More information

CSCI 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 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 information

Chapter 2: Using Data

Chapter 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 information

Creating Strings. String Length

Creating 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 information

Date & Time Handling In JAVA

Date & Time Handling In JAVA Date & Time Handling In JAVA Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 1 Date and

More information

More on variables and methods

More 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 information

Reserved Words and Identifiers

Reserved Words and Identifiers 1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

More information

Database Programming with SQL 5-1 Conversion Functions. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Programming with SQL 5-1 Conversion Functions. Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Programming with SQL 5-1 Objectives This lesson covers the following objectives: Provide an example of an explicit data-type conversion and an implicit data-type conversion Explain why it is important,

More information

EnableBasic. The Enable Basic language. Modified by Admin on Sep 13, Parent page: Scripting Languages

EnableBasic. The Enable Basic language. Modified by Admin on Sep 13, Parent page: Scripting Languages EnableBasic Old Content - visit altium.com/documentation Modified by Admin on Sep 13, 2017 Parent page: Scripting Languages This Enable Basic Reference provides an overview of the structure of scripts

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

CS 1301 Ch 8, Part A

CS 1301 Ch 8, Part A CS 1301 Ch 8, Part A Sections Pages Review Questions Programming Exercises 8.1 8.8 264 291 1 30 2,4,6,8,10,12,14,16,18,24,28 This section of notes discusses the String class. The String Class 1. A String

More information

Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly

Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly Basic Computation Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly Parentheses and Precedence Parentheses can communicate the order in which arithmetic operations are performed examples: (cost +

More information

Using Microsoft Excel

Using Microsoft Excel Using Microsoft Excel Formatting a spreadsheet means changing the way it looks to make it neater and more attractive. Formatting changes can include modifying number styles, text size and colours. Many

More information

Strings. Strings and their methods. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Strings. 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

COMP6700/2140 Data and Types

COMP6700/2140 Data and Types COMP6700/2140 Data and Types Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU February 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February

More information

Datatypes, Variables, and Operations

Datatypes, Variables, and Operations Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit

More information

The Practice of Computing Using PYTHON. Chapter 4. Working with Strings. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

The Practice of Computing Using PYTHON. Chapter 4. Working with Strings. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 4 Working with Strings 1 Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Sequence of Characters We

More information

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur 1 Number Representation 2 1 Topics to be Discussed How are numeric data items actually

More information

Using Java Classes Fall 2018 Margaret Reid-Miller

Using 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 information

Using Custom Number Formats

Using Custom Number Formats APPENDIX B Using Custom Number Formats Although Excel provides a good variety of built-in number formats, you may find that none of these suits your needs. This appendix describes how to create custom

More information

"Hello" " This " + "is String " + "concatenation"

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 information

COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016

COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016 COMP-202: Foundations of Programming Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016 More Tutoring Help The Engineering Peer Tutoring Services (EPTS) is hosting free tutoring sessions

More information

ITP 342 Mobile App Dev. Strings

ITP 342 Mobile App Dev. Strings ITP 342 Mobile App Dev Strings Strings You can include predefined String values within your code as string literals. A string literal is a sequence of characters surrounded by double quotation marks (").

More information

Agenda & Reading. VB.NET Programming. Data Types. COMPSCI 280 S1 Applications Programming. Programming Fundamentals

Agenda & Reading. VB.NET Programming. Data Types. COMPSCI 280 S1 Applications Programming. Programming Fundamentals Agenda & Reading COMPSCI 80 S Applications Programming Programming Fundamentals Data s Agenda: Data s Value s Reference s Constants Literals Enumerations Conversions Implicitly Explicitly Boxing and unboxing

More information

1. Introduction to Microsoft Excel

1. Introduction to Microsoft Excel 1. Introduction to Microsoft Excel A spreadsheet is an online version of an accountant's worksheet, which can automatically do most of the calculating for you. You can do budgets, analyze data, or generate

More information

Formatted Output Pearson Education, Inc. All rights reserved.

Formatted 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 information

Java s String Class. in simplest form, just quoted text. used as parameters to. "This is a string" "So is this" "hi"

Java 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 information

Full file at

Full 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 information

Review 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 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 information

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003 Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

More information

A Java program contains at least one class definition.

A Java program contains at least one class definition. Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Instructor s Notes Web Data Management PHP Sequential Processing Syntax. Web Data Management PHP Sequential Processing Syntax

Instructor s Notes Web Data Management PHP Sequential Processing Syntax. Web Data Management PHP Sequential Processing Syntax Instructor s Web Data Management PHP Sequential Processing Syntax Web Data Management 152-155 PHP Sequential Processing Syntax Quick Links & Text References PHP tags in HTML Pages Comments Pages 48 49

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

Exercise: Using Numbers

Exercise: Using Numbers Exercise: Using Numbers Problem: You are a spy going into an evil party to find the super-secret code phrase (made up of letters and spaces), which you will immediately send via text message to your team

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

More information

Chapter 2: Using Data

Chapter 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 information

Comments in a Java Program. Java Overview. Identifiers. Identifier Conventions. Primitive Data Types and Declaring Variables

Comments in a Java Program. Java Overview. Identifiers. Identifier Conventions. Primitive Data Types and Declaring Variables Comments in a Java Program Java Overview Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over multiple lines like C Example: /* This is a multiple

More information

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Data 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 information

Getting started with Java

Getting 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 information

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing. CISC-124 20180115 20180116 20180118 We continued our introductory exploration of Java and object-oriented programming by looking at a program that uses two classes. We created a Java file Dog.java and

More information

Adobe EchoSign Calculated Fields Guide

Adobe EchoSign Calculated Fields Guide Adobe EchoSign Calculated Fields Guide Version 1.0 Last Updated: May, 2013 Table of Contents Table of Contents... 2 Overview... 3 Calculated Fields Use-Cases... 3 Calculated Fields Basics... 3 Calculated

More information

Declaration and Memory

Declaration and Memory Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

More information

Lesson:9 Working with Array and String

Lesson:9 Working with Array and String Introduction to Array: Lesson:9 Working with Array and String An Array is a variable representing a collection of homogeneous type of elements. Arrays are useful to represent vector, matrix and other multi-dimensional

More information

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 02 Data Types and Statements MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Data Types Arithmetic

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

More information

Variables and Data Representation

Variables and Data Representation You will recall that a computer program is a set of instructions that tell a computer how to transform a given set of input into a specific output. Any program, procedural, event driven or object oriented

More information

Variables and Constants

Variables and Constants HOUR 3 Variables and Constants Programs need a way to store the data they use. Variables and constants offer various ways to work with numbers and other values. In this hour you learn: How to declare and

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

More non-primitive types Lesson 06

More non-primitive types Lesson 06 CSC110 2.0 Object Oriented Programming Ms. Gnanakanthi Makalanda Dept. of Computer Science University of Sri Jayewardenepura More non-primitive types Lesson 06 1 2 Outline 1. Two-dimensional arrays 2.

More information

GraphQuil Language Reference Manual COMS W4115

GraphQuil Language Reference Manual COMS W4115 GraphQuil Language Reference Manual COMS W4115 Steven Weiner (Systems Architect), Jon Paul (Manager), John Heizelman (Language Guru), Gemma Ragozzine (Tester) Chapter 1 - Introduction Chapter 2 - Types

More information

AP Computer Science A

AP 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 information

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space. Chapter 2: Problem Solving Using C++ TRUE/FALSE 1. Modular programs are easier to develop, correct, and modify than programs constructed in some other manner. ANS: T PTS: 1 REF: 45 2. One important requirement

More information

Chapter 2: Data and Expressions

Chapter 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 information

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: Bits and Bytes and Numbers Number Systems Much of this is review, given the 221 prerequisite Question: how high can

More information

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

Preview from Notesale.co.uk Page 9 of 108

Preview from Notesale.co.uk Page 9 of 108 The following list shows the reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names. abstract assert boolean break byte case catch char class

More information

RTL Reference 1. JVM. 2. Lexical Conventions

RTL Reference 1. JVM. 2. Lexical Conventions RTL Reference 1. JVM Record Transformation Language (RTL) runs on the JVM. Runtime support for operations on data types are all implemented in Java. This constrains the data types to be compatible to Java's

More information

Memory Addressing, Binary, and Hexadecimal Review

Memory Addressing, Binary, and Hexadecimal Review C++ By A EXAMPLE Memory Addressing, Binary, and Hexadecimal Review You do not have to understand the concepts in this appendix to become well-versed in C++. You can master C++, however, only if you spend

More information

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators, Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators, Expressions, Statements and Arrays. Java technology is: A programming

More information

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

More information

More About Objects and Methods. Objectives. Outline. Chapter 6

More About Objects and Methods. Objectives. Outline. Chapter 6 More About Objects and Methods Chapter 6 Objectives learn to define constructor methods learn about static methods and static variables learn about packages and import statements learn about top-down design

More information

More About Objects and Methods

More About Objects and Methods More About Objects and Methods Chapter 6 Objectives learn to define constructor methods learn about static methods and static variables learn about packages and import statements learn about top-down design

More information

COP Programming Assignment #7

COP Programming Assignment #7 1 of 5 03/13/07 12:36 COP 3330 - Programming Assignment #7 Due: Mon, Nov 21 (revised) Objective: Upon completion of this program, you should gain experience with operator overloading, as well as further

More information

Chapter 2 Elementary Programming

Chapter 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 information

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2 Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2 Prepared for course 160410/411 Michael C. Kunkel m.kunkel@fz-juelich.de Materials taken from; docs.oracle.com Teach Yourself

More information

Topic Notes: Bits and Bytes and Numbers

Topic Notes: Bits and Bytes and Numbers Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for

More information

Using Microsoft Excel

Using Microsoft Excel Using Microsoft Excel Excel contains numerous tools that are intended to meet a wide range of requirements. Some of the more specialised tools are useful to only certain types of people while others have

More information

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science) The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

More information

MODULE 02: BASIC COMPUTATION IN JAVA

MODULE 02: BASIC COMPUTATION IN JAVA MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment

More information

Strings are actually 'objects' Strings

Strings are actually 'objects' Strings Strings are actually 'objects' Strings What is an object?! An object is a concept that we can encapsulate data along with the functions that might need to access or manipulate that data. What is an object?!

More information

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 02 Data Types and Statements MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Constants Data Types

More information

We 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 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 information

CISC-124. This week we continued to look at some aspects of Java and how they relate to building reliable software.

CISC-124. This week we continued to look at some aspects of Java and how they relate to building reliable software. CISC-124 20180129 20180130 20180201 This week we continued to look at some aspects of Java and how they relate to building reliable software. Multi-Dimensional Arrays Like most languages, Java permits

More information

Java Basic Datatypees

Java 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 information

Strings in Java String Methods. The only operator that can be applied to String objects is concatenation (+) for combining one or more strings.

Strings in Java String Methods. The only operator that can be applied to String objects is concatenation (+) for combining one or more strings. The only operator that can be applied to String objects is concatenation (+) for combining one or more strings. Java also provides many methods with the String class to allow us to manipulate text. These

More information

Intro to Strings. CSE 231 Rich Enbody. String: a sequence of characters. Indicated with quotes: or " " 9/11/13

Intro to Strings. CSE 231 Rich Enbody. String: a sequence of characters. Indicated with quotes: or   9/11/13 CSE 231 Rich Enbody String: a sequence of characters. Indicated with quotes: or " " 2 1 Triple quotes: preserve both the vertical and horizontal formatting of the string. Allows you to type tables, paragraphs,

More information

CIS133J. Working with Numbers in Java

CIS133J. Working with Numbers in Java CIS133J Working with Numbers in Java Contents: Using variables with integral numbers Using variables with floating point numbers How to declare integral variables How to declare floating point variables

More information

Introduction to Programming Using Java (98-388)

Introduction 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 information

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2 Java Foundations Introduction to Program Design and Data Structures 4th Edition Lewis TEST BANK Full download at : https://testbankreal.com/download/java-foundations-introduction-toprogram-design-and-data-structures-4th-edition-lewis-test-bank/

More information

STUDENT LESSON A7 Simple I/O

STUDENT LESSON A7 Simple I/O STUDENT LESSON A7 Simple I/O Java Curriculum for AP Computer Science, Student Lesson A7 1 STUDENT LESSON A7 Simple I/O INTRODUCTION: The input and output of a program s data is usually referred to as I/O.

More information

Java Fall 2018 Margaret Reid-Miller

Java Fall 2018 Margaret Reid-Miller Java 15-121 Fall 2018 Margaret Reid-Miller Reminders How many late days can you use all semester? 3 How many late days can you use for a single assignment? 1 What is the penalty for turning an assignment

More information

BASIC INPUT/OUTPUT. Fundamentals of Computer Science

BASIC INPUT/OUTPUT. Fundamentals of Computer Science BASIC INPUT/OUTPUT Fundamentals of Computer Science Outline: Basic Input/Output Screen Output Keyboard Input Simple Screen Output System.out.println("The count is " + count); Outputs the sting literal

More information

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1 topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1-fall2007-sklar-leci.2 1 Java. Java is an object-oriented language: it is

More information

Objects and Classes 1: Encapsulation, Strings and Things CSC 121 Fall 2014 Howard Rosenthal

Objects and Classes 1: Encapsulation, Strings and Things CSC 121 Fall 2014 Howard Rosenthal Objects and Classes 1: Encapsulation, Strings and Things CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Understand objects and classes Understand Encapsulation Learn about additional Java classes The

More information

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

1 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

1 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 information

Universal Format Plug-in User s Guide. Version 10g Release 3 (10.3)

Universal Format Plug-in User s Guide. Version 10g Release 3 (10.3) Universal Format Plug-in User s Guide Version 10g Release 3 (10.3) UNIVERSAL... 3 TERMINOLOGY... 3 CREATING A UNIVERSAL FORMAT... 5 CREATING A UNIVERSAL FORMAT BASED ON AN EXISTING UNIVERSAL FORMAT...

More information

BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2

BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2 1 BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER Chapter 2 2 3 Types of Problems that can be solved on computers : Computational problems involving some kind of mathematical processing Logical Problems

More information

Arithmetic Expressions in C

Arithmetic Expressions in C Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic

More information