Object Orientated Programming

Slides:



Advertisements
Similar presentations
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Advertisements

Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Visual and Internet Programming using JAVA
Java: History and Introduction (Lecture # 1). History… Java – Based on C and C++ – Developed in 1991 for intelligent consumer electronic devices – Green.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
Introduction to Java Programming
 2002 Prentice Hall. All rights reserved. Week 1 - Introduction to Object- Oriented Programming Outline 1.1 Machine Languages, Assembly Languages and.
Introduction to Java.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
Java PAL.  Contains the development kit and the runtime environment ( aka the Java Virtual Machine )  Download Link:
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 1 – Introduction to Computers, the Internet, and the Web Outline 1.1 Introduction 1.2 What Is a.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
1 1 1 Introduction to Java. 2 History of Java Java – Originally for intelligent consumer-electronic devices – Then used for creating Web pages with dynamic.
CSC 142 A 1 CSC 142 Introduction to Java [Reading: chapter 0]
+ Java vs. Javascript Jessi Style. + Java Compiled Can stand on its own Written once, run anywhere Two-stage debugging Java is an Object Oriented Programming.
CSCI 224 Introduction to Java Programming. Course Objectives  Learn the Java programming language: Syntax, Idioms Patterns, Styles  Become comfortable.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction & The Java Virtual Machine Small Java Chapter 1 1.
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Training Course Dr. H.E. Dunsmore Purdue University Java – How to Program, Deitel (5 th Edition)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
 2005 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and the World Wide Web.
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.
1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project.
1 Chapter 1 Introduction to Java. 2 History of Java Java Originally for _________________________ devices Then used for creating Web pages with __________________________.
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-
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
POS 406 Java Technology And Beginning Java Code
Java Programming, Second Edition Chapter One Creating Your First Java Program.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
CT1513 Introduction To java © A.AlOsaimi.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Java – in context Main Features From Sun Microsystems ‘White Paper’
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Overview of Programming.
1 Introduction Read D&D Sec 1.8; Sec 1.13 THE Java tutorial -
ITP 109 Week 2 Trina Gregory Introduction to Java.
1 Chapter 1 Java –Originally for intelligent consumer-electronic devices –Then used for creating Web pages with dynamic content –Now also used for: Develop.
1 1 1 Introduction to Java. 2 History of Java Java – Originally for intelligent consumer-electronic devices – Then used for creating Web pages with dynamic.
Introduction to JAVA Programming
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Applications Active Web Documents Active Web Documents.
Object Oriented Programming in
Introduction to Computers, the Internet and the World Wide Web
Chapter 1 – Introduction to Computers, the Internet, and the Web
Chapter 1 Introduction to Computers, Programs, and Java
Lecture 1: Introduction to JAVA
Java programming lecture one
Introduction Enosis Learning.
Introduction to Java Dept. Business Computing University of Winnipeg
Introduction Enosis Learning.
Introduction CSC 111.
(Computer fundamental Lab)
Introducing Java.
Chap 1. Getting Started Objectives
Computer Programming-1 CSC 111
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

Object Orientated Programming An Introduction to Java

For the most accurate and up-to-date tutorials, please access the latest version from Sun's official website for the Java SE Tutorials (Last Updated 9/23/2009), which can be found at: http://java.sun.com/docs/books/tutorial.

Features of OOP Classes Objects Instantiation Inheritance Membership Functions

More OOP Features Data Encapsulation Polymorphism Operator Overloading Message Passing Software Re-Use

History of Java Java Java, first released by Sun Microsystems in 1994 Originally for intelligent consumer-electronic devices Then used for creating Web pages with dynamic content Now also used for: Develop large-scale enterprise applications Enhance WWW server functionality Provide applications for consumer devices (cell phones, etc.)

The Emergence of Java In the past decade Java has emerged in wide use partially because of its similarity to C and to C++ Perhaps more important is its implementation using a virtual machine that is intended to run code unchanged on many different platforms. This last feature has made it very attractive to larger development shops with heterogeneous environments.

Key Benefits of Java Java is “write once, run anywhere” architecture neutral portable across different platforms Due to Java Virtual Machine (JVM) Security features highly configurable security levels prevent any piece of Java code doing harm to the host system Network-centric platform easy to work with resources across a network and to create network based applications Object Oriented an interacting collection of independent software components dynamic extensible programs

Key Benefits of Java Internationalisation uses 16 bit Unicode characters that represents the phonetic and ideographic character sets of the entire world Performance although an interpreted language Java programs run almost as fast as native C, C++ programs Simple and easy to develop powerful & well designed set of APIs

Java Class Libraries Classes Include methods that perform tasks Return information after task completion Used to build Java programs Java contains class libraries Known as Java APIs (Application Programming Interfaces)

Basics of a Typical Java Environment Java programs normally undergo five phases Edit Programmer writes program (and stores program on disk) Compile Compiler creates bytecodes from program Load Class loader stores bytecodes in memory Verify Verifier ensures bytecodes do not violate security requirements Execute Interpreter translates bytecodes into machine language

Typical Java environment. Primary Memory . Disk Editor Compiler Class Loader Program is created in an editor and stored on disk in a file ending with .java. Compiler creates bytecodes and stores them on disk in a file ending with .class. Class loader reads .class files containing bytecodes from disk and puts those bytecodes in memory. Phase 1 Phase 2 Phase 3 Bytecode Verifier Bytecode verifier confirms that all bytecodes are valid and do not violate Java’s security restrictions. Phase 4 Interpreter Interpreter reads bytecodes and translates them into a language that the computer can understand, possibly storing data values as the program executes. Phase 5 Typical Java environment.

Java In discussing java it is important to distinguish between : The Java Programming Language The Java Virtual Machine The Java Platform

Java The Java Programming Language is the language in which Java applications, applets , servlets and components are written. It is an object orientated language like C++. The Java Virtual Machine, (or java interpreter) is the crucial piece of every Java installation. Java applications are portable, but they are only portable to platforms to which a java virtual machine ( or java interpreter ) has been ported. 3. The Java Platform . All programs written in Java rely on the set of predefined classes that comprise the java platform. These classes are organised into related groups known as packages. The java platform defines packages for functionality such as input/output, networking, graphics, user interface creation.

JVM Compiled by Java compiler Interpreted by JVM myCode.class Bytecode 1001100101001 … myCode.class Bytecode Compiled by Java compiler class myCode { … … } myCode.java Interpreted by JVM Source Code Application runs

JVM JVM provides the run time environment for the bytecode (Java Runtime Environment JRE) executes the bytecode and causes native machine code instructions to execute on the CPU that the JVM is on  each target platform needs an implementation of the JVM

Java Compiler myCode.java Source Code Errors Byte Code Compiler class myCode { … … } myCode.java Byte Code Compiler Source Code Interpreter for Computer A (JVM) Interpreter for Computer B (JVM) Interpreter for Computer C (JVM)

Operation of the JRE (Java Runtime Environment) Compile Class Loader java ______ ________ myCode.java Bytecode verifier Load from hard disk, network or other source javac Interpreter ______ ________ myCode.class RunTime Hardware

JRE At runtime the java bytecode that makes up a java software program are Loaded, checked and run in an interpreter In the case of applets you can download the bytecode and they are then interpreted by the JVM built into the browser. Bytecode verifier checks Attributes correctly typed Body of the methods check Type checking References to other types checked

Java Applications vs Java Applets There are two categories of Java Programs A Java Application – These are stand alone programs in the traditional sense Run independently Run under the java interpreter Java applets These are programs designed to run from browsers such as Netscape or Sun’s HotJava. They don’t run independently Programs that can be included in web documents.

First Java Program (Application) // First Program HelloWorld public class HelloWorld { public static void main(String args []){ System.out.println(“Hello world...”): } } A class definition is the basic block of a Java program Each program must have a main method to tell it where to start executing

Notes // First Program HelloWorld Comments begin with // Can also use C style comments /* First Program HelloWorld */

Notes 2 public class HelloWorld This begins a class definition for class HelloWorld These classes are known as Programmer defined classes or User defined classes The public and class terms are java keywords which are always lowercase HelloWorld is the class identifier which always start with an uppercase letter

Notes 3 When you save your class definition in a file the filename must be the same as the class identifier with a .java extension So the HelloWorld class would be stored in a HelloWorld.java file

Notes 4 public static void main(String args []) Java applications automatically begin executing at main Parentheses () after main indicate a program piece called a method which define some operational component of the class. Void indicates that the method will perform a task without returning any information when it completes String args [] are used as input arguments to the method. In this case we don’t use input but java requires it anyway

Notes 5 System.out.println(“Hello world...”): System.out is called the standard output object This will display a line of text in the command window In Java , any source and destination for I/O is considered a stream of bytes or characters. To perform output we insert bytes or characters into a stream. To perform input we extract bytes or characters from a stream. java.lang.System class contains three predefined streams System.out System.err for errors System.in

A First Java Program This is a Java application not a Java applet – indicated by presence of main Source code exists in a file with same name as the class and an extension of .java. So for the previous example it is HelloWorld.java Java is case sensitive (like C.)

Using the JDK Create source files for each class in your program The name of source file should be the same as the name of class public class myCode { … … } myCode.java Source File

Compiling your source code Compile each class source file into bytecode (class files) To compile a java source file javac myCode.java This creates a classfile called myCode.class 1001101001110101011 … myCode.class Class File

To run your program To start your program running you run the bytecode of the program control class The program control class has the main method To run bytecode – pass it to the JVM java classFileName e.g. java myProg note no .class included