Block IQ. Marko Boon Jacques Resing

Size: px
Start display at page:

Download "Block IQ. Marko Boon (marko@win.tue.nl) Jacques Resing (resing@win.tue.nl)"

Transcription

1 Block IQ Marko Boon Jacques Resing

2 Part II: Object Oriented Programming 2/ Objects and Classes 2. Class Inheritance and Interfaces 3. Some Predefined Java Classes 4. Object Oriented Software Development

3 Object Oriented Programming Programming techniques (learning curve of someone who learns to program): 3/ unstructured programming, 2. procedural programming, 3. modular programming, 4. object-oriented programming.

4 Unstructured Programming Test.java class Test { 4/266 public static void main(string[] arg) { double complexre = 3; double complexim = 2; double a = Math.sqrt(complexRe*complexRe + complexim*complexim);

5 Procedural Programming Test.java class Test { 5/266 static double complexabs(double real, double imag) { return Math.sqrt(real*real + imag*imag); public static void main(string[] arg) { double complexre = 3; double complexim = 2; double a = complexabs(complexre, complexim);

6 Modular Programming Complex.java class Complex { 6/266 static double abs(double real, double imag) { return Math.sqrt(real*real + imag*imag); Test.java public static void main(string[] arg) { double complexre = 3; double complexim = 2; double a = Complex.abs(complexRe, complexim);

7 1. Objects and classes Programming in procedural languages like C, Pascal, BASIC involves choosing data structures, designing algorithms, and translating algorithms into code. In procedural programming, data and operations on the data are separate, and this methodology requires sending data to procedures and functions. Object oriented programming places data and the operations that pertain to them within a single entity called an object. This approach organises programs in a way that mirrors the real world, in which all objects are associated with both attributes and activities. Programming in Java involves thinking in terms of objects. A Java program can be viewed as a collection of cooperating objects. 7/266

8 Objects An object represents an entity in the real world that can be distinctly defined. For example, a student, a house, a vehicle, a circle etc.. An object has a unique identity, a state and behaviours. The state is defined by a set of properties (they can be regarded as variables within the object). The behaviour is defined by a set of methods. 8/266

9 Classes A Class is a construct that defines objects of the same type. In a Java class, data are used to describe properties, and methods are used to define behaviours. 9/266 + F A N K > A H K > A = > K > + F A N L = H K > A + F A K > K > A C A J + K C = J A + F A N I K > J H =? J + F A N L The methods abs and arg return information about the object. The methods add and subtract modify (the state of) the object. The method getconjugate constructs a new Complex object. Complex is a constructor.

10 Constructors Each class must have at least one constructor which is used to create objects of this class. 10/266 This is wrong: Complex c; c.re = 3; c.im = 5; It will result in a compiler error:

11 Writing a class in Java 11/266 public class Complex {

12 Writing a class in Java 12/266 public class Complex { // properties // constructor(s) // methods

13 Writing a class in Java 13/266 public class Complex { private double re; private double im; // constructor(s) // methods

14 Writing a class in Java 14/266 public class Complex { private double re; private double im; public Complex(double real, double imaginary) { // methods

15 Writing a class in Java 15/266 public class Complex { private double re; private double im; public Complex(double real, double imaginary) { this.re = real; this.im = imaginary; // methods

16 Writing a class in Java 16/266 public class Complex { private double re; private double im; public Complex(double real, double imaginary) { this.re = real; this.im = imaginary; public double abs() { return Math.sqrt(re*re + im*im); You can use this.re and this.im if you want.

17 Writing a class in Java Some other methods: public void add(complex c) { 17/266 public Complex getconjugate() { public void multiply(complex c) {

18 Writing a class in Java Some other methods: public void add(complex c) { re += c.re; 18/266 public Complex getconjugate() { public void multiply(complex c) {

19 Writing a class in Java Some other methods: public void add(complex c) { re += c.re; im += c.im; 19/266 public Complex getconjugate() { public void multiply(complex c) {

20 Writing a class in Java Some other methods: public void add(complex c) { re += c.re; im += c.im; 20/266 public Complex getconjugate() { return new Complex(re, -im); public void multiply(complex c) {

21 Writing a class in Java Some other methods: public void add(complex c) { re += c.re; im += c.im; 21/266 public Complex getconjugate() { return new Complex(re, -im); public void multiply(complex c) { double newre = re * c.re - im * c.im; double newim = re * c.im + im * c.re;

22 Writing a class in Java Some other methods: public void add(complex c) { re += c.re; im += c.im; 22/266 public Complex getconjugate() { return new Complex(re, -im); public void multiply(complex c) { double newre = re * c.re - im * c.im; double newim = re * c.im + im * c.re; re = newre; im = newim;

23 Creating and using objects 23/266

24 Creating and using objects 24/266 Complex c1 = new Complex(3, 2);

25 Creating and using objects 25/266 Complex c1 = new Complex(3, 2); Complex c2 = new Complex(5, -2);

26 Creating and using objects 26/266 Complex c1 = new Complex(3, 2); Complex c2 = new Complex(5, -2); c1.multiply(c2);

27 Creating and using objects 27/266 Complex c1 = new Complex(3, 2); Complex c2 = new Complex(5, -2); c1.multiply(c2); Complex c3 = c1.getconjugate();

28 Object reference variables (pointers) Consider the following code: Complex c1 = new Complex(3, 2); 28/266 The variable c1 holds a reference to a Complex object. In other programming languages this is called a pointer. Some books state that Java has no pointers, but in fact every object (including arrays) is a pointer.

29 Object reference variables (pointers) Be careful when creating a copy of a variable. If the variable is a reference to an object, you will only copy the reference, not the value! primitive types: int i = 4; int j = i; j = j + 2; System.out.println("i = " + i); System.out.println("j = " + j); 29/266 i = 4 j = 6

30 Object reference variables (pointers) Be careful when creating a copy of a variable. If the variable is a reference to an object, you will only copy the reference, not the value! objects: Complex c = new Complex(3, 5); Complex d = c; d.add(new Complex(1, 1)); System.out.println("c.re = " + c.getreal()); System.out.println("d.re = " + d.getreal()); 30/266 c.re = 4.0 d.re = 4.0

31 Object reference variables (pointers) Be careful when creating a copy of a variable. If the variable is a reference to an object, you will only copy the reference, not the value! arrays: double[] a = {1, 2, 3; double[] b = a; b[2] = 4; System.out.println("a[2] = " + a[2]); System.out.println("b[2] = " + b[2]); System.out.println("a = " + a); System.out.println("b = " + b); a[2] = 4.0 b[2] = 4.0 a = [D@ b = [D@ /266

32 Object reference variables (pointers) Be careful when creating a copy of a variable. If the variable is a reference to an object, you will only copy the reference, not the value! Strings: String s = "Hello"; String t = s; t = t + " world!"; System.out.println("s = " + s); System.out.println("t = " + t); s = Hello t = Hello world! Strings are objects, but no methods exist to modify a String object. All methods defined in the String class return a new String object, and so does the + operator. 32/266

33 The tostring( ) method The tostring( ) method is automatically declared in every object. It returns a String representation of the reference value. The tostring( ) method is invoked automatically when using the System.out.println( ) command: Complex c = new Complex(3, 2); System.out.println(c); 33/266 Complex@5224ee

34 The tostring( ) method You can override the tostring( ) method to create your own String representation of the object. Put the following code in Complex.java: public String tostring() { return re + " + " + im + "i"; Now the output becomes: i Overriding methods will be discussed in greater detail later, when dealing with inheritance. 34/266

35 Constructors Constructors play the role of initialising objects. In the simplest form, they usually initialise the properties of the class (set the state of the object). Differences with methods: constructors must have the same name as the class itself constructors do not have a return type (not even void) constructors are invoked using the new operator when an object is created. 35/266

36 Multiple constructors A class can have more than one constructor: 36/266

37 Multiple constructors A class can have more than one constructor: public Complex(double real, double imaginary) { re = real; im = imaginary; 37/266

38 Multiple constructors A class can have more than one constructor: public Complex(double real, double imaginary) { re = real; im = imaginary; 38/266 public Complex(double real) {

39 Multiple constructors A class can have more than one constructor: public Complex(double real, double imaginary) { re = real; im = imaginary; 39/266 public Complex(double real) { re = real; im = 0;

40 Multiple constructors A class can have more than one constructor: public Complex(double real, double imaginary) { re = real; im = imaginary; 40/266 public Complex(double real) { re = real; im = 0; public Complex() { re = 0; im = 0;

41 Multiple constructors A constructor can invoke another constructor (but only in the first line of the constructor!) public Complex(double real, double imaginary) { re = real; im = imaginary; 41/266 public Complex(double real) { this(real, 0); public Complex() { this(0);

42 Static variables, constants and methods The properties of the Complex class, re and im, are known as instance variables. An instance variable is tied to a specific instance of the class (object). If you construct the following two complex numbers: Complex c1 = new Complex(5, 6); Complex c2 = new Complex(2, 11); then c1.re equals 5, while c2.re equals 2. If you want all the instances of a class to share data, use static variables (a.k.a. class variables). This means that all objects of the same class are affected if one object changes the value of a static variable. Static variables are mostly used for constants and common class properties. 42/266

43 Static variables, constants and methods A typical example of a static variable, is a variable that keeps track of the number of objects of a certain class that have been created. private static int numofobjects = 0; 43/266 public Complex(double real, double imaginary) { re = real; im = imaginary; numofobjects++;

44 Static variables, constants and methods 44/266 Complex c1 = new Complex(3, 2); Complex c2 = new Complex(5, -2); // c1.numofobjects = 2 // c2.numofobjects = 2 Instead of referring to c1.numofobjects, it is more comprehensible to refer to Complex.numOfObjects. This stresses that numofobjects is a class variable instead of an instance variable. In the same way we can create static methods: public static int getnumberofobjects() { return numofobjects; Usage: System.out.println(Complex.getNumberOfObjects());

45 Static variables, constants and methods Sometimes a static method can be used instead of a constructor, to create an object of the specified class. Example: suppose you would like to create a complex number given radius (modulus) r and argument (angle) φ: z = re iφ But we already have a constructor Complex(double, double). Solution: public static Complex polar(double r, double phi) { double re = r * Math.cos(phi); double im = r * Math.sin(phi); return new Complex(re, im); 45/266 Usage: Complex c3 = Complex.polar(3, Math.PI / 4);

46 Static variables, constants and methods The most common usage of static variables is to declare class related constants: public static final Complex I = new Complex(0, 1); 46/266 Usage: Complex c1 = new Complex(3, 2); c1.multiply(complex.i);

47 UML Class Diagram 47/266 + F A N 1 + F A N K > A H K > A = > K > + F A N L = H K > A + F A N + F A K > A + F A K > K > A C A J + K C = J A + F A N F = K > K > A + F A N I K > J H =? J + F A N L

48 The Math class The Java class Math is a typical class which only defines static methods and properties, and has no constructor. Examples: double d1 = 1.5 * Math.PI; double d2 = Math.sin(d1); double d3 = Math.max(d1, d2); int i = Math.round((float) d3); For a complete list of the methods defined in Math, see the Java documentation. 48/266

49 The scope of variables The scope of a variable is the block in which it is declared. Outside this block, the variable cannot be used. The following code will give a compiler error: double a = Math.random(); if (a < 0.5) { int i = -1; else { int i = 1; System.out.println("i = " + i); ScopeError.java:103: cannot find symbol symbol : variable i System.out.println("i = " + i); ^ 49/266

50 The scope of variables The scope of a variable is the block in which it is declared. Outside this block, the variable cannot be used. This is correct: double a = Math.random(); int i; if (a < 0.5) { i = -1; else { i = 1; System.out.println("i = " + i); 50/266

51 The scope of variables The scope of a variable is the block in which it is declared. Outside this block, the variable cannot be used. Initialising the variable with the else -value is even shorter: double a = Math.random(); int i = 1; if (a < 0.5) { i = -1; System.out.println("i = " + i); 51/266

52 The scope of variables Class properties are accessible within the whole class block. It is possible, however, to create variables with the same name within a method. In this case a new, local variable will be declared. public class VariableScopeExample { 52/266 private int i; public VariableScopeExample() { i = 4; public void printi() { System.out.println("i = " + i);

53 The scope of variables Now consider the following methods: 53/266

54 The scope of variables Now consider the following methods: public void function1(int j) { int i = j; 54/266

55 The scope of variables Now consider the following methods: public void function1(int j) { int i = j; 55/266 public void function2(int j) { i = j;

56 The scope of variables Now consider the following methods: public void function1(int j) { int i = j; 56/266 public void function2(int j) { i = j; public void function3(int i) { i = i + 3;

57 The scope of variables Now consider the following methods: public void function1(int j) { int i = j; 57/266 public void function2(int j) { i = j; public void function3(int i) { i = i + 3; public void function4(int i) { this.i = i + 3;

58 The scope of variables Now consider the following methods: public static void main(string[] arg) { VariableScopeExample v =new VariableScopeExample(); v.printi(); v.function1(2); v.printi(); v.function2(3); v.printi(); v.function3(4); v.printi(); v.function4(5); v.printi(); 58/266

59 The scope of variables Now consider the following methods: public static void main(string[] arg) { VariableScopeExample v =new VariableScopeExample(); v.printi(); // i = 4 v.function1(2); v.printi(); v.function2(3); v.printi(); v.function3(4); v.printi(); v.function4(5); v.printi(); 59/266

60 The scope of variables Now consider the following methods: public static void main(string[] arg) { VariableScopeExample v =new VariableScopeExample(); v.printi(); // i = 4 v.function1(2); v.printi(); // i = 4 v.function2(3); v.printi(); v.function3(4); v.printi(); v.function4(5); v.printi(); 60/266

61 The scope of variables Now consider the following methods: public static void main(string[] arg) { VariableScopeExample v =new VariableScopeExample(); v.printi(); // i = 4 v.function1(2); v.printi(); // i = 4 v.function2(3); v.printi(); // i = 3 v.function3(4); v.printi(); v.function4(5); v.printi(); 61/266

62 The scope of variables Now consider the following methods: public static void main(string[] arg) { VariableScopeExample v =new VariableScopeExample(); v.printi(); // i = 4 v.function1(2); v.printi(); // i = 4 v.function2(3); v.printi(); // i = 3 v.function3(4); v.printi(); // i = 3 v.function4(5); v.printi(); 62/266

63 The scope of variables Now consider the following methods: public static void main(string[] arg) { VariableScopeExample v =new VariableScopeExample(); v.printi(); // i = 4 v.function1(2); v.printi(); // i = 4 v.function2(3); v.printi(); // i = 3 v.function3(4); v.printi(); // i = 3 v.function4(5); v.printi(); // i = 8 63/266

64 Frequently made mistake in Constructors Correct: private double xpos, ypos, width, length; 64/266 public Rectangle(double xpos, double ypos, double width, double length) { this.xpos = xpos; this.ypos = ypos; this.width = width; this.length = length;

65 Frequently made mistake in Constructors Also correct: private double xpos, ypos, width, length; 65/266 public Rectangle(double x, double y, double w, double l) { this.xpos = x; this.ypos = y; this.width = w; this.length = l;

66 Frequently made mistake in Constructors Still correct: private double xpos, ypos, width, length; 66/266 public Rectangle(double x, double y, double w, double l) { xpos = x; ypos = y; width = w; length = l;

67 Frequently made mistake in Constructors Wrong: private double xpos, ypos, width, length; 67/266 public Rectangle(double x, double y, double w, double l) { double xpos = x; double ypos = y; double width = w; double length = l; New local variables xpos, ypos, width and length will be created, while the properties are unchanged (still 0). Of course this mistake can also be made outside constructors.

68 2. Class Inheritance and Interfaces Object oriented programming allows you to derive new classes from existing classes. This is called inheritance. If class c2 is derived from another class c1, then we call c1 the superclass and c2 the subclass (or child class, extended class, derived class). A subclass inherits all methods and properties of the superclass. Subclasses are usually extended to contain more functions and/or properties than their superclasses. Every Java class inherits from the class Object. This class defines methods like clone( ), tostring( ). 68/266

69 A class 69/266 4 A? J = C A A C J K > A M J K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 4 A? J = C K > K > K > K > A J H = I = J K > K > A L

70 Java source: Rectangle.java 70/266 public class Rectangle { private double xpos; private double ypos; private double width; private double length; public Rectangle(double xpos, double ypos, double width, double length) { this.xpos = xpos; this.ypos = ypos; this.width = width; this.length = length;

71 Java source: Rectangle.java (part 2) 71/266 public void translate(double dx, double dy) { xpos += dx; ypos += dy; public double calculateperimeter() { return 2*width + 2*length; public double calculatearea() { return width*length;

72 Using the class 72/266 Rectangle r = new Rectangle(0, 0, 20, 10); r.translate(3, 2); double area = r.area();

73 Multiple Constructors 73/266 public Rectangle(double xpos, double ypos, double width, double length) { this.xpos = xpos; this.ypos = ypos; this.width = width; this.length = length;

74 Multiple Constructors 74/266 public Rectangle(double xpos, double ypos, double width, double length) { this.xpos = xpos; this.ypos = ypos; this.width = width; this.length = length; public Rectangle(double width, double length) { this.xpos = 0; this.ypos = 0; this.width = width; this.length = length;

75 Multiple Constructors 75/266 public Rectangle(double xpos, double ypos, double width, double length) { this.xpos = xpos; this.ypos = ypos; this.width = width; this.length = length; public Rectangle(double width, double length) { this(0, 0, width, length);

76 More classes 76/266 + E H? A H E K K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A + E H? K > K > K > A J H = I = J K > K > A L

77 Java source: Circle.java 77/266 public class Circle { private double xpos; private double ypos; private double radius; public Circle(double radius) { this(0, 0, radius); public Circle(double xpos, double ypos, double radius) { this.xpos = xpos; this.ypos = ypos; this.radius = radius;

78 Java source: Circle.java (part 2) 78/266 public void translate(double dx, double dy) { xpos += dx; ypos += dy; public double calculateperimeter() { return 2*Math.PI*radius; public double calculatearea() { return Math.PI*radius*radius;

79 More classes 79/266 5 G K = H A A C J K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 5 G K = H K > K > K > A J H = I = J K > K > A L

80 Java source: Square.java 80/266 public class Square { private double xpos; private double ypos; private double length; public Square(double length) { this(0, 0, length); public Square(double xpos, double ypos, double length) { this.xpos = xpos; this.ypos = ypos; this.length = length;

81 Java source: Square.java (part 2) 81/266 public void translate(double dx, double dy) { xpos += dx; ypos += dy; public double calculateperimeter() { return 4*length; public double calculatearea() { return length*length;

82 More classes 82/266 6 H E = C A I K > A I K > A I K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A J H = I = J K > K > A L 6 H E = C K > K > K > K > K > A

83 Java source: Triangle.java 83/266 public class Triangle { private double xpos; private double ypos; private double side1; private double side2; private double side3; public Triangle(double xpos, double ypos, double side1, double side2, double side3) { this.xpos = xpos; this.ypos = ypos; this.side1 = side1; this.side2 = side2; this.side3 = side3;

84 Java source: Triangle.java (part 2) 84/266 public void translate(double dx, double dy) { xpos += dx; ypos += dy; public double calculateperimeter() { return side1 + side2 + side3; public double calculatearea() { double s = calculateperimeter()/2; // Heron of Alexandria s formula return Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));

85 Problems in current implementation: 85/ method translate(dx, dy) is implemented in the exact same way in all classes. Disadvantages: if you want to change the implementation you should modify all classes you have to implement it again for each new shape 2. although all classes have the methods translate(dx, dy), calculatearea() and calculateperimeter(), you cannot use code like this: Object[] shapes = {new Circle(7), new Rectangle(6, 2), new Triangle(5, 5, 3), new Square(10); double totalarea = 0; for (int i = 0; i < shapes.length; i++) totalarea += shapes[i].calculatearea();

86 Inheritance Solution: Inheritance. We define a superclass Shape. Objects are defined in terms of classes. 86/266 Rectangle rect = new Rectangle(30, 15); Inheritance defines classes in terms of other classes.

87 87/266 4 A? J = C A A C J K > A M J K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 4 A? J = C K > K > K > K > A J H = I = J K > K > A L + E H? A H E K K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A + E H? K > K > K > A J H = I = J K > K > A L 5 G K = H A A C J K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 5 G K = H K > K > K > A J H = I = J K > K > A L 6 H E = C A I K > A I K > A I K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A J H = I = J K > K > A L 6 H E = C K > K > K > K > K > A

88 88/266 5 D = F A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 5 D = F K > K > A J H = I = J K > K > A L 4 A? J = C A A C J K > A M J K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 4 A? J = C K > K > K > K > A J H = I = J K > K > A L + E H? A H E K K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A + E H? K > K > K > A J H = I = J K > K > A L 5 G K = H A A C J K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 5 G K = H K > K > K > A J H = I = J K > K > A L 6 H E = C A I K > A I K > A I K > A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A J H = I = J K > K > A L 6 H E = C K > K > K > K > K > A

89 89/266 5 D = F A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 5 D = F K > K > A J H = I = J K > K > A L A C J K > A M J K > A 4 A? J = C A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 4 A? J = C K > K > K > K > A H E K K > A + E H? A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A + E H? K > K > K > A A C J K > A M J K > A 5 G K = H A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 5 G K = H K > K > K > A I K > A I K > A I K > A 6 H E = C A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 6 H E = C K > K > K > K > K > A

90 Java implementation: Shape.java 90/266 public class Shape {

91 Java implementation: Shape.java 91/266 public abstract class Shape {

92 Java implementation: Shape.java 92/266 public abstract class Shape { private double xpos, ypos;

93 Java implementation: Shape.java 93/266 public abstract class Shape { protected double xpos, ypos;

94 Java implementation: Shape.java 94/266 public abstract class Shape { protected double xpos, ypos; public Shape(double xpos, double ypos) {

95 Java implementation: Shape.java 95/266 public abstract class Shape { protected double xpos, ypos; public Shape(double xpos, double ypos) { public void translate(double dx, double dy); public double calculateperimeter(); public double calculatearea();

96 Java implementation: Shape.java 96/266 public abstract class Shape { protected double xpos, ypos; public Shape(double xpos, double ypos) { this.xpos = xpos; this.ypos = ypos; public void translate(double dx, double dy); public double calculateperimeter(); public double calculatearea();

97 Java implementation: Shape.java 97/266 public abstract class Shape { protected double xpos, ypos; public Shape(double xpos, double ypos) { this.xpos = xpos; this.ypos = ypos; public void translate(double dx, double dy) { xpos += dx; ypos += dy; public double calculateperimeter(); public double calculatearea();

98 Java implementation: Shape.java 98/266 public abstract class Shape { protected double xpos, ypos; public Shape(double xpos, double ypos) { this.xpos = xpos; this.ypos = ypos; public void translate(double dx, double dy) { xpos += dx; ypos += dy; public abstract double calculateperimeter(); public abstract double calculatearea();

99 Java implementation: Circle.java 99/266 public class Circle {

100 Java implementation: Circle.java 100/266 public class Circle extends Shape {

101 Java implementation: Circle.java 101/266 public class Circle extends Shape { private double radius;

102 Java implementation: Circle.java 102/266 public class Circle extends Shape { protected double radius;

103 Java implementation: Circle.java 103/266 public class Circle extends Shape { protected double radius; public Circle(double radius) {

104 Java implementation: Circle.java 104/266 public class Circle extends Shape { protected double radius; public Circle(double radius) { public Circle(double xpos, double ypos, double radius) {

105 Java implementation: Circle.java 105/266 public class Circle extends Shape { protected double radius; public Circle(double radius) { this(0, 0, radius); public Circle(double xpos, double ypos, double radius) {

106 Java implementation: Circle.java 106/266 public class Circle extends Shape { protected double radius; public Circle(double radius) { this(0, 0, radius); public Circle(double xpos, double ypos, double radius) { this.radius = radius;

107 Java implementation: Circle.java 107/266 public class Circle extends Shape { protected double radius; public Circle(double radius) { this(0, 0, radius); public Circle(double xpos, double ypos, double radius) { super(xpos, ypos) this.radius = radius;

108 Java implementation: Circle.java (Part 2) 108/266 public double calculateperimeter() { return 2*Math.PI*radius; public double calculatearea() { return Math.PI*radius*radius;

109 Compatibility of Superclass and Subclass 109/266 Object[] shapes = {new Circle(7), new Rectangle(6, 2), new Triangle(5, 5, 3), new Square(10); double totalarea = 0; for (int i = 0; i < shapes.length; i++) totalarea += shapes[i].calculatearea();

110 Compatibility of Superclass and Subclass 110/266 Shape[] shapes = {new Circle(7), new Rectangle(6, 2), new Triangle(5, 5, 3), new Square(10); double totalarea = 0; for (int i = 0; i < shapes.length; i++) totalarea += shapes[i].calculatearea();

111 111/266 5 D = F A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 5 D = F K > K > A J H = I = J K > K > A L A C J K > A M J K > A 4 A? J = C A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 4 A? J = C K > K > K > K > A H E K K > A + E H? A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A + E H? K > K > K > A A C J K > A 5 G K = H A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 5 G K = H K > K > K > A I K > A I K > A I K > A 6 H E = C A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 6 H E = C K > K > K > K > K > A

112 112/266 5 D = F A N F K > A O F K > A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 5 D = F K > K > A J H = I = J K > K > A L A C J K > A M J K > A 4 A? J = C A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A 4 A? J = C K > K > K > K > A H E K K > A + E H? A? =? K = J A ) H A K > A? =? K = J A 2 A H E E J A K > A + E H? K > K > K > A I K > A I K > A I K > A 6 H E = C A? =? K = J A ) H A K > A? =? K = J A 2 A H E A J A K > A 6 H E = C K > K > K > K > K > A 5 G K = H A 5 G K = H K > K > K > A

113 Square.java public class Square extends Rectangle { 113/266 public Square(double length) { this(0, 0, length); public Square(double xpos, double ypos, double length) { super(xpos, ypos, length, length);

114 Interfaces 114/266 An abstract class with only abstract properties and methods is called an interface. An interface will never have a constructor. public interface Drawable { public abstract void draw(graphics g); Java does not support multiple inheritance (inheriting from more than one class at once), but a class can inherit from multiple interfaces. Inheriting from an interface is called implementing : public class DrawableRectangle extends Rectangle implements Drawable { public void draw(graphics g) { g.drawrect(xpos, ypos, width, length);

115 Accessibility 115/266 The following modifiers specify the accessibility of a class, property or method: private only accessible by the current class. protected only accessible by the current class, subclasses that extend the current class and all other classes that are part of the same package. public final static accessible by all other classes. object or type can never be changed after the initialisation. Mostly used to specify constants. the property or method can be accessed without having to create an instance of the current class.

116 3. Some Predefined Java Classes 116/266 Java has a huge number of predefined classes that can be used to build applications. These classes are grouped into packages that provide a convenient way to organise them. You can put the classes you have developed into packages and distribute them to other people. Think of packages as libraries to be shared by many users. You have already seen classes like String, Integer, Double, Math. These classes are all part of the java.lang package. All classes that are part of this package are loaded by default. Classes from other packages must be imported. Until now we have only seen the class JOptionPane which is part of the javax.swing package.

117 The Java Application Program Interface (API) 117/266 The Java API consists of numerous classes and interfaces grouped into many core packages. The most important are: java.lang awt contains all core Java classes, such as System, Math, Object, String, Number, Boolean, Integer, Float, Double. contains all classes for drawing geometrical figures and (ancient) user interface components, such as Frame, Window, Button, Menu, Font, Graphics. java.awt.event contains classes for handling events, such as MouseEvent, MouseListener, KeyEvent. javax.swing java.applet contains all modern user interface components, such as JFrame, JWindow, JButton, JTextField, JOptionPane. contains classes for supporting applets, such as Applet.

118 The Java Application Program Interface (API) 118/266 java.io contains classes for input and output streams and files, such as File, FileReader, PrintWriter. java.util contains many utilities, such as Date, Calendar, Vector, Set, Random. java.text contains classes for formatting information, such as date and time. java.net contains classes for supporting network communications, such as URL. You can browse the Java Documentation to see the documentation on all classes and packages.

119 The String class 119/266 The java.lang.string class has several constructors, but the most frequently used is the special notation using quotes: String welcometext = "Hello World!"; The constructor which has an array of character as argument, can also be used: char[] chararray = new char[26]; for (int i = 0; i < chararray.length; i++) { chararray[i] = (char) ( A + i); String abc = new String(charArray); System.out.println(abc);

120 The String class Some other useful methods are indexof(string), length( ), equals( ): abc == "ABCDEFGHIJKLMNOPQRSTUVWXYZ" abc.equals("abcdefghijklmnopqrstuvwxyz") abc.equalsignorecase("abcdefghijklmnopqrstuvwxyz") abc.substring(18, 21) abc.substring(abc.length() - 3) abc.indexof("g") abc.indexof("m") 120/266 false true true STU XYZ 6-1

121 Resizable array: java.util.vector 121/266 The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. Constructor Vector<Type> list = new Vector<Type>(); where Type is a Java class.

122 122/266 Vector<String> list = new Vector<String>(); Methods list.addelement("hello"); list.insertelementat("world", 0); String s = list.elementat(1); int length = list.size(); Other methods: contains(object), firstelement(), indexof(object), removeelement(object), removeelementat(int)

123 java.util.vector Please note that you can only insert Objects in a Vector, no primitive types: 123/266

124 java.util.vector Please note that you can only insert Objects in a Vector, no primitive types: Wrong Vector<int> list2 = new Vector<int>(); list2.addelement(3); 124/266

125 java.util.vector Please note that you can only insert Objects in a Vector, no primitive types: Right Vector<Integer> list2 = new Vector<Integer>(); list2.addelement(new Integer(3)); int i = list2.elementat(0).intvalue(); 125/266

126 java.util.vector Please note that you can only insert Objects in a Vector, no primitive types: Also right Vector<Integer> list3 = new Vector<Integer>(); list3.addelement(3); int j = list3.elementat(0); 126/266 Internally Java converts the int to Integer. Since Java 1.5, this is called autoboxing.

127 Conversion to an Array 127/266 Vector<String> list4 = new Vector<String>(); list4.addelement("hello"); list4.addelement("world"); String[] sarray = new String[list4.size()]; list4.copyinto(sarray);

128 128/ Object Oriented software development 7 developmental phases in software design: 1. requirements specification 2. system analysis 3. system design 4. implementation 5. testing 6. deployment 7. maintenance Of course when developing mathematical software, the very first step is to develop the algorithm.

129 Steps in building an object oriented system 129/ identify classes for the system 2. describe attributes and methods in each class 3. establish relationships among classes 4. create classes Three types of relationships: 1. association 2. aggregation 3. inheritance

130 Relationships among objects: association 130/266 Association is a binary relationship that describes an activity between two classes. The activity can be of any kind, for example "a Student takes a Course", or "a Teacher teaches a Course". An association is usually represented as a data field in the class.

131 Relationships among objects: aggregation 131/266 Aggregation is a special form of association, in fact the most frequent existing form that represents an ownership relationship between two classes. has a is part of owns Since aggregation is a special form of association, it is also usually represented as a data field in the class.

132 Relationships among objects: inheritance Inheritance models the "is a" relationship between two classes. strong is-a relationship: direct inheritance between two classes 132/266 extend superclass Example: a Student extends Person weak is-a relationship: class has certain properties implement interface Example: if students can be compared (e.g. on their grades), Student implements Comparable

133 Inheritance or aggregation 133/266 Sometimes there it is unclear whether a relationship should be "is a" (inheritance) or "has a" (aggregation). Both implementations can be suitable, but depending on the implementation you might have some advantages or disadvantages. Examples: suppose you are implementing the following shape: Is this shape a kind of rectangle, or does is contain one? a graphical rectangle that can be drawn (including colour, location), compared to the geometrical shape rectangle.

134 = % Case study: linked lists and search trees Array: 134/266! "! # $ "

135 =! # Case study: linked lists and search trees Linked list: A N J A N J % $ " A N J A N J K 135/266 E E I J A A A K > A A N J E E I - A A K > A L C A J 5 E A E J E I A H J - A A J ) K > A E J L E I - F J O > A = E I = I J - A A J > A = E E I J E E I K > A H A L A - A A J ) J E J L H A L A = I J - A A J L

136 A linked list 136/266 public class LinkedList {

137 A linked list 137/266 public class LinkedList { protected double element;

138 A linked list 138/266 public class LinkedList { protected double element; protected LinkedList next;

139 A linked list 139/266 public class LinkedList { protected double element; protected LinkedList next; public LinkedList() {

140 A linked list 140/266 public class LinkedList { protected double element; protected LinkedList next; public LinkedList() { this.element = Double.POSITIVE_INFINITY; // empty

141 A linked list 141/266 public class LinkedList { protected double element; protected LinkedList next; public LinkedList() { this.element = Double.POSITIVE_INFINITY; // empty this.next = null;

142 A linked list 142/266 public class LinkedList { protected double element; protected LinkedList next; public LinkedList() { this.element = Double.POSITIVE_INFINITY; // empty this.next = null; public LinkedList(double element) { this.element = element; this.next = null;

143 A linked list 143/266 public boolean isempty() { public boolean islastelement() { public int getsize() {

144 A linked list 144/266 public boolean isempty() { return element == Double.POSITIVE_INFINITY; public boolean islastelement() { public int getsize() {

145 A linked list 145/266 public boolean isempty() { return element == Double.POSITIVE_INFINITY; public boolean islastelement() { return next == null; public int getsize() {

146 A linked list 146/266 public boolean isempty() { return element == Double.POSITIVE_INFINITY; public boolean islastelement() { return next == null; public int getsize() { if (isempty()) return 0;

147 A linked list 147/266 public boolean isempty() { return element == Double.POSITIVE_INFINITY; public boolean islastelement() { return next == null; public int getsize() { if (isempty()) return 0; else {

148 A linked list 148/266 public boolean isempty() { return element == Double.POSITIVE_INFINITY; public boolean islastelement() { return next == null; public int getsize() { if (isempty()) return 0; else { if (islastelement()) return 1;

149 A linked list 149/266 public boolean isempty() { return element == Double.POSITIVE_INFINITY; public boolean islastelement() { return next == null; public int getsize() { if (isempty()) return 0; else { if (islastelement()) return 1; else return 1 + next.getsize();

150 A linked list 150/266 public void addelement(double element) {

151 A linked list 151/266 public void addelement(double element) { if (isempty()) this.element = element; else {

152 A linked list 152/266 public void addelement(double element) { if (isempty()) this.element = element; else { if (islastelement()) { else {

153 A linked list 153/266 public void addelement(double element) { if (isempty()) this.element = element; else { if (islastelement()) { this.next = new LinkedList(element); else {

154 A linked list 154/266 public void addelement(double element) { if (isempty()) this.element = element; else { if (islastelement()) { this.next = new LinkedList(element); else { next.addelement(element);

155 A linked list 155/266 public void removelastelement() {

156 A linked list 156/266 public void removelastelement() { if (islastelement()) { else {

157 A linked list 157/266 public void removelastelement() { if (islastelement()) { // only if this is first element in list! element = Double.POSITIVE_INFINITY; else {

158 A linked list 158/266 public void removelastelement() { if (islastelement()) { // only if this is first element in list! element = Double.POSITIVE_INFINITY; else { if (next.islastelement()) next = null;

159 A linked list 159/266 public void removelastelement() { if (islastelement()) { // only if this is first element in list! element = Double.POSITIVE_INFINITY; else { if (next.islastelement()) next = null; else next.removelastelement();

160 A linked list 160/266 public void removeelementat(int index) {

161 A linked list 161/266 public void removeelementat(int index) { if (index == 0) {

162 A linked list 162/266 public void removeelementat(int index) { if (index == 0) { if (islastelement())

163 A linked list 163/266 public void removeelementat(int index) { if (index == 0) { if (islastelement()) element = Double.POSITIVE_INFINITY;

164 A linked list 164/266 public void removeelementat(int index) { if (index == 0) { if (islastelement()) element = Double.POSITIVE_INFINITY; else {

165 A linked list 165/266 public void removeelementat(int index) { if (index == 0) { if (islastelement()) element = Double.POSITIVE_INFINITY; else { element = next.element;

166 A linked list 166/266 public void removeelementat(int index) { if (index == 0) { if (islastelement()) element = Double.POSITIVE_INFINITY; else { element = next.element; next = next.next;

167 A linked list 167/266 public void removeelementat(int index) { if (index == 0) { if (islastelement()) element = Double.POSITIVE_INFINITY; else { element = next.element; next = next.next; else if (index == 1) {

168 A linked list 168/266 public void removeelementat(int index) { if (index == 0) { if (islastelement()) element = Double.POSITIVE_INFINITY; else { element = next.element; next = next.next; else if (index == 1) { next = next.next;

169 A linked list 169/266 public void removeelementat(int index) { if (index == 0) { if (islastelement()) element = Double.POSITIVE_INFINITY; else { element = next.element; next = next.next; else if (index == 1) { next = next.next; else if (index > 1 &&!islastelement()) {

170 A linked list 170/266 public void removeelementat(int index) { if (index == 0) { if (islastelement()) element = Double.POSITIVE_INFINITY; else { element = next.element; next = next.next; else if (index == 1) { next = next.next; else if (index > 1 &&!islastelement()) { next.removeelementat(index - 1);

171 A linked list public void insertat(double element, int index) { 171/266

172 A linked list public void insertat(double element, int index) { if (index == 0) { 172/266

173 A linked list public void insertat(double element, int index) { if (index == 0) { if (isempty()) this.element = element; else { 173/266

174 A linked list public void insertat(double element, int index) { if (index == 0) { if (isempty()) this.element = element; else { LinkedList oldnext = next; 174/266

175 A linked list public void insertat(double element, int index) { if (index == 0) { if (isempty()) this.element = element; else { LinkedList oldnext = next; next = new LinkedList(this.element); 175/266

176 A linked list public void insertat(double element, int index) { if (index == 0) { if (isempty()) this.element = element; else { LinkedList oldnext = next; next = new LinkedList(this.element); this.element = element; 176/266

177 A linked list public void insertat(double element, int index) { if (index == 0) { if (isempty()) this.element = element; else { LinkedList oldnext = next; next = new LinkedList(this.element); this.element = element; next.next = oldnext; 177/266

178 A linked list public void insertat(double element, int index) { if (index == 0) { if (isempty()) this.element = element; else { LinkedList oldnext = next; next = new LinkedList(this.element); this.element = element; next.next = oldnext; else if (index > 0) { 178/266

179 A linked list public void insertat(double element, int index) { if (index == 0) { if (isempty()) this.element = element; else { LinkedList oldnext = next; next = new LinkedList(this.element); this.element = element; next.next = oldnext; else if (index > 0) { if (islastelement()) next = new LinkedList(element); 179/266

180 A linked list public void insertat(double element, int index) { if (index == 0) { if (isempty()) this.element = element; else { LinkedList oldnext = next; next = new LinkedList(this.element); this.element = element; next.next = oldnext; else if (index > 0) { if (islastelement()) next = new LinkedList(element); else next.insertelementat(element, index - 1); 180/266

181 A linked list 181/266 public String tostring() { String s = ""; if (!isempty()) { s = s + " " + element; if (!islastelement()) { return s + next.tostring(); return s;

182 A linked list 182/266

183 A linked list 183/266 LinkedList list = new LinkedList(); E I J K

184 ! A linked list 184/266 LinkedList list = new LinkedList(); list.addelement(3.0); E I J K

185 ! # A linked list 185/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); E I J A N J K

186 ! # A linked list 186/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); E I J A N A N J K

187 !! # A linked list 187/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); E I J A N A N J K K

188 ! # A linked list 188/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); % E I J A N A N J K K

189 ! # A linked list 189/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); % E I J A N A N J K A N J

190 ! # A linked list 190/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); % E I J A N J A N J K

191 ! # A linked list 191/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); list.removelastelement(); % E I J A N J K K

192 ! A linked list 192/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); list.removelastelement(); E I J % A N J K

193 A linked list 193/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); list.removelastelement(); list.addelement(1.9); %! ' E I J A N J A N J K

194 ! A linked list 194/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); list.removelastelement(); list.addelement(1.9); list.removeelementat(0);! ' E I J A N J A N J K

195 ! A linked list 195/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); list.removelastelement(); list.addelement(1.9); list.removeelementat(0);! ' E I J A N J A N J K

196 A linked list 196/266 LinkedList list = new LinkedList(); list.addelement(3.0); list.addelement(5.0); list.insertelementat(7.2, 0); list.removelastelement(); list.addelement(1.9); list.removeelementat(0);! ' E I J A N J K

197 A sorted linked list 197/266

198 A sorted linked list 198/266 public class SortedLinkedList {

199 A sorted linked list 199/266 public class SortedLinkedList extends LinkedList {

200 A sorted linked list 200/266 public class SortedLinkedList extends LinkedList { public SortedLinkedList() { public SortedLinkedList(double element) {

201 A sorted linked list 201/266 public class SortedLinkedList extends LinkedList { public SortedLinkedList() { super(); public SortedLinkedList(double element) { super(element);

202 A sorted linked list 202/266 Of course the method insertelementat should be overridden (it cannot be removed since it is automatically inherited from LinkedList. public void insertelementat(double element, int idx) {

203 A sorted linked list 203/266 Of course the method insertelementat should be overridden (it cannot be removed since it is automatically inherited from LinkedList. public void insertelementat(double element, int idx) { addelement(element);

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin SE 360 Advances in Software Development Object Oriented Development in Java Polymorphism Dr. Senem Kumova Metin Modified lecture notes of Dr. Hüseyin Akcan Inheritance Object oriented programming languages

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

Java Programming Fundamentals

Java Programming Fundamentals Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few

More information

Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous

Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

More information

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

More information

Computing Concepts with Java Essentials

Computing Concepts with Java Essentials 2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann

More information

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

7.1 Our Current Model

7.1 Our Current Model Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.

More information

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling

More information

Java the UML Way: Integrating Object-Oriented Design and Programming

Java the UML Way: Integrating Object-Oriented Design and Programming Java the UML Way: Integrating Object-Oriented Design and Programming by Else Lervik and Vegard B. Havdal ISBN 0-470-84386-1 John Wiley & Sons, Ltd. Table of Contents Preface xi 1 Introduction 1 1.1 Preliminaries

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman

More information

An Overview of Java. overview-1

An Overview of Java. overview-1 An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2

More information

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0 The following applies to all exams: Once exam vouchers are purchased you have up to one year from the date of purchase to use it. Each voucher is valid for one exam and may only be used at an Authorized

More information

Fundamentals of Java Programming

Fundamentals of Java Programming Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Introduction to Java Programming Language Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

More information

Introduction to Programming System Design. CSCI 455x (4 Units)

Introduction to Programming System Design. CSCI 455x (4 Units) Introduction to Programming System Design CSCI 455x (4 Units) Description This course covers programming in Java and C++. Topics include review of basic programming concepts such as control structures,

More information

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition Java 6 'th edition Concepts INTERNATIONAL STUDENT VERSION CONTENTS PREFACE vii SPECIAL FEATURES xxviii chapter i INTRODUCTION 1 1.1 What Is Programming? 2 J.2 The Anatomy of a Computer 3 1.3 Translating

More information

CS193j, Stanford Handout #10 OOP 3

CS193j, Stanford Handout #10 OOP 3 CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples

More information

16.1 DataFlavor. 16.1.1 DataFlavor Methods. Variables

16.1 DataFlavor. 16.1.1 DataFlavor Methods. Variables In this chapter: DataFlavor Transferable Interface ClipboardOwner Interface Clipboard StringSelection UnsupportedFlavorException Reading and Writing the Clipboard 16 Data Transfer One feature that was

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

Java Crash Course Part I

Java Crash Course Part I Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux

More information

University of Twente. A simulation of the Java Virtual Machine using graph grammars

University of Twente. A simulation of the Java Virtual Machine using graph grammars University of Twente Department of Computer Science A simulation of the Java Virtual Machine using graph grammars Master of Science thesis M. R. Arends, November 2003 A simulation of the Java Virtual Machine

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

java Features Version April 19, 2013 by Thorsten Kracht

java Features Version April 19, 2013 by Thorsten Kracht java Features Version April 19, 2013 by Thorsten Kracht Contents 1 Introduction 2 1.1 Hello World................................................ 2 2 Variables, Types 3 3 Input/Output 4 3.1 Standard I/O................................................

More information

Basic Programming and PC Skills: Basic Programming and PC Skills:

Basic Programming and PC Skills: Basic Programming and PC Skills: Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab. Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices What is Java? Result of Sun s efforts to remedy bad software engineering practices It is commonly thought of as a way to make Web pages cool. It has evolved into much more. It is fast becoming a computing

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Object Oriented Programming with Java. School of Computer Science University of KwaZulu-Natal

Object Oriented Programming with Java. School of Computer Science University of KwaZulu-Natal Object Oriented Programming with Java School of Computer Science University of KwaZulu-Natal January 30, 2006 2 Object Oriented Programming with Java Notes for the Computer Science Module Object Oriented

More information

Software Engineering Techniques

Software Engineering Techniques Software Engineering Techniques Low level design issues for programming-in-the-large. Software Quality Design by contract Pre- and post conditions Class invariants Ten do Ten do nots Another type of summary

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I

More information

How To Write A Program For The Web In Java (Java)

How To Write A Program For The Web In Java (Java) 21 Applets and Web Programming As noted in Chapter 2, although Java is a general purpose programming language that can be used to create almost any type of computer program, much of the excitement surrounding

More information

Classes and Objects. Agenda. Quiz 7/1/2008. The Background of the Object-Oriented Approach. Class. Object. Package and import

Classes and Objects. Agenda. Quiz 7/1/2008. The Background of the Object-Oriented Approach. Class. Object. Package and import Classes and Objects 2 4 pm Tuesday 7/1/2008 @JD2211 1 Agenda The Background of the Object-Oriented Approach Class Object Package and import 2 Quiz Who was the oldest profession in the world? 1. Physician

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

Computer Programming I

Computer Programming I Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,

More information

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts Third AP Edition Object-Oriented Programming and Data Structures Maria Litvin Phillips Academy, Andover, Massachusetts Gary Litvin Skylight Software, Inc. Skylight Publishing Andover, Massachusetts Skylight

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards Course Title: TeenCoder: Java Programming Course ISBN: 978 0 9887070 2 3 Course Year: 2015 Note: Citation(s) listed may represent

More information

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For Projet Java Responsables: Ocan Sankur, Guillaume Scerri (LSV, ENS Cachan) Objectives - Apprendre à programmer en Java - Travailler à plusieurs sur un gros projet qui a plusieurs aspects: graphisme, interface

More information

Assignment # 2: Design Patterns and GUIs

Assignment # 2: Design Patterns and GUIs CSUS COLLEGE OF ENGINEERING AND COMPUTER SCIENCE Department of Computer Science CSc 133 Object-Oriented Computer Graphics Programming Spring 2014 John Clevenger Assignment # 2: Design Patterns and GUIs

More information

CS170 Lab 11 Abstract Data Types & Objects

CS170 Lab 11 Abstract Data Types & Objects CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays. Arrays Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html 1 Grid in Assignment 2 How do you represent the state

More information

ATM Case Study OBJECTIVES. 2005 Pearson Education, Inc. All rights reserved. 2005 Pearson Education, Inc. All rights reserved.

ATM Case Study OBJECTIVES. 2005 Pearson Education, Inc. All rights reserved. 2005 Pearson Education, Inc. All rights reserved. 1 ATM Case Study 2 OBJECTIVES.. 3 2 Requirements 2.9 (Optional) Software Engineering Case Study: Examining the Requirements Document 4 Object-oriented design (OOD) process using UML Chapters 3 to 8, 10

More information

Programmation 2. Introduction à la programmation Java

Programmation 2. Introduction à la programmation Java Programmation 2 Introduction à la programmation Java 1 Course information CM: 6 x 2 hours TP: 6 x 2 hours CM: Alexandru Costan alexandru.costan at inria.fr TP: Vincent Laporte vincent.laporte at irisa.fr

More information

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459) Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459) Class Time: 6:00 8:05 p.m. (T,Th) Venue: WSL 5 Web Site: www.pbvusd.net/mis260 Instructor Name: Terrell Tucker Office: BDC 127

More information

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science updated 03/08/2012 Unit 1: JKarel 8 weeks http://www.fcps.edu/is/pos/documents/hs/compsci.htm

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt core. 2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Volume I - Fundamentals Seventh Edition CAY S. HORSTMANN GARY

More information

Construction of classes with classes

Construction of classes with classes (November 13, 2014 Class hierarchies 1 ) Construction of classes with classes Classes can be built on existing classes through attributes of object types. Example: I A class PairOfDice can be constructed

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

CSC 551: Web Programming. Fall 2001

CSC 551: Web Programming. Fall 2001 CSC 551: Web Programming Fall 2001 Java Overview! Design goals & features "platform independence, portable, secure, simple, object-oriented,! Language overview " program structure, public vs. private "instance

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Event-Driven Programming

Event-Driven Programming Event-Driven Programming Lecture 4 Jenny Walter Fall 2008 Simple Graphics Program import acm.graphics.*; import java.awt.*; import acm.program.*; public class Circle extends GraphicsProgram { public void

More information

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Developed By Brian Weinfeld Course Description: AP Computer

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Java from a C perspective. Plan

Java from a C perspective. Plan Java from a C perspective Cristian Bogdan 2D2052/ingint04 Plan Objectives and Book Packages and Classes Types and memory allocation Syntax and C-like Statements Object Orientation (minimal intro) Exceptions,

More information

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75 Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

More information

Part 1 Foundations of object orientation

Part 1 Foundations of object orientation OFWJ_C01.QXD 2/3/06 2:14 pm Page 1 Part 1 Foundations of object orientation OFWJ_C01.QXD 2/3/06 2:14 pm Page 2 1 OFWJ_C01.QXD 2/3/06 2:14 pm Page 3 CHAPTER 1 Objects and classes Main concepts discussed

More information

Facebook Twitter YouTube Google Plus Website Email

Facebook Twitter YouTube Google Plus Website Email PHP MySQL COURSE WITH OOP COURSE COVERS: PHP MySQL OBJECT ORIENTED PROGRAMMING WITH PHP SYLLABUS PHP 1. Writing PHP scripts- Writing PHP scripts, learn about PHP code structure, how to write and execute

More information

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism Polymorphism 1 Agenda What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism 2 What is & Why Polymorphism? 3 What is Polymorphism? Generally, polymorphism refers

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4

More information

Java Programming Language

Java Programming Language Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and

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 EggBasket { public static void main(string[]

More information

Homework/Program #5 Solutions

Homework/Program #5 Solutions Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the

More information

Lecture 5: Java Fundamentals III

Lecture 5: Java Fundamentals III Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd

More information

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities The classroom is set up like a traditional classroom on the left side of the room. This is where I will conduct my

More information

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui

More information

Graduate Assessment Test (Sample)

Graduate Assessment Test (Sample) Graduate Assessment Test (Sample) CS201-203 1. Fibonacci sequence is defined by a recurrence relation. The series is: 0,1,1,2,3,5,8,13,... Write a complete recursive method/function that returns the fibonacci

More information

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science I. Basic Course Information RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE CISY 105 Foundations of Computer Science A. Course Number and Title: CISY-105, Foundations of Computer Science B. New

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553]

Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553] Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553] Books: Text Book: 1. Bjarne Stroustrup, The C++ Programming Language, Addison Wesley 2. Robert Lafore, Object-Oriented

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

The Interface Concept

The Interface Concept Multiple inheritance Interfaces Four often used Java interfaces Iterator Cloneable Serializable Comparable The Interface Concept OOP: The Interface Concept 1 Multiple Inheritance, Example Person name()

More information

API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.

API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list. Sequences and Urns 2.7 Lists and Iterators Sequence. Ordered collection of items. Key operations. Insert an item, iterate over the items. Design challenge. Support iteration by client, without revealing

More information

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009 STORM Simulation TOol for Real-time Multiprocessor scheduling Designer Guide V3.3.1 September 2009 Richard Urunuela, Anne-Marie Déplanche, Yvon Trinquet This work is part of the project PHERMA supported

More information