Mathematics for Computer Graphics - Lecture 12

Size: px
Start display at page:

Download "Mathematics for Computer Graphics - Lecture 12"

Transcription

1 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 developing in class. 1 Type Conversion Type conversion occurs when a variable of one type is assigned a value of another type. Type conversion can be done one of three ways: Automatic conversion Type casting Type conversion routines. 1.1 Automatic Conversion When one type of data is assigned to another type of variable, automatic type conversion will take place if the following two conditions are met: 1. The two types are compatible. 2. The destination type is larger than the source type. This type of conversion is often called a widening conversion. For example, an int can always hold a byte. A double can always hold a float. 1

2 1.2 Type Casting When the types are not compatible, a type cast must be used. The general form is (target type) value. For example, suppose that a is a double and b is a float. The statement b = a would cause an error because b cannot hold a. To force a type conversion, onemustuseatypecast.itwouldbeastatementoftheform 1.3 Conversion Routines b = (float) a The basic types such as int, double, float have been encapsulated in a class which has the same name but begins with an upper case letter. These classes hold an object of the basic type along with conversion routines. Let us look at some of these classes Integer This encapsulates the type int. There are two constructors: Integer(int value) Integer(String s) Some of the useful methods it implements are public double doublevalue() Returns the value of this integer as a double. There is a similar method for floatvalue(), intvalue(), longvalue, byte- Value() public static int parseint(string s) parses the string as a signed integer. public String tostring() returns the String representation of this int Long This encapsulates the type long. There are two constructors: Long(long value) Long(String s) Some of the useful methods it implements are 2

3 public double doublevalue() Returns the value of this long integer as a double. There is a similar method for floatvalue(), intvalue(), longvalue, byte- Value() public static long parselong(string s) parses the string as a signed long integer. public String tostring() returns the String representation of this long integer Double This encapsulates the type double. It has similar methods as the previous two types, and a few more. Here are some of the extra methods: public static boolean isinfinite(double d) public boolean isinfinite() public static boolean isnan(double d) public static boolean isnan() Float This encapsulates the type float. It has similar methods to Double String This class represents character strings. Here are the methods associated with it. Methods beginning with * are static. charat(int index) Returns the character at the specified index. compareto(string anotherstring) Compares two strings lexicographically. concat(string str) Concatenates the specified string to the end of this string. * copyvalueof(char[] data) Returns a String that is equivalent to the specified character array. * copyvalueof(char[] data, int offset, int count) Returns a String that is equivalent to the specified character array. endswith(string suffix) Tests if this string ends with the specified suffix. 3

4 equals(object anobject) Compares this string to the specified object. equalsignorecase(string anotherstring) Compares this String to another object. getchars(int srcbegin, int srcend, char[] dst, int dstbegin) Copies characters from this string into the destination character array. indexof(string str) Returns the index within this string of the first occurrence of the specified substring. indexof(string str, int fromindex) Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. indexof(int ch, int fromindex) Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. indexof(int ch) Returns the index within this string of the first occurrence of the specified character. lastindexof(string str, int fromindex) Returns the index within this string of the last occurrence of the specified substring. lastindexof(int ch, int fromindex) Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. lastindexof(int ch) Returns the index within this string of the last occurrence of the specified character. lastindexof(string str) Returns the index within this string of the rightmost occurrence of the specified substring. length() Returns the length of this string. regionmatches(boolean ignorecase, int toffset, String other, int ooffset, int len) Tests if two string regions are equal. regionmatches(int toffset, String other, int ooffset, int len) Tests if two string regions are equal. 4

5 replace(char oldchar, char newchar) Returns a new string resulting from replacing all occurrences of oldchar in this string with newchar. startswith(string prefix, int toffset) Tests if this string starts with the specified prefix. startswith(string prefix) Tests if this string starts with the specified prefix. substring(int beginindex) Returns a new string that is a substring of this string. substring(int beginindex, int endindex) Returns a new string that is a substring of this string. tochararray() Converts this string to a new character array. tolowercase() Converts this String to lowercase. tolowercase(locale locale) Converts all of the characters in this String to lower case using the rules of the given locale. tostring() This object (which is already a string!) is itself returned. touppercase(locale locale) Converts all of the characters in this String to upper case using the rules of the given locale. touppercase() Converts this string to uppercase. trim() Removes white space from both ends of this string. * valueof(object obj) Returns the string representation of the Object argument. * valueof(char c) Returns the string representation of the char argument. * valueof(boolean b) Returns the string representation of the boolean argument. * valueof(long l) Returns the string representation of the long argument. 5

6 *valueof(inti) Returns the string representation of the int argument. * valueof(char[] data, int offset, int count) Returns the string representation of a specific subarray of the char array argument. * valueof(char[] data) Returns the string representation of the char array argument. * valueof(float f) Returns the string representation of the float argument. * valueof(double d) Returns the string representation of the double argument. 2 Java Applets and Computer Graphics 2.1 Introduction The main purpose of this class is to learn about 3D computer graphics. Java 2, our platform of development, provides the programmer with several tools to help in this task. Howver, because we are trying to understand the mathematics behind computer graphics, we will not use most of these tools. We will use some of them though; we will not do everything from scratch. More precisely, since our goal is to understand 3D computer graphics, we will develop our own tools to do 3D computer graphics, using the 2D tools Java 2 provides. The 2D tools Java 2 provides are called Java2D. Java2Dformanintegral part of Java 2. In other words, once you install Java 2, Java2D is available to you. In the next section, we will look at the features of Java2D we will use for this project. Among the tools available in Java 2 that we will not use are Java3D and the Advanced Imaging API. Though we will not use these tools it is important to know they exist for future projects you might be involved with. Unlike Java2D, these two tools are not part of Java 2. They must be downloaded and installed separately. They are available from Sun Microsystems, at The project we will be developing will run as a Java applet. We will also need to learn how to write Java applets as well as deal with user interfaces. There are several choices here. One can use AWT (the Advanced Window Toolkit) for the user interface. Another option is SWING. It is a more powerful user interface. It allows the programmer to make applets behave and look more like regular programs. 6

7 3 ComponentsUsedinanApplet 3.1 Basics of a Java Applet A Java applet is a java program which runs inside a Java enabled web browser. See the notes on the vect3d class, given on September 17, for more details regarding the difference between a java applet and a java application. When creating a java applet, remember the following: 1. The main class of your java applet must be saved in a file with the same name. 2. You must also create an html file which will call the applet. In its simplest form, an applet simply defines an area on which you can place various components. It is these various components which will perform the tasks you want the applet to perform. A java applet is "event driven". This means that the applet sits there, quietly, until the user does something. That thing can be a mouse click, pressing a key,... Whenever this happens, an event is triggered. Bylookingatwhatkind of event is triggered, and where it was triggered, the programmer decides which action should be taken. In reality, only the events the programmer decides to listen to will be triggered. A given event can be listened to over the entire applet, or over certain components of the applet. The second way is usually the way it is done. Catching and handling events is a big part of writing a java applet. The applet JApplet1.java is an applet which does nothing, except opens an area in your browser which is 426 by 266 pixels. Every applet must contain at least the code this applet contains. Look atthecodeandthecommentsinit to understand what an applet is made of. The applet JAppletE.java is the same as the above applet, but we have enabled two events: the lost focus event and the mouse click event. Again, look at the code The applet JAppletAllEvents.java is similar to JApplet1.java, but all the events have been enabled so you can see what they are. We now review some of the components an applet can be made of, the events they can handle and how to handle these events. 3.2 JPanel If an applet can be divided into different areas, it is a good idea to draw a panel corresponding to each area. Other objects can then be drawn to each panel. This allows the programmer to enable different events for each panel. The applet JAppletPanel.java is a very simple applet on which 3 panels have been drawn The applet JAppletPanelE.java is like JAppletPanel, but some events have been enabled. Note how events can be enabled for specific panels. 7

8 3.3 JLabel A display area for a short text string or an image, or both. A label does not react to input events. As a result, it cannot get the keyboard focus. Some useful methods associated with it are: public String gettext() Returns the text string that the label displays. public void settext(string text) Defines the single line of text this component will display. See the test1.java applet for how this object is used. 3.4 JTextField JTextField is a lightweight component that allows the editing of a single line of text. It is intended to be source-compatible with java.awt.textfield where it is reasonable to do so. This component has capabilities not found in the java.awt.textfield class. The superclass should be consulted for additional capabilities. Some useful methods associated with it are: public String gettext() Returns the text string that the label displays. public void settext(string text) Defines the single line of text this component will display. See the test1.java applet for how this object is used. 3.5 JTextArea A TextArea is a multi-line area that displays plain text. It is intended to be a lightweight component that provides source compatibility with the java.awt.textarea class where it can reasonably do so. This component has capabilities not found in the java.awt.textarea class. The superclass should be consulted for additional capabilities. Alternative multi-line text classes with more capabilities are JTextPane and JEditorPane. In addition to the methods of the previous component, it also has: append(string str) Appends the given text to the end of the document. getcolumns() Returns the number of columns in the TextArea. getlinecount() Determines the number of lines contained in the area. 8

9 getlineendoffset(int line) Determines the offset of the end of the given line. getlineofoffset(int offset) Translates an offset into the components text to a line number. getlinestartoffset(int line) Determines the offset of the start of the given line. getlinewrap() Gets the line-wrapping policy of the text area. getpreferredscrollableviewportsize() getrows() Returns the number of rows in the TextArea. insert(string str, int pos) Inserts the specified text at the specified position. 3.6 JComboBox Swing s implementation of a ComboBox a combination of a text field and drop-down list that lets the user either type in a value or select it from a list that is displayed when the user asks for it. The editing capability can also be disabled so that the JComboBox acts only as a drop down list. Some useful methods associated with it are: additem(object anobject) Adds an item to the item list. getitemat(int index) Returns the list item at the specified index. getitemcount() Returns the number of items in the list. getselectedindex() Returns the index of the currently selected item in the list. getselecteditem() Returns the currently selected item. See the test1.java applet for how this object is used. 3.7 JButton An implementation of a "push" button. See the test1.java applet for how this object is used. 9

10 4 Assignment Go over the various program examples, including the test1 applet and make sure you understand them. If you have any questions, have them ready for the next class period. 5 Resources This is a list of books and other resources I used to compile these notes. References [BG1] Burger, Peter, and Gillies, Duncan, Interactive Computer Graphics, Addison-Wesley, [DD1] Deitel, H.M., and Deitel, P. J., Java, How to Program, Prentice Hall, [DP1] Dunn, Fletcher and Parberry, Ian, 3D Math Primer for Graphics and Game Development, Wordware Publishing, Inc., [FD1] Foley, J.D., Van Dam, A., Feiner, S.K., and Hughes, J.F., Computer Graphics, Principles and Practices, Addison-Wesley, [FD2] Foley, J.D., Van Dam, A., Feiner, S.K., Hughes, J.F., and Philipps, R.L., Introduction to Computer Graphics, Addison-Wesley, [H1] Hill, F.S. JR., Computer Graphics Using Open GL, Prentice Hall, [LE1] Lengyel, Eric, Mathematics for 3D Game Programming & Computer Graphics, Charles River Media, Inc., [SE1] Schneider, Philip J., and Eberly, David H., Geometric Tools for Computer Graphics, Morgan Kaufman, [SP1] Shirley, Peter, Fundamentals of Computer Graphics, AKPeters, [SJ1] Stewart, James, Calculus, Concepts and Contexts, second edition, Brooks/Cole, [WG1] Wall, David, and Griffith, Arthur, Graphics Programming with JFC, Wiley, [AW1] Watt, Alan, 3D Computer Graphics, Addison-Wesley, [AW2] Watt, Alan, The Computer Image, Addison-Wesley,

Mathematics for Computer Graphics - Lecture 13

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

More information

Mathematics for Computer Graphics - Lecture 8

Mathematics for Computer Graphics - Lecture 8 Mathematics for Computer Graphics - Lecture 8 Dr. Philippe B. Laval Kennesaw State University September 22, 2003 Abstract This document is about our rst project: the creation of a 3D vector class. It gives

More information

Mathematics for Computer Graphics - Ray Tracing III

Mathematics for Computer Graphics - Ray Tracing III Mathematics for Computer Graphics - Ray Tracing III Dr. Philippe B. Laval Kennesaw State University November 12, 2003 Abstract This document is a continuation of the previous documents on ray tracing.

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

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

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

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

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

"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

JAVA NUMBERS, CHARS AND STRINGS

JAVA NUMBERS, CHARS AND STRINGS JAVA NUMBERS, CHARS AND STRINGS It turned out that all Workstation in the classroom are NOT set equally. This is why I wil demonstrate all examples using an on line web tool http://www.browxy.com/ Please

More 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

09 Objects III: String and StringBuffer, Singly (Doubly) Linked Lists

09 Objects III: String and StringBuffer, Singly (Doubly) Linked Lists Exercises Software Development I 09 Objects III: String and StringBuffer, Singly (Doubly) Linked Lists December 10th, 2014 Software Development I Winter term 2014/2015 Priv.-Doz. Dipl.-Ing. Dr. Andreas

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

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

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

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

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

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

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

CHAPTER 6 MOST COMMONLY USED LIBRARIES

CHAPTER 6 MOST COMMONLY USED LIBRARIES 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

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

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

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

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

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

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

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

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

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

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

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

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

IS502052: Enterprise Systems Development Concepts Lab 1: Java Review

IS502052: Enterprise Systems Development Concepts Lab 1: Java Review IS502052: Enterprise Systems Development Concepts Lab 1: Java Review I. Introduction In this first lab, we will review the Java Programming Language, since this course is focus on Java, especially, Java

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

Chapter 10: Text Processing and More about Wrapper Classes

Chapter 10: Text Processing and More about Wrapper Classes Chapter 10: Text Processing and More about Wrapper Classes Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley.

More information

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale Review Single Pixel Filters Thresholding Posterize Histogram Equalization Negative Sepia Grayscale Spatial Filters Smooth Blur Low Pass Filter Sharpen High Pass Filter Erosion Dilation Image Processing

More 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

Chapter 8 Strings. Chapter 8 Strings

Chapter 8 Strings. Chapter 8 Strings Chapter 8 Strings Chapter 6 Arrays Chapter 7 Objects and Classes Chapter 8 Strings Chapter 9 Inheritance and Polymorphism GUI can be covered after 10.2, Abstract Classes Chapter 12 GUI Basics 10.2, Abstract

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

S.E (Computer ) (Second Semester) EXAMINATION, Time : Two Hours Maximum Marks : 50

S.E (Computer ) (Second Semester) EXAMINATION, Time : Two Hours Maximum Marks : 50 S.E (Computer ) (Second Semester) EXAMINATION, 2017 PRINCIPLES OF PROGRAMMING LANGUAGE (2015 PATTERN) Time : Two Hours Maximum Marks : 50 N.B. :- (i) All questions are compulsory (ii)neat diagrams must

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

Chapter 11 Object-Oriented Design Exception and binary I/O can be covered after Chapter 9

Chapter 11 Object-Oriented Design Exception and binary I/O can be covered after Chapter 9 CHAPTER 8 STRINGS Chapter 6 Arrays Chapter 7 Objects and Classes Chapter 8 Strings Chapter 9 Inheritance and Polymorphism GUI can be covered after 10.2, Abstract Classes Chapter 12 GUI Basics 10.2, Abstract

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

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

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

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

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

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

Lesson 4 Utility classes: Math, String, I/O

Lesson 4 Utility classes: Math, String, I/O Lesson 4 Utility classes: Math, String, I/O Programming Grade in Computer Engineering Outline 1. Math class 2. Wrapper classes 3. String management 4. Input and output Printing on the screen Reading from

More information

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphics. Lecture 18 COP 3252 Summer June 6, 2017 Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple

More information

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a Spring 2017 Name: TUID: Page Points Score 1 28 2 18 3 12 4 12 5 15 6 15 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. i Some API Reminders

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

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

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

Utilities (Part 2) Implementing static features

Utilities (Part 2) Implementing static features Utilities (Part 2) Implementing static features 1 Goals for Today learn about preventing class instantiation learn about methods static methods method header method signature method return type method

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

+ Inheritance. n Superclass (base class) higher in the hierarchy. n Subclass (child class) lower in the hierarchy

+ Inheritance. n Superclass (base class) higher in the hierarchy. n Subclass (child class) lower in the hierarchy + Word Clouds + Inheritance n Superclass (base class) higher in the hierarchy n Subclass (child class) lower in the hierarchy n A subclass is derived from from a superclass n Subclasses inherit the fields

More information

Strings, StringBuffer, StringBuilder

Strings, StringBuffer, StringBuilder Strings, StringBuffer, StringBuilder STRINGS, STRINGBUFFER, STRINGBUILDER... 1 1. What is a string... 1 String() IMMUTABLE... 2 2. using the new operator to invoke the constructor in the String class...

More 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

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

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can

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

Java IDE Programming-I

Java IDE Programming-I Java IDE Programming-I Graphical User Interface : is an interface that uses pictures and other graphic entities along with text, to interact with user. User can interact with GUI using mouse click/ or

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

Java Strings Java, winter semester

Java Strings Java, winter semester Java Strings 1 String instances of java.lang.string compiler works with them almost with primitive types String constants = instances of the String class immutable!!! for changes clases StringBuffer, StringBuilder

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

ECS-503 Object Oriented Techniques

ECS-503 Object Oriented Techniques UNIT-4 Part-2 ECS-503 Object Oriented Techniques CHAPTER 16 String Handling Java implements strings as objects of type String. Implementing strings as built-in objects allows Java to provide a full complement

More information

String is a Class; Quoted Text is an Object

String is a Class; Quoted Text is an Object String is a Class; Quoted Text is an Object String s = "abc d"; Indexed characters: 01234 abc d s.length() is 5 s.charat(2) is 'c' s.substring(2) is "c d" s.substring(1,3) is "bc" @3e9cff "abc d" length()

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

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

More About Objects and Methods

More About Objects and Methods More About Objects and Methods Chapter 5 Chapter 5 1 Programming with Methods - Methods Calling Methods A method body may contain an invocation of another method. Methods invoked from method main typically

More information

Java Programming Lecture 6

Java Programming Lecture 6 Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components

More information

PIC 20A Number, Autoboxing, and Unboxing

PIC 20A Number, Autoboxing, and Unboxing PIC 20A Number, Autoboxing, and Unboxing Ernest Ryu UCLA Mathematics Last edited: October 27, 2017 Illustrative example Consider the function that can take in any object. public static void printclassandobj

More information

Review: Python Transi,on Warning

Review: Python Transi,on Warning Objec,ves More Java fundamentals Ø java.lang classes: Math and String class Ø Control Structures Ø Arrays Sept 14, 2016 Sprenkle - CSCI209 1 Review: Python Transi,on Warning OK: You cannot redeclare a

More information

Data Types and Variables

Data Types and Variables Data Types and Variables Variables are names for places in memory in which to put values Data types describe the nature of the variable Data types limit the operations on each value Variables bind data

More information

Inf1-OOP. Data Types. A Foundation for Programming. type value set operations. Overview. Using Data Types 1. Image Processing

Inf1-OOP. Data Types. A Foundation for Programming. type value set operations. Overview. Using Data Types 1. Image Processing Inf1-OOP Using Data Types 1 Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics January 11, 2014 Overview Image Processing String Processing Summary/Admin 1 Thanks to Sedgewick&Wayne

More information

Activity 3: Better Keyword Detection Prepare Exploration: Using the API

Activity 3: Better Keyword Detection Prepare Exploration: Using the API Activity 3: Better Keyword Detection In the previous activity, you discovered that simply searching for collections of letters in a string does not always work as intended. For example, the word cat is

More information

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose

More information

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

Java Programming Lecture 10

Java Programming Lecture 10 Java Programming Lecture 10 Alice E. Fischer February 21 2012 Alice E. Fischer () Java Programming - L10... 1/19 February 21 2012 1 / 19 Outline 1 Encryption 2 Wrapper Classes 3 Unicode and the Character

More 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

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

AP Computer Science A Magpie Chatbot Lab Student Guide

AP Computer Science A Magpie Chatbot Lab Student Guide AP Computer Science A Magpie Chatbot Lab Student Guide The AP Program wishes to acknowledge and thank Laurie White of Mercer University, who developed this lab and the accompanying documentation. Activity

More information

CS Exam 1 Review Suggestions

CS Exam 1 Review Suggestions CS 235 - Fall 2015 - Exam 1 Review Suggestions p. 1 last modified: 2015-09-30 CS 235 - Exam 1 Review Suggestions You are responsible for material covered in class sessions, lab exercises, and homeworks;

More information

Laboratory Manual PROGRAMMING IN JAVA. For. Third Year Students CSE Dept: Computer Science & Engineering. Author JNEC, Aurangabad

Laboratory Manual PROGRAMMING IN JAVA. For. Third Year Students CSE Dept: Computer Science & Engineering. Author JNEC, Aurangabad Laboratory Manual PROGRAMMING IN JAVA For Third Year Students CSE Dept: Computer Science & Engineering Author JNEC, Aurangabad 1 FORWORD It is my great pleasure to present this laboratory manual for Third

More information

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

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2010) - All Sections Final Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2010) - All Sections Final Examination Wednesday, December 8, 2010 Examiners: Maja Frydrychowicz

More 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

TeenCoder : Java Programming (ISBN )

TeenCoder : Java Programming (ISBN ) TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+

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

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13 CONTENTS Chapter 1 Getting Started with Java SE 6 1 Introduction of Java SE 6... 3 Desktop Improvements... 3 Core Improvements... 4 Getting and Installing Java... 5 A Simple Java Program... 10 Compiling

More information

JAVA.LANG.INTEGER CLASS

JAVA.LANG.INTEGER CLASS JAVA.LANG.INTEGER CLASS http://www.tutorialspoint.com/java/lang/java_lang_integer.htm Copyright tutorialspoint.com Introduction The java.lang.integer class wraps a value of the primitive type int in an

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

Selected Java Topics

Selected Java Topics Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings

More information

CST141 Thinking in Objects Page 1

CST141 Thinking in Objects Page 1 CST141 Thinking in Objects Page 1 1 2 3 4 5 6 7 8 Object-Oriented Thinking CST141 Class Abstraction and Encapsulation Class abstraction is the separation of class implementation from class use It is not

More information

York University Fall 2001 / Test #1 Department of Computer Science

York University Fall 2001 / Test #1 Department of Computer Science York University all 2001 / est #1 Department of Computer Science COSC1020.01 his is a closed book, 90-minute test. ill in your personal data below and wait. You may use pen or pencil but answers written

More information

Lecture 4. Strings, Wrappers, & Containers

Lecture 4. Strings, Wrappers, & Containers Lecture 4 Strings, Wrappers, & Containers Announcements for This Lecture Readings pp. 175 181 Sections 2.5, 3.1.2-3.1.3 Also Section 5.2 PLive (optional): Lesson 2-5 Lessons 5-1 and 5-2 Assignments Assignment

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

Designing data types. Overview. Object Oriented Programming. Alan Kay. Object Oriented Programming (OOP) Data encapsulation. Checking for equality

Designing data types. Overview. Object Oriented Programming. Alan Kay. Object Oriented Programming (OOP) Data encapsulation. Checking for equality Designing data types Overview Object Oriented Programming (OOP) Data encapsulation Important consideration when designing a class Access modifiers Immutability, preventing change to a variable Checking

More information