How is Java different from other languages Less than you think: –Java is an imperative language (like C++, Ada, C, Pascal) –Java is interpreted (like LISP,

Slides:



Advertisements
Similar presentations
pa 1 Porting BETA to ROTOR ROTOR Projects Presentation Day, June by Peter Andersen.
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.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
Introduction to Java Kiyeol Ryu Java Programming Language.
JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Reasons to study concepts of PL
Java: the core language What it looks like: class OnceAgain { public static void main (String[] args){ int X = 1234; System.out.println (“we’ve seen this.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
1 Java Object oriented features Object oriented features Polymorphic type Polymorphic type Inheritance Inheritance Information Hiding Information Hiding.
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
How is Java different from other languages Less than you think: –Java is an imperative language (like C++, Ada, C, Pascal) –Java is interpreted (like LISP,
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
OOP Languages: Java vs C++
Comparison of OO Programming Languages © Jason Voegele, 2003.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Advanced Java Programming Lecture 5 Reflection dr hab. Szymon Grabowski dr inż. Wojciech Bieniecki
CISC6795: Spring Object-Oriented Programming: Polymorphism.
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Implement High-level Program Language on JVM CSCE 531 ZHONGHAO LIU ZHONGHAO LIU XIAO LIN.
Java Language and SW Dev’t
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Core Java: Essential Features 08/05/2015 Kien Tran.
Introduction to Object Oriented Programming CMSC 331.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
1 Interfaces Reading for today: Sec and corresponding ProgramLive material. Also, compare with previous discussions of abstract classes (Sec. 4.7).
INTERFACES More OO Concepts. Interface Topics Using an interface Interface details –syntax –restrictions Create your own interface Remember polymorphism.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
Chapter 2: A Brief History Object- Oriented Programming Presentation slides for Object-Oriented Programming by Yahya Garout KFUPM Information & Computer.
Computer Programming 2 Why do we study Java….. Java is Simple It has none of the following: operator overloading, header files, pre- processor, pointer.
Types in programming languages1 What are types, and why do we need them?
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
How is Java different from other languages Less than you think: ◦ Java is an imperative language (like C++, Ada, C, Pascal) ◦ Java is interpreted (like.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
CSCE 314 Programming Languages Reflection Dr. Hyunyoung Lee 1.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
JAVA TRAINING IN NOIDA. JAVA Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented and specifically.
5th MaCS Debrecen On the Turing-Completeness of Generative Metaprograms Zoltán Porkoláb, István Zólyomi Dept. of Programming.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Final exam: Period B: Thursday, 13 May, 9:00-11:30AM, Barton East
Java Programming Language
EE 422C Java Reflection re·flec·tion rəˈflekSH(ə)n/ noun
Java Programming Language
CSCE 314: Programming Languages Dr. Dylan Shell
Presentation transcript:

How is Java different from other languages Less than you think: –Java is an imperative language (like C++, Ada, C, Pascal) –Java is interpreted (like LISP, APL) –Java is garbage-collected (like LISP, Eiffel, Modula-3) –Java can be compiled (like LISP) –Java is object-oriented (like C++, Ada, Eiffel) A succesful hybrid for a specific-application domain A reasonable general-purpose language for non-real- time applications Work in progress: language evolving rapidly

Original design goals (white paper 1993) Simple Object-oriented (inheritance, polymorphism) Distributed Interpreted multithreaded Robust Secure Architecture-neutral a language with threads, objects, exceptions and garbage-collection can’t really be simple!

Portability Critical concern: write once-run everywhere Consequences: –Portable interpreter –definition through virtual machine: the JVM –run-time representation has high-level semantics –supports dynamic loading –(+) high-level representation can be queried at run-time to provide reflection –(-) Dynamic features make it hard to fully compile, safety requires numerous run-time checks

Contrast with conventional systems languages (C, C++, Ada) Conventional languages are fully compiled: –run-time structure is machine language –minimal run-time type information –language provides low-level tools for accessing storage –safety requires fewer run-time checks because compiler –(least for Ada and somewhat for C++) can verify correctness statically. –Languages require static binding, run-time image cannot be easily modified –Different compilers may create portability problems

Serious omissions No parameterized classes (C++ templates, Ada generics) Can simulate generic programming with untyped style: casting Object down into specific class. –Forces code duplication, or run-time conversions No operator overloading (syntactic annoyance) No enumerations (using final constants is clumsy)

A new construct: interfaces Allow otherwise unrelated classes to satisfy a given requirement Orthogonal to inheritance –inheritance: an A is-a B (has the attributes of a B, and possibly others) –interface: an A can-do X (and other unrelated actions) –better model for multiple inheritance More costly at run-time (minor consideration)

Interface Comparable public interface Comparable { public int CompareTo (Object x) throws ClassCastException; // returns -1 if this < x, // 0 if this = x, // 1 if this > x }; // Implementation has to cast x to the proper class. // Any class that may appear in a container should implement Comparable

Threads and their interface class Doodler extends Thread { // override the basic method of a thread public void run( ) {... // scribble something } } … Doodler gary = new Doodler ( ); gary.start( ); // calls the run method

The runnable interface allows any object to have dynamic behavior class Simple_Gizmo { …} class Active_Gizmo extends Simple_Gizmo implements Runnable { public void run ( ) {…} } // a thread can be constructed from anything that runs: Thread thing1 = new Thread (new Active_Gizmo ( )); Thread thing2 = new Thread (new Active_Gizmo ( )); thing1.start( ); thing2.start ( );

Interfaces and event-driven programming A high-level model of event-handling: –graphic objects generate events mouse click, menu selection, window close... –an object can be designated as a handler a listener, in Java terminology –an event can be broadcast to several handlers several listeners can be attached to a source of events –a handler must implement an interface actionPerformed, keyPressed, mouseExited..

Events and listeners class Calm_Down extends Jframe { private Jbutton help := new Jbutton (“HELP!!!”); // indicate that the current frame handles button clicks help.addActionListener (this); // if the button is clicked the frame executes the following: public void actionPerformed (ActionEvent e) { if (e.getSource () == help) { System.out.println (“can’t be that bad. What’s the problem?”); }

Introspection, reflection, and typeless programming public void DoSomething (Object thing) { // what can be do with a generic object? if (thing instanceof gizmo) { // we know the methods in class Gizmo …. Instanceof requires an accessible run-time descriptor in the object. Reflection is a general programming model that relies on run- time representations of aspects of the computation that are usually not available to the programmer. More common in Smalltalk and LISP.

Reflection and metaprogramming Given an object at run-time, it is possible to obtain: –its class –its fields (data members) as strings –the classes of its fields –the methods of its class, as strings –the types of the methods It is then possible to construct calls to these methods This is possible because the JVM provides a high- level representation of a class, with embedded strings that allow almost complete disassembly.

Reflection classes java.lang.Class –Class.getMethods () returns array of method objects –Class.getConstructor (Class[] parameterTypes) returns the constructor with those parameters java.lang.reflect.Array –Array.NewInstance (Class componentType, int length) java.lang.reflect.Field java.lang.reflect.Method All of the above require the existence of run-time objects that describe methods and classes

Reflection and beans The beans technology requires run-time examination of foreign objects, in order to build dynamically a usable interface for them. Class Introspector builds a method dictionary based on simple naming conventions: public boolean isCoffeeBean ( ); // is... predicate public int getRoast ( ); // get... retrieval public void setRoast (int darkness) ; // set… assignment