Programming in Java Dr. M. Ahmadzadeh. Course Outline (subject to tiny changes) I will cover the following but not necessarily in this order. –Strings.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Advertisements

Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Strings in Java 1. strings in java are handled by two classes String &
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Chapter 10 Review. Write a method that returns true is s1 and s2 end with the same character; otherwise return false. Sample Answer: public boolean lastChar(String.
Arrays, A1 COMP 401, Fall 2014 Lecture 4 8/28/2014.
Written by: Dr. JJ Shepherd
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Lecture Roger Sutton 21: Revision 1.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 9: Characters * Character primitives * Character Wrapper class.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
CSM-Java Programming-I Spring,2005 String Handling Lesson - 6.
Strings Reading for this Lecture, L&L, 3.2. Strings String is basically just a collection of characters. Thus, the string “Martyn” could be thought of.
Java Course Outline Kumar Harshit, USW. Course Description Teaches students to program using the Java programming language with the help of the Netbeans.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
© 2007 Lawrenceville Press Slide 1 Chapter 6 The while Statement  Loop structure that executes a set of statements as long as a condition is true  The.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
5.1 and 5.4 through 5.6 Various Things. Terminology Identifiers: a name representing a variable, class name, method name, etc. Operand: a named memory.
Week71 APCS-AB: Java Control Structures October 17, 2005.
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
Week 2 - Monday.  What did we talk about last time?  Software development  Lab 1.
Recitation 2 Main Method, API & Packages, Java Basics.
1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Arrays BCIS 3680 Enterprise Programming. Overview 2  Array terminology  Creating arrays  Declaring and instantiating an array  Assigning value to.
The java.lang Package chapter 8 Java Certification Study Group February 2, 1998 Seth Ladd.
CIT 590 Intro to Programming First lecture on Java.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
Best Practices. Contents Bad Practices Good Practices.
Chapter 7: Characters, Strings, and the StringBuilder.
1 Textual Data Many computer applications manipulate textual data word processors web browsers online dictionaries.
String Class. Variable Holds a primitive value or a reference to an object. Holds a primitive value or a reference to an object. A reference lets us know.
G51PR1 Introduction to Programming I University of Nottingham Unit 8 : Strings.
String Processing Word processing term papers, writing memoirs, sending messages, responding to surveys, placing online orders and registering products.
CS1101 Group1 Discussion 10 Lek Hsiang Hui comp.nus.edu.sg
Lecture 7 February 24, Javadoc version and author Tags These go in the comments before named classes. –Put your SS# on a separate line from the.
Array Declarations Arrays contain a fixed number of variables of identical type Array declaration and allocation are separate operations Declaration examples:
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Written by: Dr. JJ Shepherd
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
17-Feb-16 String and StringBuilder Part I: String.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
Strings, StringBuilder, and Character
EKT 472: Object Oriented Programming
Primitive Types Vs. Reference Types, Strings, Enumerations
Advanced Programming Behnam Hatami Fall 2017.
Chapter 6 The while Statement
String Objects & its Methods
Modern Programming Tools And Techniques-I Lecture 11: String Handling
Chapter 7: Strings and Characters
Object Oriented Programming
MSIS 655 Advanced Business Applications Programming
Java Programming Language
CMSC 202 Java Primer 2.
Strings in Java.
In Java, strings are objects that belong to class java.lang.String .
Presentation transcript:

Programming in Java Dr. M. Ahmadzadeh

Course Outline (subject to tiny changes) I will cover the following but not necessarily in this order. –Strings –ArrayList (Vector) –Variables: Primitive & References –Object oriented design & programming Inheritance Overriding method Getter & setter Methods Encapsulation Polymorphism Initialization and clean up Overloaded Constructor Superclass Constructor Exception Handling –File I/O –If we had time, probably Packages GUI Generics Release your code

References Head First Java, Kathy Sierra, Bert Bates, 2 nd Edition, O’Reilly, 2005 Thinking in Java, Bruce Eckel, 4 th Edition, Prentice Hall, 2006 Effective Java Programming Language guide, Joshua Bloch, Addison Wesley, 2001

How to successfully pass this course. Practice, practice & practice Don't give up easily Do not just read –Stop, think, and do it yourself –Use pen & paper Have a rest if you encounter a problem and come back later Talk about the problem loudly Try to break the code Do pair programming (of course not for the exercises that is marked)

Assessment 50% Programming Exercises –In average we would have 1 exercise per week. It depends on how big the exercises are. –Deadline for each exercise will be Sunday at 3:45 pm. (of course it depends on how long you had time to do the exercise) –You deliver your exercise to Ms. Tavakoli. No Exercises will be received after the deadline. In special cases, some marks will be reduced (20% per day). Make your excuse as clear as possible to Ms. Tavakoli (write it down and sign it), when you deliver it late. To my experience, 29 excuses out of 30 are not justifies. So I will not accept those exercises. –Make a folder for each exercise. So Student with Student No. X will have a folder called X and a subfolder called 1 for first set of exercises, 2 for the second …. –Some exercises are programming exercises. –Some exercises are debugging. What I need you to do is To find a bug. To write it down. (in a text file) How did you find the bug. (Which strategy? Had you seen the error before? Did you use any special technique?) To write the solution that you found. How long did it take to correct the entire buggy program. Remember: you will not be assessed by the above parameters. It is just the way that I can check your progress. However if you do not have this report, you will not get the mark for that exercise. 50% final exam. –It might be on-line.

Lectures Sunday starts 8:15 Tuesday: The lecture takes place in lab

A brief history of java Java 1.02 –250 classes –Slow Java 1.1 –500 classes –A little faster –Better GUI code –Friendlier Java 2 –2300 classes –Much faster –Becomes a language of choice for new enterprise (esp. web-based and mobile application) Java 5.0 –3500 classes –More power, easier to develop –Giving a feature that were popular in other languages Java 6.0 –

Code Structure in Java Put a class in a source file –.java extension –Every java application has to have at least one Class Put methods in a class –A class has one or more methods –Each method declares inside a class (within the curly braces of the class) –Every java application has to have one main method per application It is where JVM starts executing Put statements in a method –Within the curly braces of the methods, write the instruction on how that method should perform

What goes inside methods Variables, Literals, etc. Statements  Do something Loops  Do something again & again –While, do.. While, for Branches  Do something under this condition –if, if.. else, nested if, switch

String The most common activity in computer programming They are in java.lang so they are imported implicitly Java Provides 3 classes to manipulate strings. –String: for constant Strings –StringBuilder: For the strings that can change –StringBuffer: the same as StringBuilder with more security for thread programming

String String MyFirstString = new String() –Initializes a newly created String object so that it represents an empty character sequence. String MySecondString = new (char[] value) –Allocates a new String so that it represents the sequence of characters currently contained in the character array argument. String MyThirdString = new String( String original) –Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Because strings are so common, Java includes them in its syntax so we can have String str = “Hello World”;

String, Overloaded Operator +, += are the only operators that are overloaded for strings –Overload = the operator has been given extra meaning when used with a particular class

Strings Objects of String are immutable –Look at every method in class String that modifies a String, they actually creates a new object and return it containing the modification. The object String left untouched. example: immutable class –It means that when a String is passed to a method, it is actually a copy of the reference to that string. –The reference that is passed to the string method, will exist as long as the body of the string is being executed.

Operations on Strings char  charAt( int index ) int  codePointAt( int index ) int  compareTo( String anotherString ) int  compareToIgnoreCase( String str ) String  concat( String str ) Boolean  equalsIgnoreCase( String anotherString ) int  indexOf( char ch ) int  indexOf( char ch, int fromIndex ) int  indexOf( String str ) int  length() String  replace( char oldChar, char newChar ) String  substring( int bgnIndx ) char[]  toCharArray() String  toLowerCase() String  toUpperCase() String  valueOf( int i ) Example: Substring.java AllStringClasses.java Have a look at For more operation on strings.

Exercise String-First.txt –Deadline Sunday 85/12/6 at 3:45 pm.