CSC1351 9/6/2011 Where are we?. Polymorphism // Use dynamic lookup to allow different data types to be manipulated // with a uniform interface. public.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Written by: Dr. JJ Shepherd
Lecture 2: Object Oriented Programming I
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Chapter 3 - Java Programming With Supplied Classes1 Chapter 3 Java Programming With Supplied Classes.
Java Syntax Primitive data types Operators Control statements.
Object Oriented Concepts in Java Objects Inheritance Encapsulation Polymorphism.
Inheritance and interfaces A class C1 is derived from class C2, then C1 is called subclass, and C2 is called superclass Superclass-parent, base class Subclass.
LESSON 4 - Variables JAVA PROGRAMMING. Variables Variable is a named storage location that stores data and the value of the data may change while the.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
JAVA PROGRAMMING PART II.
Chapter 11 Abstract Classes and Interfaces 1. Abstract method New modifier for class and method: abstract An abstract method has no body Compare: abstract.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Object Oriented Programming: Java Edition By: Samuel Robinson.
C Tokens Identifiers Keywords Constants Operators Special symbols.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Primitive Variables.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Announcements Final Exam:TBD. public static void main(String [] args) { final int ASIZE = 5; int [] intArray= new int[ASIZE]; for(int i = 0; i < ASIZE;
Copyright Curt Hill Variables What are they? Why do we need them?
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Abstract Classes and Interfaces Chapter 9 CSCI 1302.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
 byte  short  int  long  float  double  boolean  char.
Basic Syntax อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 2.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Object Oriented Programming Lecture 2: BallWorld.
Java: Base Types All information has a type or class designation
CSC1351 Class 6 Classes & Inheritance.
Objects as a programming concept
JAVA MULTIPLE CHOICE QUESTION.
Java: Base Types All information has a type or class designation
University of Central Florida COP 3330 Object Oriented Programming
Starting JavaProgramming
Unit-2 Objects and Classes
null, true, and false are also reserved.
Introduction to Java Programming
Wrapper Classes The java.lang package contains wrapper classes that correspond to each primitive type: Primitive Type Wrapper Class byte Byte short Short.
Interfaces.
Chapter 2: Java Fundamentals
JavaScript Reserved Words
Programs and Classes A program is made up from classes
Tonga Institute of Higher Education
Module 2 - Part 1 Variables, Assignment, and Data Types
Object Oriented Programming in java
Chapter 8 Class Inheritance and Interfaces
Chap 2. Identifiers, Keywords, and Types
Agenda Types and identifiers Practice Assignment Keywords in Java
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Presentation transcript:

CSC1351 9/6/2011 Where are we?

Polymorphism // Use dynamic lookup to allow different data types to be manipulated // with a uniform interface. public class FlameThrower implements Weapon { public void inflict(Target t) { t.fireDamage(6); } public class Sword implements Weapon { public void inflict(Target t) { t.cuttingDamage(3); }... Weapon w = new Sword(); w.inflict(target); // Dynamic lookup of Sword's inflict method w = new FlameThrower(); w.inflict(target); // Method comes from object type, not variable type

Vocabulary super class sub class accessor mutator polymorphism callback observer pattern side effect constant object

Types Eight primitive types int - signed, 4 bytes double - 8 bytes float - 4 bytes short - signed, 2 bytes long - signed 8 bytes char - unsigned, 2 bytes byte - signed, 1 byte boolean - two states

Primitive vs. Object Primitives passed by value automatic variables are allocated off the stack wrappers for all primitives are in java.lang wrappers provide parse methods Objects passed by reference automatic variables are allocated with new and come from the heap

Keywords - Know what they mean interface class abstract public private package import static final

Types Objects All classes extend class Object Objects all have public String toString() String/StringBuffer public char charAt(int pos) int length() String substring(int start,int end) int indexOf(char)

Types Arrays allocated with new final int field named length Enums A special type of object to represent a finite set of values

Conventions All class names are capitalized First letters of words are capitalized, e.g. GiantRat, BankAccount, etc. All method names start with lower case constants (final static) are in all caps and use the underscore to separate words, e.g. MIN_VALUE

Inheritance You can only extend one class Abstract classes have some undefined methods Interfaces have only undefined methods, or constants

Inner Classes Static Inner Classes – declared inside another class – does not have access to fields of enclosing class Non-static Inner Classes – declared inside another class – has access to fields of enclosing class Anonymous Inner Classes – a non-static inner class without a name