Object-Oriented Programming Chapter Two. Java Buzz Words Simple Architecture neutral Object oriented Portable Distributed High performance Interpreted.

Slides:



Advertisements
Similar presentations
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Advertisements

The Web Warrior Guide to Web Design Technologies
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Object Orientated Programming
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
What is an object? Your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior;
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
Introduction to Java Programming
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
Created by Ron Beglieter (based on the Java Tutorial) 1 What is Java? Java technology is both a programming language and a platform; Programming Language.
Object-oriented Programming Concepts
Chapter 13: Object-Oriented Programming
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
Getting Started with Java
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
1 Pertemuan 6 Object Oriented Programming Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
TCU CoSc Introduction to Programming (with Java) Getting to Know Java.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Object-Oriented Programming Concepts
Chapter 4 Objects and Classes.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
About the Java  Java technology is both a programming language and a platform –The Java Programming Language A high-level language that can be characterized.
JSP Java Server Pages Softsmith Infotech.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
1.  At the end of this slide, student can:  Explore tools, features, properties and interface of the Textpad.  Creating a new project.  Open and run.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
POS 406 Java Technology And Beginning Java Code
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
OOP Basics Classes & Methods (c) IDMS/SQL News
ITP 109 Week 2 Trina Gregory Introduction to Java.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
Object Oriented Programming in Java Habib Rostami Lecture 2.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
JAVA By Waqas.
Text by: Lambert and Osborne
Chapter 3: Using Methods, Classes, and Objects
Java Programming: From Problem Analysis to Program Design,
Chapter 1 Introduction to Computers, Programs, and Java
Java Applets.
Defining Classes and Methods
Introducing Java.
Computer Programming-1 CSC 111
Presentation transcript:

Object-Oriented Programming Chapter Two

Java Buzz Words Simple Architecture neutral Object oriented Portable Distributed High performance Interpreted Multithreaded Robust Dynamic Secure

Design Goals Simplicity –Java’s overriding design goals. Removal of many features from C++. To illustrate the simplicity – use classic HelloWord app.

HelloWorld class HelloWorld { static public void main(String args[]) { System.out.println("Hello world!"); } } //This example declares a class name /**HelloWorld.*/ /*more comments*/

What is a Class? A class--the basic building block of an object- oriented language such as Java. A template that describes the data and behavior associated with instances of that class. When you instantiate a class you create an object that looks and feels like other instances of the same class. The data associated with a class or object is stored in variables the behavior associated with a class or object is implemented with methods.

Definitions Methods are similar to the functions or procedures in procedural languages such as C. Class – a collection of data and methods to operate on the data. Instantiation - producing a particular object from its class template. This involves allocation of a structure with the types specified by the template, and initialization of instance variables with either default values or those provided by the class's constructor function.

Definitions Continued Object – an instance of a class – a class models a group of things, an object models a particular member of that group. Instance – an object – when a class is instantiated to produce an object, we say the object is an instance of the class. Variable – data items in a class – fields. Encapsulate – technique that makes an object’s data private or protected – allow programmers to access and manipulate – only thru method calls – data hiding.

Back to Code class HelloWorld { static public void main(String args[]) { System.out.println("Hello world!"); } } //This example declares a class name /**HelloWorld.*/ /*more comments*/

HelloWorld Class defined as HelloWorld Method is Main( ) Pre-defined method – println() – for text output – this code is CLP GUI – by adding other objects into our code

GUI New code: JFrame frame = new Jframe( “Hello World” ); frame.setSize( 300, 300); frame.setVisible( true ); Use this to replace println() New object – JFrame title Hello World Configure size – method Make visible - method

More GUI Now put a message in the window – import javax.swing.*; class HelloWorld { static public void main( String args[]) { JFrame frame = new Jframe(“Hello World”); JLabel label = new JLabel (“Hello World”, JLabel.CENTER); frame.getContentPanel( ).add( label ); frame.setSize( 300, 300 ); frame.setVisible ( true ); }

A Class RW Example Julia Child's recipe for rack of lamb is a real-world example of a class. Her rendition of the rack of lamb is one instance of the recipe, and mine is quite another. (While both racks of lamb may "look and feel" the same, I imagine that they "smell and taste" different.)

Or Another Class Exp. A more traditional example from the world of programming is a class that represents a rectangle. The class would contain variables for the origin of the rectangle, its width, and its height. The class might also contain a method that calculates the area of the rectangle. An instance of the rectangle class would contain the information for a specific rectangle, such as the dimensions of the floor of an office, or the dimensions of a page.

Arguments to Main public static void main(String[ ] args) -the main method accepts a single argument: an array of elements of type String -mechanism through which the runtime system passes information to your application. -Each String in the array is called a command-line argument

Command Line Arguments CLA’s let users affect the operation of the application without recompiling it. An example, a sorting program might allow the user to specify that the data be sorted in descending order with this command-line argument: -descending Our program ignores CLA’s at this point.

Back to our GUI: import javax.swing.*; class HelloWorld { static public void main( String args[]) { JFrame frame = new Jframe(“Hello World”); JLabel label = new JLabel (“Hello World”, JLabel.CENTER); frame.getContentPanel( ).add( label ); frame.setSize( 300, 300 ); frame.setVisible ( true ); }

What is an Object A pen, a desk, a TV, a computer. Real world objects have state & behavior. Pen -> red, thin -> lay on desk, roll Software object maintains its state in one or more variables – and has behavior with methods. Object is a software bundle of variables and related methods.

More Objects Everything that the software object knows (state) and can do (behavior) is expressed by the variables and the methods within that object. A software object that modeled a real-world bicycle would have variables that indicated the bicycle's current state: its speed is 10 mph, its pedal cadence is 90 rpm, and its current gear is the 5th gear. These variables are formally known as instance variables because they contain the state for a particular bicycle object, and in object-oriented terminology, a particular object is called an instance.

Objects cont. In addition to its variables, the software bicycle would also have methods to brake, change the pedal cadence, and change gears. These are instance methods because they inspect and change the state of a bicycle instance.

Class Loaders Second layer of security. Responsible for bringing the bytecode for one or more classes into the interpreter.

Security Managers Responsible for application-level security. An object – can be installed by an app to restrict access to system resources. Consulted every time the app tries to access items – filesystem, network ports – etc. Integrity is based on the protection afforded by the lower-levels.

Application & User-level Security Web provides a insecure environment. Java needs to be able to run some components even if may cause problems. Therefore creates the ability to ask user for okay requests. Security manager offers another option – to flag windows created by untrusted app – with special borders. Stop impersonations.

Java & the Web Web browser that uses the Java runtime system -> java applets as executable content inside docs. Enormous possibilities for Java use – with the app security manager. Spreadsheet apps can become fully- functional after its embedded into a web doc.

Applets Means small, subordinate or embedded app. To web browser an applet is just another object to display – its embedded into an HTML page with a special tag. Java applet is a compiled Java program, composed of classes.

A Message A single object alone is generally not very useful. an object usually appears as a component of a larger program or application that contains many other objects. Software objects interact and communicate with each other by sending messages to each other.

More about Messages When object A wants object B to perform one of B's methods, object A sends a message to object B. Sometimes, the receiving object needs more information so that it knows exactly what to do. Our example, when you want to change gears on your bicycle, you have to indicate which gear you want. This information is passed along with the message as parameters.

Visualize The next figure shows the three components that comprise a message: 1.The object to which the message is addressed ( YourBicycle ) 2.The name of the method to perform ( changeGears ) 3.Any parameters needed by the method ( lowerGear )

Message Benefits Messages provide two important benefits. –An object's behavior is expressed through its methods, so (aside from direct variable access) message passing supports all possible interactions between objects. –Objects don't need to be in the same process or even on the same machine to send and receive messages back and forth to each other.