COP 3330: Object Oriented Programming FALL 2017 STUDY UNION REVIEW CREDIT TO DR. GLINOS AND PROFESSOR WHITING FOR COURSE CONTENT
|
|
- Marion Waters
- 6 years ago
- Views:
Transcription
1 COP 3330: Object Oriented Programming FALL 2017 STUDY UNION REVIEW CREDIT TO DR. GLINOS AND PROFESSOR WHITING FOR COURSE CONTENT
2 Object-Oriented Structure
3 Program Structure Main structural elements of Java programming Classes Interfaces Subclasses Methods, Class Variables Objects Instance Variables
4 Objects Objects Instance Variables Software bundle of related state and behavior used within programs Model real-world objects State: variables Behavior: methods Let s use this car as an example object.
5 State In the form of instance variables AKA member variables, fields Specific to object they are representing Allow for encapsulation Can use private instance variables Getters and setters: public String getbrand() { return brand; } What are some instance variables for this object? There are many possible answers, try it!
6 State In the form of instance variables AKA member variables, fields Specific to object they are representing Allow for encapsulation Can use private instance variables Getters and setters: public String getbrand() { return brand; } What are some instance variables for this object? String color = gray; int speed = 100; Person owner = Brigit; Instance variables can be a variety of types!
7 Behavior Tasks are performed through methods Calling a method tells program to perform that specific task or behavior: ObjectName.methodName(); How would you call the setspeed method on the object mycar? Try it!
8 Behavior Tasks are performed through methods Calling a method tells program to perform that specific task or behavior: ObjectName.methodName(); How would you call the setspeed method on the object mycar? mycar.setspeed(100); We will see more about methods later on!
9 Benefits of Objects Modularity: object can be easily used throughout system Information-hiding: interact with object s methods rather than its exact internal representation Code reuse Debugging: only need to change/remove specific object if it causes issues
10 Classes Like blueprint to create individual objects Contain variables and methods Can import methods from other classes through import statements at top of class Related classes may be put into same package Vehicle Car CoolSportsCar
11 Classes Writing new class follows format: public class ClassName{ // Variables // Methods }
12 Objects Vs Classes Classes are broad blueprint Objects are specific instances of that blueprint
13 Methods Method signatures require name, types and names of parameters, and return type (int, String, void, etc.) Valid method signatures: public String getname(car mycar); private static Boolean setspeed(int speed); void adddriver(string name); this keyword refers to object currently running the method Useful when parameter and instance variable have same name
14 Constructor Similar to a method, but name is same as class, no return type Explicit (specified by programmer) or default (Java uses default no argument constructor) Can call one from another by using this() as first line in constructor
15 Constructor Let s code up a class for a House with a few constructors One will call the other
16
17 Instantiation In order to create new objects, they need to be instantiated Follow general format: ClassName objectname = new ClassName(); ClassName indicates type of object, which is the class ObjectName indicates name of this specific object/instance of the class new ClassName() calls the constructor for the class and actually sets aside memory for this object
18 Declaration vs Instantiation Declaring an object: Vehicle car; No memory associated with it Instantiating an object: car = new Vehicle(); Object actually exists and has memory
19 Try It! Practice Problem: Create your own class for shoes. It should have instance variables for brand, size, color, and owner. Its methods should include a constructor, a getter for the color, and a setter for the owner. There can be more than one right answer! We ll code it up in a few minutes.
20
21 General Java Syntax and Practices
22 Assignment Simple assignment: uses = operator x = 10 * y; Compound assignment: perform operation and assignment x *= 10; y += j; z /= 100; a -= 1;
23 Assignment Conditional assignment: uses? and : First choice assigned if condition is true Example: int x = 100, y = 50; int larger = (x > y)? x : y; What is the value of larger?
24 Assignment Conditional assignment: uses? and : int x = 100, y = 50; int larger = (x > y)? x : y; What is the value of larger? Evaluates condition (x > y) If condition is met (x is larger than y), then first choice (x) is assigned Otherwise, second choice (y) is assigned Assigns x to larger since x = 100 > y = 50 larger = x = 100
25 Order of Precedence Operators: Special symbols that perform specific actions on one, two, or three operands Evaluated in order of precedence Parentheses first * and / and % next + and next + used with both addition and string concatenation = is evaluated last
26 Order Example What would be the output from the example below? Try it! j = 10; j++; x = j; System.out.println(j); System.out.println(x); System.out.println(x++); System.out.println(++x); System.out.println(x); System.out.println( x+j );
27 Order Example What would be the output from the example below? Try it! j = 10; j++; x = j; System.out.println(j); System.out.println(x); System.out.println(x++); System.out.println(++x); System.out.println(x); System.out.println( x+j ); Output: x+j
28 Mathematic Methods Built in methods to perform math functions easily Explore the Math class API Math.pow(x, y), Math.sqt(x), Math.min(x, y), Math.max(x, y) But what if want to find the minimum or maximum of more than two values? Try it! Use the Math.max() method to find the maximum of three numbers.
29 Max or Min of More than Two Numbers Math.max( Math.max(x, y), z); First compares x and y Then compares greater of x and y with z Use the method more than once
30 Expressions Expressions consist of variables, operators, and method invocations Constructed following appropriate Java syntax Evaluate to a single value Doesn t need to be a complete statement/working line of code Examples: result = Value1 == value 2
31 Expression Statement Complete unit of execution with a terminating semicolon myvalue = 800; Question: Evaluate the line: x + y z = 100; Is it an expression or expression statement? Why?
32 Control Flow Statements Control Flow Statements: regulate order in which statements get executed Examples: if while if-else do-while if-else if-else break switch continue for return
33 if statement Decision making statement Only executes certain section of code if particular condition true if(condition) { // code executed if condition met }
34 if else statement Different from if statement since provides specific alternate code to execute if condition is not met Else always associated with immediately preceding if Use curly braces! Once a condition is satisfied, remaining conditions are not evaluated
35 Example What is the output of this code? int x = 50; if(x > 5) System.out.println( Hello! ); else if(x > 40) System.out.println( Goodybe! );
36 Example What is the output of this code? int x = 50; if(x > 5) System.out.println( Hello! ); else if(x > 40) System.out.println( Goodybe! ); Output: Hello!
37 Switch Statement Decision making statement Break statements are necessary, or else fall through All statements after matching case label are executed until a break is encountered Tests expressions only on single value while if-else can test expressions or ranges of values
38 Example What is the output of this code? int x = 10; switch(x){ case 10: System.out.println( Hello! ); case 5: System.out.println( Goodybe! ); default: System.out.println( Again! ); break; }
39 Example What is the output of this code? int x = 10; switch(x){ case 10: System.out.println( Hello! ); case 5: System.out.println( Goodybe! ); default: System.out.println( Again! ); break; } Output: Hello! Goodbye! Again!
40 For Loops Two different forms Traditional: for(int i = 0; i < 100; i++) for(; ; ;) is also an acceptable form For each: for(string temp : names)
41 While Loops While loops execute while a condition is true while(x < 10) x++; May never execute if condition is not initially met Do-While loops also execute while a condition is true do { x++; }while(x < 10); Will execute at least once since condition is evaluated after body of loop
42 Break, Continue Break: Exits out of closest loop Use labels if wish to break out earlier first: while(.. ) while(.) if(.) break first; Continue: jumps to end of current loop iteration for(i = 0; i < 10; i++) if(i % 2 == 0) continue; j += 2;
43 Chars vs Strings Chars and Strings are more distinct in Java than in C Character: single letter, primitive type Assigned using single quotes char a = a ; Compared with == a == b
44 Chars vs Strings String: sequence of characters Reference type, not primitive Defaults to null Immutable (can t be changed) once created Enclosed in double quotes: String name = Brigit ;
45 Strings Convert to string: Integer.toString(100); Convert to integer: Integer.parseInt( 100 ); Useful methods in String API s.length(); s.charat(); Concatenation with + Use Method.equals() rather than == to compare Strings
46 Strings: Self-Test! You re given the following variables: int x = 100; String name = Hello ; Write the Java code to create the String Hello100 from the two variables x and name Is a String one character in length equivalent to a character? Is null string the same as empty string?
47 Strings: Self-Test! You re given the following variables: int x = 100; String name = Hello ; String hundred = Integer.toString(100); String result = name + hundred; Is a one character String equivalent to a character? No; char is primitive and String is reference type Is null string the same as empty string? No; strings default to null but are specifically set to empty Empty string: String name = ;
48 Arrays Must hold variables/objects all same data type Index starts at 0 Access specific index: a[0] String[] myarray and String myarray[] both acceptable myarray.length defined for every array All index values already initialized 0 for primitive types, null for reference types Can t be resized
49 ArrayList ArrayList extends AbstractList and implements List interface Size increases and decreases as appropriate Cannot hold primitive types (sorry char, int, double) Need to be initialized like other objects ArrayList<String> hi = new Arraylist<String>();
50 ArrayList ArrayList API lists many useful methods:.get().add(e).add(i, e).remove(i).remove(o).indexof().size().contains().isempty()
51 Wrapper Classes But what if I want to store an int in an ArrayList? Wrapper Classes: Allow primitives to be used as reference variables Integer for int i.e. int x = 100; Integer myx = new Integer(x); Double for double Character for char
52 Input Scanner class: text scanner can parse primitive types and strings Input broken into string tokens Whitespace is default delimiter between tokens Create scanner object: Scanner myscan = new Scanner(inputStream);
53 Input and Scanning myscan.next(); myscan.nextint(); myscan.nextdouble(); myscan.nextline(); myscan.hasnext();
54 Output System.out.print() System.out.println() System.out.printf() Most like C Requires arguments if there are format specifiers Format specifiers: %d, %s, %c
55 Methods, Variables, and Class Specifics
56 Variables Class Variables: use static keyword Value shared by all instances of the class i.e. for Car class, a class variable would be numwheels All cars will have numwheels = 4 Instance variables: non-static Each object has its own i.e. for Car class, an instance variable would be owner Each car will have a distinct owner unique to that car
57 Class and Instance Variables Example Let s code up an example of class and instance variables using a class for Laptop
58
59 Constants Declared with static final Static makes it consistent across all objects Final prevents its value from being changed later All caps by naming convention public static final WHEELS = 4;
60 Instance vs Class Methods Instance Method: depends in some way on instance variables Use dot operator with object name: myinstance.method(); Class Method: static keyword used Behavior not dependent on instance variables Dot operator with class name: Class.method();
61 Overloading For methods and constructors All have same name Differ in order, number, or types of input parameters Different method signatures Useful if users may have different parameters at different points when calling the method
62 Overloading Try it! 1. Overload the following method two different ways: public void editcar(); 2. Are the following method signatures valid overloading? public void addname(string name, int age); public void addname(string lastname, int id);
63 Overloading 1. Overload the following method two different ways public void editcar(int number); public void editcar(string name); 2. Are the following method signatures valid overloading? No! Their parameters are of the same type and in the same order.
64 Overloading Try it! Add to the Laptop class to overload at least one method.
65
66 Overriding Declaring a field or method in a subclass that s already in the superclass Must use same signature and access modifier Or else would be overloading Can t override final method
67 Overriding Let s try it with our Laptop class! We re going to make the Computer class
68
69
70 Levels of Access Different access modifiers for classes, methods, and variables Package-private is default access for classes, methods, variables Public: accessible anywhere Private: only same class, not subclasses; better than protected Protected: accessible by same class, subclasses, classes in same package
71 Inheritance Create new class using existing class Superclass: class from which other classes inherit fields and methods Subclass: inherits all fields and methods from superclass Can modify inherited methods through overriding Can add own fields and methods
72 Inheritance Use keyword extends public class Person extends Human Every class extends a superclass Object class inherently Can extend only one superclass One superclass can have many subclasses
73 Abstract Classes Blueprint for similar subclasses Declared with format: public abstract MyClass{ Can t be instantiated i.e. can t instantiate broad Vehicle superclass All vehicles either car, truck,
74 Abstract Classes Includes concrete methods With implementation (method body) Also includes abstract methods Without implementation (no method body, just signature) Subclass must implement all abstract methods Subclass is abstract otherwise
75 Interfaces Specifies set of methods a class must implement Class won t compile if doesn t implement them all Class becomes more formal about behavior promises to provide Declared as: public interface MyInterface{
76 Interfaces Different than superclass since all methods (other than static or default) are abstract All methods are public and abstract Don t have to include keywords No instance variables
77 Abstract Classes and Interfaces Let s create abstract class Friend BestFriend vs Frenemy
78
79
80
81 Multiple Inheritance of Type Class can implement more than one interface Extend just one superclass Object can have multiple types Its own class All the interfaces its class implements i.e. if class Car implements Vehicle, then both instantiations below are valid: Car mycar = new Car(); Vehicle mycar = new Car();
82 Polymorphism Subclasses share functionality of their parent class but also define their own unique behaviors Treating objects of different types the same based on their common characteristics Hierarchy, implement same interfaces Instance of class can be of type its supertype List mylist = new ArrayList();
83 Organizing Information
84 List Ordered collection of objects All elements must be same type or common superclass Allows for duplicates and null elements Type in angled brackets <> i.e. List<String>
85 Iterator Java class to traverse a collection Iterator<String> myiterator = mylist.iterator(); while(iter.hasnext()) String temp = iter.next();
86 Set Unordered collection of objects Elements must be same type or superclass No duplicates, only 1 null element Type within angle brackets <> Need to save in SortedSet or other structure (like an array or List) if want ordered elements
87 Map Maps keys to values No duplicate keys Each key mapped to at most 1 value Can have null key or value Keys and values must be reference types Map<Integer, String> = new HashMap();
88 Generics Perform same actions on different kinds of objects Use uppercase letter (typically T) to indicate use of generics Generic method: declared with one or more type parameters Types will be input parameters and/or return types Example Method: what if want to print an array, but don t know what type of data will be held in the array? Public static <T> void printarray(t[] inputarray) {. }
89 Generic Classes Class is generic with one or more generic type parameters Use angled brackets with uppercase letter after class name Try it! Declare a generic class called MyClass There are several possible answers
90 Generic Classes Try it: Declare a generic class called MyClass public class MyClass<T>{ } public class MyClass<T, V>{ }
91 Stacks, Queues, Linked Lists Stack: LIFO ($ is life!) Push, pop Queue: FIFO Enqueue, dequeue Linked list: dynamic list of nodes, alternative to arrays Java API for built-in functionality for all three classes
92 Raw Type Raw Type: If don t specify type when instantiating a generic Stack mystack = new Stack(); Stack is a generic, and it wasn t declared with a type in angled brackets Introduce diamond operator when want to restrict what type of objects generic can hold Stack<String> mystack = new Stack<String>();
93 User Interfaces, Exceptions, and Threads
94 Java GUI Graphical User Interface Visual, user-friendly way to interact with application AWT (Abstract Window Toolkit): basic GUI Swing: platform independent, most widely used Java FX: more multimedia, still in development Focus on Swing
95 Swing Start with top-level container (JFrame, JDialog, JApplet) Every UI component must be part of a containment hierarchy Tree of components with a top-level container as its root At least one containment hierarchy will have JFrame at its root Each UI component can only be contained once
96 Event Handling Event Source: physical action (mouse click, keyboard press) Event Object: encapsulates info about the event Event Listener: instance of a class that listens for certain events (i.e. certain keyboard click) JVM notifies listener when specific event occurs JVM passes event object to listener Listener handles event in a method, the event is processed
97 Action Listener Declare an event handler class and specify that the class either implements an ActionListener interface or extends a class that implements ActionListener public class MyClass implements ActionListener { Register an instance of the event handler class as a listener on one or more components somecomponent.addactionlistener(instanceofmyclass); Include code that implements the methods in listener interface public void actionperformed(actionevent e) {...//code that reacts to the action... }
98 Exception Handling Exception: runtime program error (not syntax error) Exception is short for exceptional event Disrupts normal flow of instructions Program may or may not terminate
99 Exception Handling Handle exception in try-catch block or throw it User error, programmer error, or failure of physical resources Examples: NullPointerException, ArrayIndexOutOfBoundsException, FileNotFoundException Exception classes all subtypes of java.lang.exception class Exception class is subclass of Throwable class Error is also subclass of Throwable
100 Checked Exception Occurs at compile time, AKA compile time exceptions Can t be ignored at time of compilation Programmer needs to fix
101 Unchecked Exception Occurs at time of execution, AKA runtime exception Programming bugs, logic errors, incorrect API usage Ignored at time of compilation
102 Errors Not exceptions Problems beyond user or programmer Typically ignored in code and at compilation time, rarely can do anything about it Example: stack overflow causes error Normally programs can t recover from them
103 Exception Handling: Try, Catch, Finally Try block: first step in exception handler Encloses code that may throw exception Must be present with either catch or finally clause Catch block: must immediately follow brace of try block Can have more than one Handles exception of type specified by argument Finally: always executed after exiting try block, unless JVM exits Helps clean up resources
104 Exception Handling try { // Try to open file } catch (FileNotFoundException e) { // File wasn t found // Print error to user, exit program }
105 Throws If method doesn t handle checked exception, method must declare it with throws keyword at end of method signature throws postpones handling of a checked exception throw invokes an exception explicitly Can define your own exceptions in Java All will be child of Throwable
106 Throws public static void main(string[] args) throws FileNotFoundException { } // Try to open and use file // If file not found, exception will be thrown and code won t execute
107 Concurrency and Multithreading Concurrency supported by allowing programs to have multiple threads of execution Allow lengthy child process to run while rest of the program still runs i.e. can still use browser when downloading an app online Each thread has own call stack and program counter Threads share app-wide resources (memory, files) Run like separate programs but still tied together
108 Thread States New: thread first created, not running Runnable: starts running, acquires resources Waiting: must wait for another thread to finish Timed waiting Blocked: threat is waiting for another to release a resource Terminated: threat completes or crashes
109 Threads Priority: inherit priority from thread that spawned it High priority ones usually preempt lower ones Starve: constantly gets preempted, never finishes Deadlock: two threads hold onto resource while waiting for other to release its resource Monitor: lock held by one thread at a time, blocks other threads needing lock until this thread releases it (synchronized keyword)
110 Final Practice Problems
111 Final Practice Problem 1 Write a class called Student that extends the superclass Person Include instance variables for name, age, and height Include class variable school that is set to UCF Include two different constructors Include a getter and setter method for each instance variable
112
113 Final Practice Problem 2 Create a Car class Instance variables for speed, name, list of driver names Constructor that takes input parameter for car name Setter for speed Getter for car name
114
115 Final Practice Problem 2 Write code to perform the following actions: Create a new car object Set the speed of the car to 20 Add a new String to the list of drivers Print the name of the car you have chosen
116
117 Final Practice Problem 3: Find the Errors public class ErrorProne { private static int x = 10; private ArrayList<String> mylist; private int y = 100; } private int ErrorProne() { mylist = new ArrayList<Integer>(); } public void setx(int new) { x = new; }
118 Final Practice Problem 3: Find the Errors public class ErrorProne { private static int x = 10; private ArrayList<String> mylist; private int y = 100; } private int ErrorProne() { mylist = new ArrayList<Integer>(); } public void setx(int new) { x = new; }
119 Practice Problem Create an Alien class Make an ArrayList of Alien objects in a separate class Manipulate our ArrayList in our separate class
120
121
122 Summary Object Oriented Structure Data manipulation and arithmetic Blocks, statements, expressions Variables, methods, and classes Generics User Interfaces Exceptions Threads
123 Any Questions?
COP 3330: Object Oriented Programming
COP 3330: Object Oriented Programming SPRING 2017 STUDY UNION REVIEW SUNDAY, APRIL 23 RD CREDIT TO DR. GLINOS AND PROFESSOR WHITING FOR COURSE CONTENT Object-Oriented Structure Program Structure Main structural
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationDOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS
Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationCasting -Allows a narrowing assignment by asking the Java compiler to "trust us"
Primitives Integral types: int, short, long, char, byte Floating point types: double, float Boolean types: boolean -passed by value (copied when returned or passed as actual parameters) Arithmetic Operators:
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More information1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8
Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More information15CS45 : OBJECT ORIENTED CONCEPTS
15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?
More informationA Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1
A Third Look At Java Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Little Demo public class Test { public static void main(string[] args) { int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]);
More informationContents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix
PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring
More informationData Structure. Recitation IV
Data Structure Recitation IV Topic Java Generics Java error handling Stack Lab 2 Java Generics The following code snippet without generics requires casting: List list = new ArrayList(); list.add("hello");
More informationB2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA
B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE
More informationc) And last but not least, there are javadoc comments. See Weiss.
CSCI 151 Spring 2010 Java Bootcamp The following notes are meant to be a quick refresher on Java. It is not meant to be a means on its own to learn Java. For that you would need a lot more detail (for
More informationWA1278 Introduction to Java Using Eclipse
Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc WA1278 Introduction to Java Using Eclipse This course introduces the Java
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationboolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while
CSCI 150 Fall 2007 Java Syntax The following notes are meant to be a quick cheat sheet for Java. It is not meant to be a means on its own to learn Java or this course. For that you should look at your
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationAssoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Marenglen Biba Exception handling Exception an indication of a problem that occurs during a program s execution. The name exception implies that the problem occurs infrequently. With exception
More informationProgramming overview
Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in
More informationIndex. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107
A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationBrief Summary of Java
Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java
More informationSoftware Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)
Software Development & Education Center Java Platform, Standard Edition 7 (JSE 7) Detailed Curriculum Getting Started What Is the Java Technology? Primary Goals of the Java Technology The Java Virtual
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;
More informationJava: introduction to object-oriented features
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationReview sheet for Final Exam (List of objectives for this course)
Review sheet for Final Exam (List of objectives for this course) Please be sure to see other review sheets for this semester Please be sure to review tests from this semester Week 1 Introduction Chapter
More informationThe Sun s Java Certification and its Possible Role in the Joint Teaching Material
The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationSyllabus & Curriculum for Certificate Course in Java. CALL: , for Queries
1 CONTENTS 1. Introduction to Java 2. Holding Data 3. Controllin g the f l o w 4. Object Oriented Programming Concepts 5. Inheritance & Packaging 6. Handling Error/Exceptions 7. Handling Strings 8. Threads
More informationBasic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems
Basics of OO Programming with Java/C# Basic Principles of OO Abstraction Encapsulation Modularity Breaking up something into smaller, more manageable pieces Hierarchy Refining through levels of abstraction
More informationMultitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit
Threads Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multitasking Thread-based multitasking Multitasking
More informationBIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic
BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines
More information5/23/2015. Core Java Syllabus. VikRam ShaRma
5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5
More informationLanguage Features. 1. The primitive types int, double, and boolean are part of the AP
Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are
More informationJava Primer. CITS2200 Data Structures and Algorithms. Topic 2
CITS2200 Data Structures and Algorithms Topic 2 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies Interfaces Exceptions Reading: Lambert and Osborne,
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationJava+- Language Reference Manual
Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect
More informationObject-Oriented Programming (OOP) Fundamental Principles of OOP
Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is
More informationJava for Programmers Course (equivalent to SL 275) 36 Contact Hours
Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Course Overview This course teaches programmers the skills necessary to create Java programming system applications and satisfies the
More informationModern Programming Languages. Lecture Java Programming Language. An Introduction
Modern Programming Languages Lecture 27-30 Java Programming Language An Introduction 107 Java was developed at Sun in the early 1990s and is based on C++. It looks very similar to C++ but it is significantly
More informationSTRUCTURING OF PROGRAM
Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the
More informationCH. 2 OBJECT-ORIENTED PROGRAMMING
CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED
More informationCSC207H: Software Design. Java + OOP. CSC207 Winter 2018
Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside
More informationCONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17
List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationJava Overview An introduction to the Java Programming Language
Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationObject oriented programming. Instructor: Masoud Asghari Web page: Ch: 3
Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning
More informationJava for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.
Java for Non Majors Final Study Guide April 26, 2017 The test consists of 1. Multiple choice questions 2. Given code, find the output 3. Code writing questions 4. Code debugging question 5. Short answer
More informationCosc 241 Programming and Problem Solving Lecture 9 (26/3/18) Collections and ADTs
1 Cosc 241 Programming and Problem Solving Lecture 9 (26/3/18) Collections and ADTs Michael Albert michael.albert@cs.otago.ac.nz Keywords: abstract data type, collection, generic class type, stack 2 Collections
More informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 60 0 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK III SEMESTER CS89- Object Oriented Programming Regulation 07 Academic Year 08 9 Prepared
More informationObject-Oriented Programming
Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object
More informationJava Fundamentals (II)
Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class
More informationDay 4. COMP1006/1406 Summer M. Jason Hinek Carleton University
Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information
More informationCO Java SE 8: Fundamentals
CO-83527 Java SE 8: Fundamentals Summary Duration 5 Days Audience Application Developer, Developer, Project Manager, Systems Administrator, Technical Administrator, Technical Consultant and Web Administrator
More informationIntroduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview
Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple
More informationData Structures (list, dictionary, tuples, sets, strings)
Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables
More informationCore Java - SCJP. Q2Technologies, Rajajinagar. Course content
Core Java - SCJP Course content NOTE: For exam objectives refer to the SCJP 1.6 objectives. 1. Declarations and Access Control Java Refresher Identifiers & JavaBeans Legal Identifiers. Sun's Java Code
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba Laboratory Session: Exercises on classes Analogy to help you understand classes and their contents. Suppose you want to drive a car and make it go faster by pressing down
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationCourse Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline ::
Module Title Duration : Intro to JAVA SE7 and Programming using JAVA SE7 : 9 days Course Description The Java SE 7 Fundamentals course was designed to enable students with little or no programming experience
More informationA Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.
A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. 9 Classes and Objects p. 11 Creating Objects p. 12 Static or
More informationLesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014
Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class
More informationJava Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing
Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationCS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1
P a g e 1 CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1 Q1 Describe some Characteristics/Advantages of Java Language? (P#12, 13, 14) 1. Java
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and
More informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationBBM 102 Introduction to Programming II Spring Exceptions
BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom
More informationCS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?
CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 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
More informationInheritance (continued) Inheritance
Objectives Chapter 11 Inheritance and Polymorphism Learn about inheritance Learn about subclasses and superclasses Explore how to override the methods of a superclass Examine how constructors of superclasses
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationObject Oriented Programming with Java
Object Oriented Programming with Java What is Object Oriented Programming? Object Oriented Programming consists of creating outline structures that are easily reused over and over again. There are four
More informationIntroduction to Java Written by John Bell for CS 342, Spring 2018
Introduction to Java Written by John Bell for CS 342, Spring 2018 Based on chapters 1 to 6 of Learning Java by Patrick Niemeyer and Daniel Leuck, with additional material from other sources. History I
More informationExceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages
References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/
More informationReviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Things to Review Review the Class Slides: Key Things to Take Away Do you understand
More informationLecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:
Lecture 28 Exceptions and Inner Classes Goals We are going to talk in more detail about two advanced Java features: Exceptions supply Java s error handling mechanism. Inner classes ease the overhead of
More informationChapter 4. Defining Classes I
Chapter 4 Defining Classes I Introduction Classes are the most important language feature that make object oriented programming (OOP) possible Programming in Java consists of dfii defining a number of
More informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationObject Oriented Programming with Java. Unit-1
CEB430 Object Oriented Programming with Java Unit-1 PART A 1. Define Object Oriented Programming. 2. Define Objects. 3. What are the features of Object oriented programming. 4. Define Encapsulation and
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 02: Using Objects MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Using Objects 2 Introduction to Object Oriented Programming Paradigm Objects and References Memory Management
More informationDo not turn to the next page until the start of the exam.
Principles of Java Language with Applications, PIC20a E. Ryu Winter 2017 Final Exam Monday, March 20, 2017 3 hours, 8 questions, 100 points, 11 pages While we don t expect you will need more space than
More informationCONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13
CONTENTS Chapter 1 Getting Started with Java SE 6 1 Introduction of Java SE 6... 3 Desktop Improvements... 3 Core Improvements... 4 Getting and Installing Java... 5 A Simple Java Program... 10 Compiling
More informationChapter 5 Object-Oriented Programming
Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares
More informationInheritance and Polymorphism
Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationLecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166
Lecture 20 Java Exceptional Event Handling Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics What is an Exception? Exception Handler Catch or Specify Requirement Three Kinds of Exceptions
More informationSimple Java Reference
Simple Java Reference This document provides a reference to all the Java syntax used in the Computational Methods course. 1 Compiling and running... 2 2 The main() method... 3 3 Primitive variable types...
More information