Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Language Concepts (CIS 635)

Similar presentations


Presentation on theme: "Programming Language Concepts (CIS 635)"— Presentation transcript:

1 Programming Language Concepts (CIS 635)
Elsa L Gunter 4303 GITC NJIT,

2 Object-Oriented Programming
Class is a form of abstract type Instances of class called objects Operators of class called methods Applying a method to an object in the class called message passing Messages take object as implicit argument Copyright Elsa L. Gunter

3 Variables and Methods Classes have two kinds of methods and two kinds of variables: Instance methods and instance variables Class methods and class variable Copyright Elsa L. Gunter

4 Instance Variables and Methods
Instance variables hold state of single object Different objects have different (copies of) instance variables Instance methods: Instance methods act on a single object, usually acting on instance variables Copyright Elsa L. Gunter

5 Class Variables and Methods
Class variables hold state that is shared in common among all objects of class Class methods act on attributes of the whole class through class variables Class methods can’t access instance variables Copyright Elsa L. Gunter

6 Inheritance Inheritance allows all variables and methods exported from parent class to be part of a derived class or subclass Copyright Elsa L. Gunter

7 Inheritance Export information: public: everybody sees
private: only seen inside class protected: exported only to subclasses Copyright Elsa L. Gunter

8 Inheritance If a method is added to a subclass with the same name (and usually signature) as in the parent class the new version overrides inherited version in subclass Copyright Elsa L. Gunter

9 Inheritance Polymorphism and Dynamic Binding
Method of superclass may be overridden in subclass Dynamic binding: when a method of superclass is applied to object of subclass, methods of subclass are used in computing result, instead of methods of superclass Java has dynamic binding by default C++ method must be marked as virtual for dynamic binding to be used with it Copyright Elsa L. Gunter

10 Virtual (or Abstract) Methods
Virtual method: has declaration but no function body Subclass must override all virtual methods with methods with fully concrete bodies to be instantiated Copyright Elsa L. Gunter

11 Single Versus Multiple Inheritance
Single inheritance: Class may only be a subclass of one parent Multiple inheritance: Class may be immediate subclass of two or more parents Problem with multiple inheritance: class A:B,C {…} What if we have both B.m and C.m? Which method is A.m? Answer in most languages: B.m Copyright Elsa L. Gunter

12 Introduction to Java Recently introduced (1995)
Modern and sound design (Gosling) Very rapid growth (and heavy hype) Killer application: web-based computing (applets) Copyright Elsa L. Gunter

13 Introduction to Java Originally designed for smart appliances such as interactive TVs and “set-top boxes” Priorities: small, secures, portable Makes it good for running on the web Copyright Elsa L. Gunter

14 Platform Independence
Machine-independent semantics and security model Key concept: Java Virtual Machine Each platform implements Java Virtual Machine Java compiles to Java byte code that runs on (is interpreted by) Java Virtual Machine Copyright Elsa L. Gunter

15 Getting Java For MS Windows: Installation instructions found
Installation instructions found Copyright Elsa L. Gunter

16 Getting Started With Java
Will assume you have adjusted your PATH variable as described in instructions Start up editor (eg Notepad) Create file called “Hello.java” Use quotes so that editor doesn’t add its own extension (like .txt) Copyright Elsa L. Gunter

17 Getting Started With Java
Put code on next slide in file and save In MS_DOS window in same directory, run javac Hello.java to compile code In MS_DOS window in same directory, run java Hello Copyright Elsa L. Gunter

18 Sample Java Code (“Hello.java”)
class Hello { public static void main (String args[]) { System.out.println ("So at last we get to Java!\n"); } Copyright Elsa L. Gunter

19 Sample Java Code (“Hello.java”)
To execute: C:\My Documents\635\java>javac Hello.java C:\My Documents\635\java>java Hello So at last we get to Java! Copyright Elsa L. Gunter

20 Terminolgoy Class: Hello Class method: main
Only class method of class Hello Copyright Elsa L. Gunter

21 Terminolgoy Object: System Method of System: out Object: System.out
Method of System.out: println Object: “So at last we get to Java!“ of class String of immutable strings Copyright Elsa L. Gunter

22 Java Declarations Declarations state type and other attributes of identifier private int i, j; Declaration has three parts: Modifiers: private Type: int List of identifiers: i, j Copyright Elsa L. Gunter

23 Java Method Declaration
public static void main (String args []) public and static describe scope and sharing characteristics of method main Copyright Elsa L. Gunter

24 Java Method Declaration
Input of main is an array of strings (objects of class String) Return type of main is void, i.e. no return value Formal input parameter is args (not actually ever used here) Copyright Elsa L. Gunter

25 Initialization If an identifier is declared without being initialized, Java used default initialization To initialize identifier, follow its declaration by = and an expression: int lo = 1; int hi = 1; Copyright Elsa L. Gunter

26 Java Built-in Data Types
Size(bits) Default initial value boolean 8 false byte char 16 ‘x0’ short Copyright Elsa L. Gunter

27 Java Built-in Data Types
Size(bits) Default initial value int 32 long 64 float 0.0F double 0.0D Copyright Elsa L. Gunter

28 boolean and char Literals
true and false are not (andcannot be cast into) integers Character literals are enclosed in single quotes: ‘a’ Uses same convention for special characters as C: \n for newline, \\ for backslash, \’ for single quote Copyright Elsa L. Gunter

29 Assignment and Equality
Assignment operator: = Assigns value to identifier Value and type of assignment operation is resulting value and type of left-hand identifier int nA, nB; nB = (nA = 4) / 2 Do not confuse with binary boolean equality operator == Copyright Elsa L. Gunter

30 Boolean Operators Comparison operators >, <, >=, <=, ==, != return boolean values, not integers Logical boolean operations: And: E1 & E2 ( && for short circuit) Or: E1 | E2 ( || for short circuit) Exclusive Or: E1 ^ E2 Copyright Elsa L. Gunter


Download ppt "Programming Language Concepts (CIS 635)"

Similar presentations


Ads by Google