Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Programming in Java Dr. M. Ahmadzadeh. Course Outline (subject to tiny changes) I will cover the following but not necessarily in this order. –Strings."— Presentation transcript:

1 Programming in Java Dr. M. Ahmadzadeh

2 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

3 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

4 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)

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

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

7 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 –http://java.sun.com/javase/6/webnotes/features.htmlhttp://java.sun.com/javase/6/webnotes/features.html

8 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

9 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

10 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

11 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”;

12 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

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

14 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 http://java.sun.com/javase/6/docs/api/http://java.sun.com/javase/6/docs/api/ For more operation on strings.

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


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

Similar presentations


Ads by Google