What s Wrong with This?

Size: px
Start display at page:

Download "What s Wrong with This?"

Transcription

1 More Sophisticated Behaviour 2 Using library classes to implement more advanced functionality. Also class (static( static) ) fields. What s Wrong with This? class Notebook private ArrayList<String> notes; public Notebook () ArrayList<String> notes = new ArrayList<String> (); public void addnote (String note) notes.add (note); What s Wrong with This? class Notebook private ArrayList<String> notes; Delete!!! public Notebook () ArrayList<String> notes = new ArrayList<String> (); public void addnote (String note) notes.add (note); 1

2 Keep going to the classes! Main Concepts to be Covered More library classes sets and maps (HashSet( and HashMap) Information hiding public versus private Class fields static and final Writing documentation Seen before Using lists import java.util.arraylist ArrayList; import java.util.iterator; ArrayList<String> mylist = new ArrayList<String> (); mylist.add ("one"); mylist.add ("two"); mylist.add ("one"); Iterator<String> it = mylist.iterator (); while (it.hasnext( ()) String s = it.next ();... do something with s 2

3 New Using sets import java.util.hashset HashSet; import java.util.iterator; HashSet<String> myset = new HashSet<String> (); myset.add ("one"); myset.add ("two"); myset.add ("one"); Iterator<String> it = myset.iterator (); while (it.hasnext( ()) String s = it.next ();... do something with s Using sets and lists import java.util.hashset HashSet; import java.util.iterator; All varieties of set and list are examples of collection classes. We can use for-each loops and Iterators on them. Of course, we can also use get (index) methods on them as well (or instead). One difference is that a set one holds one instance of objects that are equal i.e. if a and b have both been added to a set and a.equals(b),, then only one of them will be there. It is not guaranteed which one is kept. So, never search a set using ==. Using sets and lists import java.util.hashset HashSet; import java.util.iterator; All varieties of set and list are examples of collection classes. We can use for-each loops and Iterators on them. Of course, we can also use get (index) methods on them as well (or instead). A second difference is that the order in which elements are kept in a set is not defined. For example, the order of elements returned by a for-each loop or Iterator is not necessarily the same order in which they were added. 3

4 Using sets and lists import java.util.hashset HashSet; import java.util.iterator; Go look them up in the Java API documentation!!! Seen before Eliza Project SupportSystem InputReader See Chapter05, tech-support projects Seen before Eliza Main Loop boolean finished = false; while (!finished) ) This returns the line of text typed by the customer. String input = reader.getinput (); if (input.startswith( ("bye"))) finished = true; else String response = responder.generateresponse (); System.out.println (response); Chapter05, tech-support1, SupportSystem.start() 4

5 New Eliza Main Loop boolean finished = false; while (!finished) ) This returns the set of different words typed by the customer. HashSet<String> input = reader.getinput (); if (input.contains( ("bye"))) finished = true; Now, bye can be any else word not just the first. Go look this up String response = (java.util.hashset) responder.generateresponse (input); System.out.println (response); Chapter05, tech-support-complete, complete, SupportSystem.start() New Eliza Main Loop boolean finished = false; while (!finished) ) This is the first time the response is dependant upon the enquiry! HashSet<String> input = reader.getinput (); if (input.contains( ("bye"))) finished = true; else String response = responder.generateresponse (input); System.out.println (response); Chapter05, tech-support-complete, complete, SupportSystem.start() New Eliza InputReader public String getinput () System.out.print ("> "); String inputline = scanner.nextline(); return inputline; import java.util.scanner; private Scanner scanner; go look this up (java.util.scanner) This is a String Note: in the project code, scanner is (confusingly) called reader Chapter05, tech-support1, InputReader.getInput() 5

6 New Eliza InputReader public HashSet<String> getinput () private Scanner scanner; System.out.print ("> ") ; String inputline = scanner.nextline().trim().tolowercase(); ();... more stuff import java.util.scanner; Note: in the project code, scanner is (confusingly) called reader Chapter05, tech-support-complete, complete, InputReader.getInput() New Eliza InputReader public HashSet<String> getinput () private Scanner scanner; System.out.print ("> ") ; String inputline = scanner.nextline().trim().tolowercase(); ();... more stuff import java.util.scanner; This is a String Chapter05, tech-support-complete, complete, InputReader.getInput() New Eliza InputReader public HashSet<String> getinput () private Scanner scanner; System.out.print ("> ") ; String inputline = scanner.nextline().trim().tolowercase(); ();... more stuff import java.util.scanner; So is this Chapter05, tech-support-complete, complete, InputReader.getInput() 6

7 New Eliza InputReader import java.util.scanner; public HashSet<String> getinput () go look these up private Scanner scanner; (java.lang.string) System.out.print ("> ") ; String inputline = scanner.nextline().trim().tolowercase(); ();... more stuff go look this up (java.util.scanner) So is this Chapter05, tech-support-complete, complete, InputReader.getInput() New Eliza InputReader public HashSet<String> getinput () go look this up (java.lang.string) System.out.print ("> "); String inputline = scanner.nextline().trim().tolowercase(); (); String[] wordarray = inputline.split (" "); HashSet<String> wordset = new HashSet<String> (); for (String word : wordarray) ) wordset.add (word); converts the which eliminates array to a set return wordset; repeated words Chapter05, tech-support-complete, complete, InputReader.getInput() Maps Maps are collections that contain pairs of values. A pair consists of a key and a value. Lookup works by supplying a key, and retrieving the corresponding value. An example: a telephone book. 7

8 Using Maps A map with Strings both as keys and values: phonebook:hashmap "Rick Blaine" "(531) " "Ilsa Lund" "(402) " "Victor Laszlo" "(998) " Using Maps HashMap<String, String> phonebook = new HashMap<String, String> (); key value ( "Rick Blaine", "(531) "); ( "Ilsa" Lund", "(402) "); ("Victor Laszlo", "(998) "); value key String phonenumber = phonebook.get ("Rick Blaine");... System.out.println (phonenumber); Using Maps HashMap<String, String> phonebook = new HashMap<String, String> (); key value ( "Rick Blaine", "(531) "); ( "Ilsa" Lund", "(402) "); ("Victor Laszlo", "(998) "); value key String phonenumber = phonebook.get ("Ricky Blaine");... Important: invoking get with a key that does not exist in the HashMap object returns null.. This can be useful! 8

9 Using Maps HashMap<String, String> phonebook = new HashMap<String, String> (); key value ( "Rick Blaine", "(531) "); ( "Ilsa" Lund", "(402) "); ("Victor Laszlo", "(998) "); value key String phonenumber = phonebook.get ("Ricky Blaine"); if (phonenumber( == null)... else... Important: invoking get with a key that does not exist in the HashMap object returns null.. This can be useful! Using Maps HashMap<String, String> phonebook = new HashMap<String, String> (); key value ( "Rick Blaine", "(531) "); ( "Ilsa" Lund", "(402) "); ("Victor Laszlo", "(998) "); value key String phonenumber = phonebook.get ("Ricky Blaine"); if (phonenumber( == null)... else... "Ricky Blaine" was not in the phonebook "Ricky Blaine" was in the phonebook Seen before Eliza Project SupportSystem InputReader See Chapter05, tech-support projects 9

10 Just seen Eliza InputReader public HashSet<String> getinput () go look this up (java.lang.string) System.out.print ("> "); String inputline = scanner.nextline().trim().tolowercase(); (); String[] wordarray = inputline.split (" "); HashSet<String> wordset = new HashSet<String> (); for (String word : wordarray) ) wordset.add (word); convert the which eliminates array to a set return wordset; repeated words Chapter05, tech-support-complete, complete, InputReader.getInput() Seen before Eliza Project SupportSystem InputReader See Chapter05, tech-support projects Just seen Eliza Main Loop boolean finished = false; while (!finished) ) This is the first time the response is dependant upon the enquiry! HashSet<String> input = reader.getinput (); if (input.contains( ("bye"))) finished = true; else String response = responder.generateresponse (input); System.out.println (response); Chapter05, tech-support-complete, complete, SupportSystem.start() 10

11 Seen before Eliza Project SupportSystem InputReader See Chapter05, tech-support projects Seen before Generating Random Responses public () Chapter05, tech-support2, randomgenerator = new Random (); responses = new ArrayList<String> (); fillresponses (); private void fillresponses () returns a random... number in the legal range for indexing responses public String generateresponse () int index = randomgenerator.nextint (responses.size ()); return responses.get (index); New Generating Better Responses Chapter05, tech-support-complete, complete, public () randomgenerator = new Random (); defaultresponses = new ArrayList<String> (); filldefaultresponses (); responsemap = new HashMap<String, String> (); fillresponsemap ();... private void filldefaultresponses ()... private void fillresponsemap () private String pickdefaultresponse () int index = randomgenerator.nextint (defaultresponses.size ()); return responses.get (index); Same as tech-support2 generateresponse 11

12 Generating Random Responses Chapter05, tech-support-complete, complete, private void filldefaultresponses () defaultresponses.add ("That sounds odd. Tell me more?"); defaultresponses.add ("No one else complained!"); defaultresponses.add ("Interesting. Tell me more?"); defaultresponses.add ("Do you have a dll conflict?"); defaultresponses.add ("Read the ******* manual!"); defaultresponses.add ("That's not a bug - it's a feature!");... etc. Same as tech-support2 fillresponses Just seen Generating Better Responses Chapter05, tech-support-complete, complete, public () randomgenerator = new Random (); defaultresponses = new ArrayList<String> (); filldefaultresponses (); responsemap = new HashMap<String, String> (); fillresponsemap ();... private void filldefaultresponses ()... private void fillresponsemap () private String pickdefaultresponse () int index = randomgenerator.nextint (defaultresponses.size ()); return responses.get (index); Same as tech-support2 generateresponse New Generating Relevant Responses Chapter05, tech-support-complete, complete, private void fillresponsemap () responsemap.put ("crash", "Well, it never crashes here!\n" + "Tell me about your configuration?"); responsemap.put ("slow", "Upgrade your processor then!\n" + "That should solve your problems."); responsemap.put ("windows", "This is a known bug in Windows!\n + "Please report it to Microsoft");... etc. 12

13 New Generating Better Responses Chapter05, tech-support-complete, complete, public String generateresponse (HashSet<String> words) Iterator<String> it = words.iterator (); while (it.hasnext( ()() String word = it.next (); String response = responsemap.get (word); if (response(!= null) return response; supply the key return pickdefaultresponse (); If the key is in the Map,, this returns the matching value otherwise returns null. Or Generating Better Responses Chapter05, tech-support-complete, complete, public String generateresponse (HashSet<String> words) for (String word : words) ) String response = responsemap.get (word); if (response(!= null) return response; supply the key return pickdefaultresponse (); If the key is in the Map,, this returns the matching value otherwise returns null. Revision Make sure you understand every statement on the next slide 13

14 Revision A class is a template from which objects can be constructed. A class defines the data fields held by its objects, together with logic for constructors of its objects and methods for accessing and operating on their data. Methods (and constructors) may declare and use their own local variables these exist only for the duration of their method (or constructor). On the other hand, data fields last for the duration of their object. Methods and constructors may be passed parameters these exist only for the duration of the method or constructor. Data fields, parameters and local variables may have class types (i.e. they are references to other objects) or primitive types (e.g. int, float, boolean, char, ). Data fields, constructors and methods may be declared public or private. Revision If you don t, you must find out e.g. read the book! Information hiding Public attributes (fields, constructors, methods) are accessible to other classes. Fields should not (usually) be public. Private attributes are accessible only within the same class. Only methods and constructors that are intended for use by other classes should be public. 14

15 Information hiding Data belonging to one object should be hidden from other objects. Know what an object can do, not how it does it. Information hiding increases the level of independence. Independence of modules ( low coupling ) is important for building and maintaining large systems. Chapter05, balls Class Fields New Class Fields A class defines the data fields held by its objects, together with logic for constructors of its objects and methods for accessing and operating on their data. A class may also define class fields,, which are shared by all its objects. The class itself holds a single instance of each of these fields its objects all work with the same instances. Compare this with data fields objects all work with their own (different) instances. Class fields are declared with the keyword: static. In the BouncingBall class, gravity is a class field whose common value is shared by all its instances the data fields xposition and yposition have values that are specific for each ball. 15

16 A Class Constant private static final int gravity = 3; private : specifies the visibilty of the declaration. static : specifies that all objects of this class share this field it belongs to the class. final : specifies that the value given cannot be changed it is a constant. Note: final can be applied to any field (class or data), method local variable or parameter. Writing class documentation Your own classes should be documented in the same way and to the same standard as the built- in library classes. Other people should be able to use your classes without reading their implementation. Make your class a library class Investigate Investigate Investigate!!!!!!!!! Java libraries are called packages Elements of documentation Documentation for a class should include: the class name a description of the overall purpose and characteristics of the class a version number author names documentation explaining each constructor and each method 16

17 Elements of documentation Documentation for each constructor and method should include: the name of the method the return type (if any) the parameter names and types a description of the purpose and function of each method a description of each parameter a description of the value returned (if any) javadoc - Class comments /** * The class represents a response * generator object. It is used to generate * an automatic response. * Michael Kölling and David J. Barnes 1.0 (30.Mar.2006) */ class... javadoc - Method comments /** * Change the colour of this shape. The new colour * becomes visible immediately. Legal colour strings * are "White", "Orange", "Blonde", "Pink", "Blue" * and "Brown". * colour The name of the new colour. true, if the colour was successfully changed; * false, if the colour name is invalid. */ public boolean changecolour (String colour)... 17

18 Review Java has an extensive class library (packages). A good programmer must know how to find things in the library and become familiar with those regularly used. The documentation tells us what we need to know to use a class (interface). The implementation is hidden (information hiding). We document our classes so that the interface can be read on its own (class comment, method comments). 18

Collections and iterators

Collections and iterators Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 2.0 Concepts covered so far Abstraction Modularization Classes define types Class and object diagrams

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

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

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

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

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

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

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

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

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

System.out.println(\nEnter Product Number 1-5 (0 to stop and view summary) : Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class

More information

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources

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

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

10 Java API, Exceptions, and Collections

10 Java API, Exceptions, and Collections 10 Java API, Exceptions, and Collections Activities 1. Familiarize yourself with the Java Application Programmers Interface (API) documentation. 2. Learn the basics of writing comments in Javadoc style.

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

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

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Directions: In mobile Applications the Control Model View model works to divide the work within an application.

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

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

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

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

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

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

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

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

CMSC 202H. ArrayList, Multidimensional Arrays

CMSC 202H. ArrayList, Multidimensional Arrays CMSC 202H ArrayList, Multidimensional Arrays What s an Array List ArrayList is a class in the standard Java libraries that can hold any type of object an object that can grow and shrink while your program

More information

Specialized Programme on Web Application Development using Open Source Tools

Specialized Programme on Web Application Development using Open Source Tools Specialized Programme on Web Application Development using Open Source Tools A. NAME OF INSTITUTE Centre For Development of Advanced Computing B. NAME/TITLE OF THE COURSE C. COURSE DATES WITH DURATION

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

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

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement CompSci 125 Lecture 08 Chapter 5: Conditional Statements Chapter 4: return Statement Homework Update HW3 Due 9/20 HW4 Due 9/27 Exam-1 10/2 Programming Assignment Update p1: Traffic Applet due Sept 21 (Submit

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

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

Topic 11 Scanner object, conditional execution

Topic 11 Scanner object, conditional execution Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright

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

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

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

Computer Programming I

Computer Programming I Computer Programming I Levels: 10-12 Units of Credit: 1.0 CIP Code: 11.0201 Core Code: 35-02-00-00-030 Prerequisites: Secondary Math I, Keyboarding Proficiency, Computer Literacy requirement (e.g. Exploring

More information

Using Files as Input/Output in Java 5.0 Applications

Using Files as Input/Output in Java 5.0 Applications Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead

More information

To Java SE 8, and Beyond (Plan B)

To Java SE 8, and Beyond (Plan B) 11-12-13 To Java SE 8, and Beyond (Plan B) Francisco Morero Peyrona EMEA Java Community Leader 8 9...2012 2020? Priorities for the Java Platforms Grow Developer Base Grow Adoption

More information

AP Computer Science Java Mr. Clausen Program 9A, 9B

AP Computer Science Java Mr. Clausen Program 9A, 9B AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will

More information

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error

More information

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

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

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 Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix

Java Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Java Cheatsheet http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Hello World bestand genaamd HelloWorld.java naam klasse main methode public class HelloWorld

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

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

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

Visual Basic Programming. An Introduction

Visual Basic Programming. An Introduction Visual Basic Programming An Introduction Why Visual Basic? Programming for the Windows User Interface is extremely complicated. Other Graphical User Interfaces (GUI) are no better. Visual Basic provides

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

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Introduction to Electrical and Computer Engineering II Lecture 1 Course Overview Welcome! What is this class about? Java programming somewhat software somewhat

More information

CSE 308. Coding Conventions. Reference

CSE 308. Coding Conventions. Reference CSE 308 Coding Conventions Reference Java Coding Conventions googlestyleguide.googlecode.com/svn/trunk/javaguide.html Java Naming Conventions www.ibm.com/developerworks/library/ws-tipnamingconv.html 2

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

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

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

Chapter 11 Data Structures

Chapter 11 Data Structures Chapter 11 Data Structures Introduction Up until now, we have been declaring variables one at a time. But, sometimes you want ten, or a thousand variables. If you were implementing software for a real

More information

Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i),

Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i), Arrays Has special language support Iterators Collections in Java Iterator (i) Collections (also called containers) Collection (i) Set (i), HashSet (c), TreeSet (c) List (i), ArrayList (c), LinkedList

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

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

Reach 4 million Unity developers

Reach 4 million Unity developers Reach 4 million Unity developers with your Android library Vitaliy Zasadnyy Senior Unity Dev @ GetSocial Manager @ GDG Lviv Ankara Android Dev Days May 11-12, 2015 Why Unity? Daily Users 0 225 M 450 M

More information

FOR EVALUATION ONLY NOT FOR DISTRIBUTION

FOR EVALUATION ONLY NOT FOR DISTRIBUTION David Barnes Michael Kölling Objects First with Java A Practical Introduction using BlueJ FOR EVALUATION ONLY NOT FOR DISTRIBUTION Copyright Barnes, Kölling, 2002 Pearson Education / Prentice Hall ISBN

More information

Lab 5: Bank Account. Defining objects & classes

Lab 5: Bank Account. Defining objects & classes Lab 5: Bank Account Defining objects & classes Review: Basic class structure public class ClassName Fields Constructors Methods Three major components of a class: Fields store data for the object to use

More information

AP Computer Science Static Methods, Strings, User Input

AP Computer Science Static Methods, Strings, User Input AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because

More information

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement

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

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

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc. WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25

More information

How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014

How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014 How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014 This work is licensed under a Creative Commons Attribution 4.0 International License. http://creativecommons.org/licenses/by/4.0/

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

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

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

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

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

Web Development using PHP (WD_PHP) Duration 1.5 months

Web Development using PHP (WD_PHP) Duration 1.5 months Duration 1.5 months Our program is a practical knowledge oriented program aimed at learning the techniques of web development using PHP, HTML, CSS & JavaScript. It has some unique features which are as

More information

In this Chapter you ll learn:

In this Chapter you ll learn: Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

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

Specialized Programme on Web Application Development using Open Source Tools

Specialized Programme on Web Application Development using Open Source Tools Specialized Programme on Web Application Development using Open Source Tools Objective: At the end of the course, Students will be able to: Understand various open source tools(programming tools and databases)

More information

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000 Intro to Web Programming using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000 Intro Types in PHP Advanced String Manipulation The foreach construct $_REQUEST environmental variable Correction on

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

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION 1. Write a loop that computes (No need to write a complete program) 100 1 99 2 98 3 97... 4 3 98 2 99 1 100 Note: this is not the only solution; double sum

More information

Basics of Java Programming Input and the Scanner class

Basics of Java Programming Input and the Scanner class Basics of Java Programming Input and the Scanner class CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

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

Affdex SDK for Android. Developer Guide For SDK version 1.0

Affdex SDK for Android. Developer Guide For SDK version 1.0 Affdex SDK for Android Developer Guide For SDK version 1.0 www.affdex.com/mobile-sdk 1 August 4, 2014 Introduction The Affdex SDK is the culmination of years of scientific research into emotion detection,

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

e ag u g an L g ter lvin v E ram Neal G g ro va P Ja

e ag u g an L g ter lvin v E ram Neal G g ro va P Ja Evolving the Java Programming Language Neal Gafter Overview The Challenge of Evolving a Language Design Principles Design Goals JDK7 and JDK8 Challenge: Evolving a Language What is it like trying to extend

More information

Web development... the server side (of the force)

Web development... the server side (of the force) Web development... the server side (of the force) Fabien POULARD Document under license Creative Commons Attribution Share Alike 2.5 http://www.creativecommons.org/learnmore Web development... the server

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck

More information

More on Objects and Classes

More on Objects and Classes Software and Programming I More on Objects and Classes Roman Kontchakov Birkbeck, University of London Outline Object References Class Variables and Methods Packages Testing a Class Discovering Classes

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Inner classes, RTTI, Tree implementation Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 29, 2010 G. Lipari (Scuola Superiore Sant

More information

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch3 Implementing Classes PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com,

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

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

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

1. What are Data Structures? Introduction to Data Structures. 2. What will we Study? CITS2200 Data Structures and Algorithms

1. What are Data Structures? Introduction to Data Structures. 2. What will we Study? CITS2200 Data Structures and Algorithms 1 What are ata Structures? ata Structures and lgorithms ata structures are software artifacts that allow data to be stored, organized and accessed Topic 1 They are more high-level than computer memory

More information

3 Improving the Crab more sophisticated programming

3 Improving the Crab more sophisticated programming 3 Improving the Crab more sophisticated programming topics: concepts: random behavior, keyboard control, sound dot notation, random numbers, defining methods, comments In the previous chapter, we looked

More information

Lecture J - Exceptions

Lecture J - Exceptions Lecture J - Exceptions Slide 1 of 107. Exceptions in Java Java uses the notion of exception for 3 related (but different) purposes: Errors: an internal Java implementation error was discovered E.g: out

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

Loops and ArrayLists

Loops and ArrayLists Chapter 6 Loops and ArrayLists What is in this Chapter? When programming, it is often necessary to repeat a selected portion of code a specific number of times, or until some condition occurs. We will

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