CHAPTER 6 MOST COMMONLY USED LIBRARIES

Size: px
Start display at page:

Download "CHAPTER 6 MOST COMMONLY USED LIBRARIES"

Transcription

1 LIBRARY CHAPTER 6 - A set of ready-made software routines (class definitions) that can be reused in new programs, is called a Library. - Some commonly used java libraries are : Math Library String Library IO(Input/output) Library WORKING WITH STRINGS Java offers two classes to work with string data: 1. String Class Whose instances or object can hold unchanging string (immutable string) i.e. once initialized its contents cannot be modified. 2. StringBuffer Class Whose instance or objects can hold (mutable) strings that can be changed or modified. CREATING STRINGS String <object/variable> = <value of object/variable> ; e.g. String name = I am a Student ; CREATING STRINGBUFFERS Java provide three ways to create Stringbuffer object: 1. StringBuffer s = new StringBuffer( ); This method creates an empty StringBuffer object namely s. 2. StringBuffer str = new StringBuffer( First ); This method creates a StringBuffer object namely str and initializes it with string value First. 3. int n =15; StringBuffer str2 = new StringBuffer(n); This method creates the StringBuffer with an initial capacity equal to n (=15 here) number of characters. METHODS OF STRING CLASS 1. char charat( int index) - Returns the character at the specified index. e.g. String a = INFORMATICS PRACTICE ; char ch=a.charat(0); System.out.println( +ch ); The value in ch will be I as the index of this character is int capacity( ) - Returns maximum no. of characters that can be entered in the string object. Page 1 of 8

2 e.g. CHAPTER 6 String a = INFORMATICS PRACTICES ; int cap =a.capacity( ); System.out.println( +cap ); The output is int compareto( String1 ) - Compares two strings lexicographically. 0 (Zero) is returned if the strings are identical. e.g.1 String a = ABC ; String b = ABC ; int c = a.compareto(b); System.out.println( +c ); The output is 0. e.g.2 String a = ABC ; String b = DBC ; int c = a.compareto(b); System.out.println( +c ); The output is String concat(string str) - Concatenates the specified string to the end of this string (current string object). e.g. String a = INFORMATICS ; String b = PRACTICES ; String c = a.concat (b); OR String c = a + b ; System.out.println(c) ; 6. boolean equals(string) The output is INFORMATICSPRACTICES - compares this string (current string object) to the specified string. e.g. e.g. 2. String a = IBCM ; String b = IBCM ; boolean c = a. equals(b); The output is true String a = IBCM ; String b = ibcm ; boolean c = a. equals(b); The output is false Page 2 of 8

3 7. boolean equalsignorecase(string) - compares this string (current string object) to the specified string, ignoring case consideration. e.g. String p= INFORM ; String q= inform ; boolean r = p.equalsignorecase(q); System.out.println( +r); The output is true 8. int indexof(char) - Returns the index within the this string (current string object) of the first occurrence of the specified character. 9. int lastindexof(char) String b = INTIMATION ; int z = b.indexof( I ); System.out.println( +z); The output is 0 - Returns the character within this string of the last occurrence of the specified character. 10. int length( ) String b = INTIMATION ; int z = b.lastindexof( I ); System.out.println( +z); The output is 7 - Returns the length of this string. String a= INFORMATICS ; int b = a.length( ); System.out.println( +b); The output is String replace(char oldchar, char newchar) - Returns a new string resulting from replacing all occurrence of old char in this string with new char. String a = INFORMATION ; String c = a.replace( I, P ); System.out.println( +b); 12. boolean endswith(string) The output is PNFORMATPON - Tests if this string (current String object) ends with the specified suffix. e.g. String a = INFORMATICS ; boolean s = a.endswith( MATICS ); Page 3 of 8

4 13. boolean startswith(string) CHAPTER 6 System.out.println( s); The output is true for above code. - Tests if this string (current String object) starts with specified suffix. e.g. String a = JAVAPROGRAM ; boolean s = a.startswith( JAVA ); System.out.println( s); The output is true for above code. 14. String substring(int, int ) - Returns a new string that is a substring of the this string. e.g.1. String a = INFORMATICS PRACTICES ; String c = a.substring(0,5); System.out.println( +c); The output is INFOR e.g.2. String a = INFORMATICS PRACTICES ; String c = a.substring(8,13); System.out.println( +c); The output is ICS P 15. String tolowercase( ) - Converts all the characters in this String to lower case. e.g. String z = PRACTICES ; String n = z.tolowercase( ); System.out.println( +n); The output is practices 16. String touppercase( ) - Converts all the characters in this String to upper case. e.g. String z = Informatics ; String n = z.touppercase( ); System.out.println( +n); The output is INFORMATICS 17. String trim( ) - Removes white spaces from both sides of this String. e.g. String a = INFORMATION ; String c = a. trim ( ) ; The output is INFORMATION Page 4 of 8

5 18. String valueof(all types) - Returns the String representation of the passed argument. e.g. int a = 123 ; valueof(a) ; The value retuned by above statement is 123 STRING BUFFER METHODS 1. String append (String) - adds the specified string in parameter at the end of current String object. e.g. StringBuffer s = new StringBuffer( INFORMATICS ); String c = s.append( PRACTICES ); The Output is INFORMATICSPRACTICES 2. String insert(int, String) - adds the string specified in parameter, at the index specified in first parameter. e.g. StringBuffer s = new StringBuffer( IFORM ); String c = s.insert(1, N ); The output is INFORM 3. String setcharat (int, char ) - Alter just one character. It replaces character specified in second parameter at the index specified in first parameter. e.g. StringBuffer b = new StringBuffer( POGRAM ); String c = b.setcharat(1, R ); The output is PROGRAM 4. String delete (int beginindex, int endindex) -delete the characters from begin to end index. e.g. StringBuffer s = new StringBuffer( INFORMATICS ); String c = s.delete(6,10); The output is INFORM 5. String reverse( ) - Reverse the content of String Buffer. e.g. StringBuffer str = new StringBuffer( POWDER ); String a = str.reverse( ); System.out.println( +a); The output is REDWOP Page 5 of 8

6 MATH CLASS METHODS 1. pow ( ) - This method returns the first argument raised to the power of the second argument. Syntax is : double pow(double, double) OR int pow(int, int) e.g. Math.pow(2, 3) = 2 3 = 8. Math.pow(2.0, 2.0 ) = = round( ) - Round off the number to the nearest integer. Syntax is : double round( double) OR float round(float) e.g. Math.round(1.5) = 2 Math.round(1.568, 2) = 1.57 Math.round(2.68, 0) = 3 PROBLEMS Q1. Write the output that will be displayed in the textfields by the following Java code : String x ; String stream = Commerce ; jtextfield1.settext((stream.length( ) + 9) + ); x = stream.concat( Humainities ); jtextfield2.settext(x); jtextfield3.settext( +x. substring(2,5)); jtextfield4.settext(stream.tolowercase( )); Q2. Predict the output of the following code : String s = COMPUTER ; int L = s.length(); for(int i =L ; i >=0 ; i--) System.out.println(s.substring(0, i)); Q3. What will be the content of jtextarea1 after the execution of the following statement? String message = All the Best ; jtextfield1.settext((message.length() - 6 )+ ); Q4. What will be the value of X1 after the execution of the following code? String X1= Graduate, X2= Post ; X1=X2.concat(X1); Page 6 of 8

7 Q5. Give the output of the following java code: String name = Sid Nagar ; int T = name.length( ), N ; N = 150 T ; jtextfield2.settext(integer.tostring(t)); jtextfield3.settext(integer.tostring(n)); Q6. What will be the contents of jtextfield1 and jtextfield2 after executing the following code : String s = Best ; jtextfield1.settext(s.length( ) + ); jtextfield2.settext(s.touppercase( )); Q7. What will be the contents of str1 and str2 after the following code is executed? String Str2, Str1 ; Str1 = Dear Friend ; Str2 = Hello ; Str1 = Str2.concat(Str1); Q8. What will be the contents of jtextfield1 and jtextfield2 after executing the following : String name1 = Hello World ; Name1 = name.tolowercase( ) ; String name2 = name1.replace(,! ); jtextfield1.settext(name1); jtextfield2.settext(name2); Q9. Given an int variable K with value 253. It is converted into equivalent string i.e What are two ways of doing this? Q10. Write the output : System.out.println(Math.pow(4.0,2.0)); System.out.println(Math.pow(6.459)); Q11.What will be the contents of jtextfield1 and jtextfield2 after executing the following code: String s = ABC MicroSystems ; jtextfield1.settext(s.length( ) + ); jtextfield2.settext(s.tolowercase( )); Q12. Given a String object named code having value as 908 stored in it. What will be result of the following? JOptionPane.showMessageDialog(null, +(code.length( ) +Integer.parseInt(code)); Q13. Assuming String age = 17 ; Write the Java expression to store value of age in a variable of double type(say double d). Q14. What will be the value of X1 after execution of the following code : String X1= Spread, X2= PEACE ; X1 = X2.concat(X1); Q15. What will be the content of jtextfield1 and jtextfield2 after executing the following code: String st = New to Information Technology ; jtextfield1.settext(st.replace( Technology, Practices )); jtextfield2.settext(st.substring(7)); Page 7 of 8

8 Page 8 of 8

"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

Appendix 3. Description: Syntax: Parameters: Return Value: Example: Java - String charat() Method

Appendix 3. Description: Syntax: Parameters: Return Value: Example: Java - String charat() Method Appendix 3 Java - String charat() Method This method returns the character located at the String's specified index. The string indexes start from zero. public char charat(int index) index -- Index of the

More information

2. All the strings gets collected in a special memory are for Strings called " String constant pool".

2. All the strings gets collected in a special memory are for Strings called  String constant pool. Basics about Strings in Java 1. You can create Strings in various ways:- a) By Creating a String Object String s=new String("abcdef"); b) By just creating object and then referring to string String a=new

More information

Lab 14 & 15: String Handling

Lab 14 & 15: String Handling Lab 14 & 15: String Handling Prof. Navrati Saxena TA: Rochak Sachan String Handling 9/11/2012 22 String Handling Java implements strings as objects of type String. Once a String object has been created,

More information

String. Other languages that implement strings as character arrays

String. Other languages that implement strings as character arrays 1. length() 2. tostring() 3. charat() 4. getchars() 5. getbytes() 6. tochararray() 7. equals() 8. equalsignorecase() 9. regionmatches() 10. startswith() 11. endswith() 12. compareto() 13. indexof() 14.

More information

J.43 The length field of an array object makes the length of the array available. J.44 ARRAYS

J.43 The length field of an array object makes the length of the array available. J.44 ARRAYS ARRAYS A Java array is an Object that holds an ordered collection of elements. Components of an array can be primitive types or may reference objects, including other arrays. Arrays can be declared, allocated,

More information

appreciate the difference between a char and a string understand and use the String class methods

appreciate the difference between a char and a string understand and use the String class methods 1 8 THE STRING CLASS Terry Marris 16 April 2001 8.1 OBJECTIVES By the end of this lesson the student should be able to appreciate the difference between a char and a string understand and use the String

More information

String related classes

String related classes Java Strings String related classes Java provides three String related classes java.lang package String class: Storing and processing Strings but Strings created using the String class cannot be modified

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A CSC 1051 Algorithms and Data Structures I Midterm Examination March 1, 2018 Name: KEY A Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make

More information

Object-Oriented Programming

Object-Oriented Programming Data structures Object-Oriented Programming Outline Primitive data types String Math class Array Container classes Readings: HFJ: Ch. 13, 6. GT: Ch. 13, 6. Đại học Công nghệ - ĐHQG HN Data structures 2

More 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

CS112 Lecture: Characters and Strings

CS112 Lecture: Characters and Strings CS112 Lecture: Characters and Strings Objectives: Last Revised 3/21/06 1. To introduce the data type char and related basic information (escape sequences, Unicode). 2. To introduce the library classes

More information

Lecture Notes K.Yellaswamy Assistant Professor K L University

Lecture Notes K.Yellaswamy Assistant Professor K L University Lecture Notes K.Yellaswamy Assistant Professor K L University Building Strings and Exploring String Class: -------------------------------------------- The String class ------------------- String: A String

More information

Building Strings and Exploring String Class:

Building Strings and Exploring String Class: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Lecture Notes K.Yellaswamy Assistant Professor CMR College of Engineering & Technology Building Strings and Exploring

More information

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination Thursday, December 11, 2008 Examiners: Mathieu Petitpas [Section 1] 14:00

More information

STUDENT LESSON A10 The String Class

STUDENT LESSON A10 The String Class STUDENT LESSON A10 The String Class Java Curriculum for AP Computer Science, Student Lesson A10 1 STUDENT LESSON A10 The String Class INTRODUCTION: Strings are needed in many programming tasks. Much of

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name: CSC 1051 Algorithms and Data Structures I Midterm Examination March 2, 2017 Name: Question Value Score 1 10 2 10 3 20 4 20 5 20 6 20 TOTAL 100 Please answer questions in the spaces provided. If you make

More information

OOP-Lecture Java Loop Controls: 1 Lecturer: Hawraa Sh. You can use one of the following three loops: while Loop do...while Loop for Loop

OOP-Lecture Java Loop Controls: 1 Lecturer: Hawraa Sh. You can use one of the following three loops: while Loop do...while Loop for Loop Java Loop Controls: You can use one of the following three loops: while Loop do...while Loop for Loop 1- The while Loop: A while loop is a control structure that allows you to repeat a task a certain number

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

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

Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University Mathematical Functions, Characters, and Strings CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Static methods Remember the main method header? public static void

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name: CSC 1051 Algorithms and Data Structures I Midterm Examination October 6, 2016 Name: Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make a

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

USING LIBRARY CLASSES

USING LIBRARY CLASSES USING LIBRARY CLASSES Simple input, output. String, static variables and static methods, packages and import statements. Q. What is the difference between byte oriented IO and character oriented IO? How

More information

Strings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects.

Strings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. 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

Class Library java.lang Package. Bok, Jong Soon

Class Library java.lang Package. Bok, Jong Soon Class Library java.lang Package Bok, Jong Soon javaexpert@nate.com www.javaexpert.co.kr Object class Is the root of the class hierarchy. Every class has Object as a superclass. If no inheritance is specified

More information

Programming with Java

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

Class. Chapter 6: Data Abstraction. Example. Class

Class. Chapter 6: Data Abstraction. Example. Class Chapter 6: Data Abstraction In Java, there are three types of data values primitives arrays objects actually, arrays are a special type of object Class In Java, objects are used to represent data values

More information

TEXT-BASED APPLICATIONS

TEXT-BASED APPLICATIONS Objectives 9 TEXT-BASED APPLICATIONS Write a program that uses command-line arguments and system properties Write a program that reads from standard input Write a program that can create, read, and write

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY CSC 1051 Algorithms and Data Structures I Midterm Examination October 11, 2018 Name: KEY Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make

More information

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016 First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm

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

Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University Mathematical Functions, Characters, and Strings CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Static methods Remember the main method header? public static void

More information

CS-140 Fall Binghamton University. Methods. Sect. 3.3, 8.2. There s a method in my madness.

CS-140 Fall Binghamton University. Methods. Sect. 3.3, 8.2. There s a method in my madness. Methods There s a method in my madness. Sect. 3.3, 8.2 1 Example Class: Car How Cars are Described Make Model Year Color Owner Location Mileage Actions that can be applied to cars Create a new car Transfer

More 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

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Mathematical Functions Java provides many useful methods in the Math class for performing common mathematical

More 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

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

CLASS X. THEORY 100 Marks

CLASS X. THEORY 100 Marks There will be one written paper of two hours duration carrying 100 marks and Internal Assessment of 100 marks. The paper will be divided into two sections A and B. Section A (Compulsory 40 marks) will

More information

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

Strings. Strings and their methods. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics Strings Strings and their methods Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list Primitive Types: char Object Types: String Primitive

More information

Brief Summary of the Chapter: CHAPTER-6 MORE ABOUT CLASSES AND LIBRARIES In this chapter the way access of members of a class i.e. about access specifier will be discuss. Java include predefined classes

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

Mathematics for Computer Graphics - Lecture 12

Mathematics for Computer Graphics - Lecture 12 Mathematics for Computer Graphics - Lecture 12 Dr. Philippe B. Laval Kennesaw State University October 6, 2003 Abstract This document is about creating Java Applets as they relate to the project we are

More information

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) - All Sections Final Examination

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) - All Sections Final Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) - All Sections Final Examination Wednesday, April 29, 2009 Examiners: Mathieu Petitpas

More 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

Chapter 4 Mathematical Functions, Characters, and Strings

Chapter 4 Mathematical Functions, Characters, and Strings Chapter 4 Mathematical Functions, Characters, and Strings Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited 2015 1 Motivations Suppose you need to estimate

More information

Intro to Strings. Lecture 7 COP 3252 Summer May 23, 2017

Intro to Strings. Lecture 7 COP 3252 Summer May 23, 2017 Intro to Strings Lecture 7 COP 3252 Summer 2017 May 23, 2017 Strings in Java In Java, a string is an object. It is not a primitive type. The String class is used to create and store immutable strings.

More information

STRINGS AND STRINGBUILDERS. Spring 2019

STRINGS AND STRINGBUILDERS. Spring 2019 STRINGS AND STRINGBUILDERS Spring 2019 STRING BASICS In Java, a string is an object. Three important pre-built classes used in string processing: the String class used to create and store immutable strings

More information

Ans: Store s as an expandable array of chars. (Double its size whenever we run out of space.) Cast the final array to a String.

Ans: Store s as an expandable array of chars. (Double its size whenever we run out of space.) Cast the final array to a String. CMSC 131: Chapter 21 (Supplement) Miscellany Miscellany Today we discuss a number of unrelated but useful topics that have just not fit into earlier lectures. These include: StringBuffer: A handy class

More information

Overloaded Methods. Sending Messages. Overloaded Constructors. Sending Parameters

Overloaded Methods. Sending Messages. Overloaded Constructors. Sending Parameters Overloaded Methods Sending Messages Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Initialization & Cleanup 2 Overloaded Constructors Sending Parameters accessor method 3 4 Sending Parameters

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain Duhok Polytechnic University Amedi Technical Institute/ IT Dept. By Halkawt Rajab Hussain 2016-04-02 String and files: String declaration and initialization. Strings and Char Arrays: Properties And Methods.

More information

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Internal Examination 1 Answer Key DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Branch & Sec : CSE Date : 08.08.2014 Semester : V Sem Max Marks : 50 Marks Sub Code& Title : CS2305 Programming Paradigms

More information

SOFTWARE DEVELOPMENT 1. Strings and Enumerations 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

SOFTWARE DEVELOPMENT 1. Strings and Enumerations 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz) SOFTWARE DEVELOPMENT 1 Strings and Enumerations 2018W (Institute of Pervasive Computing, JKU Linz) CHARACTER ENCODING On digital systems, each character is represented by a specific number. The character

More 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

TechSparxJavaTuitionsTechSparxJava

TechSparxJavaTuitionsTechSparxJava TechSparxJavaTuitionsTechSparxJava Java Question Bank TuitionsTechSparxJavaTuitionsTechSp arxjavatuitionstechsparxjavatuitions TechSparxJavaTuitionsTechSparxJava Tuitions Better than a thousand days of

More information

More on Strings. Lecture 10 CGS 3416 Fall October 13, 2015

More on Strings. Lecture 10 CGS 3416 Fall October 13, 2015 More on Strings Lecture 10 CGS 3416 Fall 2015 October 13, 2015 What we know so far In Java, a string is an object. The String class is used to create and store immutable strings. Some String class methods

More information

Eng. Mohammed Abdualal

Eng. Mohammed Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2124) Lab 2 String & Character Eng. Mohammed Abdualal String Class In this lab, you have

More information

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February 2006 11.05-12.35 Please fill in your Examination Number here: Student Number here: All answers to

More information

Chapter 29: String and Object References Bradley Kjell (Revised 06/15/2008)

Chapter 29: String and Object References Bradley Kjell (Revised 06/15/2008) Chapter 29: String and Object References Bradley Kjell (Revised 06/15/2008) In previous chapters, methods were called with parameters that were primitive data types. This chapter discusses how to use object

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

Intro to Computer Science II

Intro to Computer Science II Intro to Computer Science II CS112-2012S-04 Strings David Galles Department of Computer Science University of San Francisco 04-0: Types in Java Primative Types Hold simple values Can be stored on the stack

More information

ADVANCED PROGRAMMING CONCEPTS

ADVANCED PROGRAMMING CONCEPTS 5 CHAPTER Learning Objectives ADVANCED PROGRAMMING CONCEPTS After studying this lesson the students will be able to: Define objects and their usage Appreciate the usage of native classes Math and String

More information

CSE1710. Big Picture. Tuesday, Dec 02 is designated as a study day. No classes. Thursday, Dec 04 is last lecture.

CSE1710. Big Picture. Tuesday, Dec 02 is designated as a study day. No classes. Thursday, Dec 04 is last lecture. CSE1710 Click to edit Master Week text 12, styles Lecture 22 Second level Third level Fourth level Fifth level Fall 2014 Tuesday, Nov 25, 2014 1 Big Picture Tuesday, Dec 02 is designated as a study day.

More information

Lecture 8: The String Class and Boolean Zen

Lecture 8: The String Class and Boolean Zen Lecture 8: The String Class and Boolean Zen Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Strings string: An object

More information

Visit for more.

Visit  for more. Chapter 5: Advanced Programming Concepts Informatics Practices Class XII (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra, PGT

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

CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II)

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

AP Computer Science. Strings. Credit: Slides are modified with permission from Barry Wittman at Elizabethtown College

AP Computer Science. Strings. Credit: Slides are modified with permission from Barry Wittman at Elizabethtown College Strings AP Computer Science Credit: Slides are modified with permission from Barry Wittman at Elizabethtown College This work is licensed under an Attribution-NonCommercial-ShareAlike 3.0 Unported License

More information

CSE1710. Big Picture. Today is last day covering Ch 6. Tuesday, Dec 02 is designated as a study day. No classes. Thursday, Dec 04 is last lecture.

CSE1710. Big Picture. Today is last day covering Ch 6. Tuesday, Dec 02 is designated as a study day. No classes. Thursday, Dec 04 is last lecture. CSE1710 Click to edit Master Week text 12, styles Lecture 23 Second level Third level Fourth level Fifth level Fall 2014! Thursday, Nov 27, 2014 1 Big Picture Today is last day covering Ch 6 Tuesday, Dec

More information

Java: Learning to Program with Robots

Java: Learning to Program with Robots Java: Learning to Program with Robots Chapter 07: More on Variables and Methods Chapter Objectives After studying this chapter, you should be able to: Write queries to reflect the state of an object Use

More information

Midterm Exam 2 Thursday, November 15th, points (15% of final grade) Instructors: Jim Williams and Marc Renault

Midterm Exam 2 Thursday, November 15th, points (15% of final grade) Instructors: Jim Williams and Marc Renault Computer Sciences 200 Midterm Exam 2 Thursday, November 15th, 2018 100 points (15% of final grade) Instructors: Jim Williams and Marc Renault (Family) Last Name: (Given) First Name: CS Login Name: NetID

More information

Strings! Today! CSE String Methods!

Strings! Today! CSE String Methods! Strings CSE 1710 Lecture 14, 15 String Handling We have covered three chunks of material: Week 1: String Literals pp. 22-23; Fig 1.12; PT 1.8 Week 6: The String Class Section 6.1.1, pp. 219-220 The Masquerade

More information

String is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents

String is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents String is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents character strings. All string literals in Java programs,

More information

Interaction with Android

Interaction with Android Interaction with Android The Android program can output data by working with the xml files. The main use of the java files is to get some data, make decisions and change the output based on the results

More information

Computer Science 252 Problem Solving with Java The College of Saint Rose Spring Topic Notes: Strings

Computer Science 252 Problem Solving with Java The College of Saint Rose Spring Topic Notes: Strings Computer Science 252 Problem Solving with Java The College of Saint Rose Spring 2016 Topic Notes: Strings This semester we ve spent most of our time on applications that are graphical in nature: Manipulating

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

Chapter 12 Strings and Characters. Dr. Hikmat Jaber

Chapter 12 Strings and Characters. Dr. Hikmat Jaber Chapter 12 Strings and Characters Dr. Hikmat Jaber 1 The String Class Constructing a String: String message = "Welcome to Java ; String message = new String("Welcome to Java ); String s = new String();

More information

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination Wednesday, December 16, 2009 Examiners: Mathieu Petitpas

More information

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to

More information

Java String Java String provides a lot of concepts that can be performed on a string such as compare, concat, equals, split, length, replace,

Java String Java String provides a lot of concepts that can be performed on a string such as compare, concat, equals, split, length, replace, Java String Java String provides a lot of concepts that can be performed on a string such as compare, concat, equals, split, length, replace, compareto, intern, substring etc. In java, string is basically

More information

Computer Science 145 Midterm 1 Fall 2016

Computer Science 145 Midterm 1 Fall 2016 Computer Science 145 Midterm 1 Fall 2016 Doodle here. This is a closed-book, no-calculator, no-electronic-devices, individual-effort exam. You may reference one page of handwritten notes. All answers should

More information

- Thus there is a String class (a large class)

- Thus there is a String class (a large class) Strings - Strings in Java are objects - Thus there is a String class (a large class) - In a statement like this: System.out.println( Hello World ); the Java compiler creates a String object from the quoted

More information

TEST (MODULE:- 1 and 2)

TEST (MODULE:- 1 and 2) TEST (MODULE:- 1 and 2) What are command line arguments? Write a program in JAVA to print Fibonacci series using command line arguments? [10] Create a class employee with data members empid, empname, designation

More information

Chapter 3: Using Classes and Objects

Chapter 3: Using Classes and Objects Chapter 3: Using Classes and Objects CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 3: Using Classes and Objects CS 121 1 / 51 Chapter 3 Topics

More information

Bellwork Strings 11/25/13

Bellwork Strings 11/25/13 Bellwork Strings 11/25/13 1. How have we been using Strings in Java for? 2. Why does String begin with a capital letter? 3. From your homework, what are the problems that we run into when we try to compare

More information

Intro to Strings. Lecture 7 CGS 3416 Spring February 13, Lecture 7 CGS 3416 Spring 2017 Intro to Strings February 13, / 16

Intro to Strings. Lecture 7 CGS 3416 Spring February 13, Lecture 7 CGS 3416 Spring 2017 Intro to Strings February 13, / 16 Intro to Strings Lecture 7 CGS 3416 Spring 2017 February 13, 2017 Lecture 7 CGS 3416 Spring 2017 Intro to Strings February 13, 2017 1 / 16 Strings in Java In Java, a string is an object. It is not a primitive

More information

CS-140 Fall Binghamton University. Methods. Sect. 3.3, 8.2. There s a method in my madness.

CS-140 Fall Binghamton University. Methods. Sect. 3.3, 8.2. There s a method in my madness. Methods There s a method in my madness. Sect. 3.3, 8.2 1 Example Class: Car How Cars are Described Make Model Year Color Owner Location Mileage Actions that can be applied to cars Create a new car Transfer

More information

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February 2006 11.05-12.35 Please fill in your Examination Number here: Student Number here: All answers to

More information

Java Programming. String Processing. 1 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Java Programming. String Processing. 1 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Java Programming String Processing 1 Copyright 2013, Oracle and/or its affiliates. All rights Overview This lesson covers the following topics: Read, search, and parse Strings Use StringBuilder to create

More information

COMPUTER APPLICATIONS (86)

COMPUTER APPLICATIONS (86) Aims: 1. To empower students by enabling them to build their own applications. 2. To introduce students to some effective tools to enable them to enhance their knowledge, broaden horizons, foster creativity,

More information

Class API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects

Class API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects CS200: Computer Science I Module 19 More Objects Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 Class API a class API can contain three different types of methods: 1. constructors

More information

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent Programming 2 Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent information Input can receive information

More information

CISC 370: Introduction to Java

CISC 370: Introduction to Java CISC 370: Introduction to Java Instructor: Sara Sprenkle sprenkle@cis cis.udel.eduedu TA: Ke Li kli@cis cis.udel.eduedu 1 What is Java? and, why should I learn it? Sara Sprenkle - CISC370 2 What is Java?

More information

C08c: A Few Classes in the Java Library (II)

C08c: A Few Classes in the Java Library (II) CISC 3115 TY3 C08c: A Few Classes in the Java Library (II) Hui Chen Department of Computer & Information Science CUNY Brooklyn College 9/20/2018 CUNY Brooklyn College 1 Outline Discussed Concepts of two

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasketEnhanced { public static void main(string[]

More information

Topic 13 procedural design and Strings

Topic 13 procedural design and Strings Topic 13 procedural design and Strings Ugly programs are like ugly suspension bridges: they're much more liable to collapse than pretty ones, because the way humans (especially engineerhumans) perceive

More information

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline Java Intro 3 9/7/2007 1 Java Intro 3 Outline Java API Packages Access Rules, Class Visibility Strings as Objects Wrapper classes Static Attributes & Methods Hello World details 9/7/2007 2 Class Libraries

More information

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

Java Foundations: Unit 3. Parts of a Java Program

Java Foundations: Unit 3. Parts of a Java Program Java Foundations: Unit 3 Parts of a Java Program class + name public class HelloWorld public static void main( String[] args ) System.out.println( Hello world! ); A class creates a new type, something

More information

Advanced Object Concepts

Advanced Object Concepts Understanding Blocks Blocks - Appears within any class or method, the code between a pair of curly braces Outside block- The first block, begins immediately after the method declaration and ends at the

More information