Programming Language Concepts (CIS 635)

Slides:



Advertisements
Similar presentations
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Advertisements

METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Object Oriented Programming in JAVA
Lecture 2: Object Oriented Programming I
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
ITEC200 – Week03 Inheritance and Class Hierarchies.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
INTRODUCTION TO JAVA CHAPTER 1 1. WHAT IS JAVA ? Java is a programming language and computing platform first released by Sun Microsystems in The.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
POS 406 Java Technology And Beginning Java Code
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
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.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CS 106 Introduction to Computer Science I 04 / 23 / 2010 Instructor: Michael Eckmann.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
By Mr. Muhammad Pervez Akhtar
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
OOP Basics Classes & Methods (c) IDMS/SQL News
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
April 13, 1998CS102-02Lecture 3-1 Data Types in Java CS Lecture 3-1 Java’s Central Casting.
Design issues for Object-Oriented Languages
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Information and Computer Sciences University of Hawaii, Manoa
Modern Programming Tools And Techniques-I
JAVA MULTIPLE CHOICE QUESTION.
Inheritance and Polymorphism
Introduction to.
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Internet and Java Foundations, Programming and Practice
Types of Programming Languages
Compiler Design 18. Object Oriented Semantic Analysis (Symbol Tables, Type Checking) Kanat Bolazar March 30, 2010.
Java Programming Language
An Introduction to Java – Part I, language basics
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Defining Classes and Methods
Introduction to java Part I By Shenglan Zhang.
Corresponds with Chapter 5
Presentation transcript:

Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT, www.cs.njit.edu/~elsa/635

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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

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

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

Getting Java For MS Windows: Installation instructions found http://www.cis.njit.edu/~elsa/635/j2sdk-1_3_0_02-win.exe Installation instructions found http://java.sun.com/j2se/1.3/install-windows.html Copyright 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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

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

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter

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 2002 Elsa L. Gunter