Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

Similar documents
C++ Spring Break Packet 11 The Java Programming Language

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Course Outline. Introduction to java

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Chapter 1 Introduction to Java

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Chapter 1. Introduction

Introduction to Java Applications; Input/Output and Operators

Lecture 1: Introduction to Java

Chapter 1 Introduction to Computers and C++ Programming

Introduction to Computers, the Internet and the World Wide Web

Chapter 2 Author Notes

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

1/14/2014. Introduction to CSE 1325 Object Oriented Programming (Using Java) Introduction (Cont.) Introduction

Introduction to C# Applications

Fundamentals of Programming. By Budditha Hettige

Module 1: Introduction to Computers, Programs, and Java

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Chapter 1 Introduction to Computers, Programs, and Java

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

Object Oriented Concepts and Programming (CSC244) By Dr. Tabbasum Naz

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 2, Part I Introduction to C Programming

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Chapter 1: Introduction to Computers, Programs, and Java

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

6.096 Introduction to C++ January (IAP) 2009

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

CHAPTER 1 Introduction to Computers and Java

II. Compiling and launching from Command-Line, IDE A simple JAVA program

Introduction to Java Applications

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

IT 374 C# and Applications/ IT695 C# Data Structures

Chapter 1 Introduction to Computers, Programs, and Java

Lesson 2: First Java Programs

Introduction to JAVA Programming Language

COMP Computer Basics. Yi Hong May 13, 2015

Chapter 1 & 2 Introduction to C Language

Introduction to Java Programming CPIT 202. WEWwwbvxnvbxmnhsgfkdjfcn

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

Objectives. Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer?

Introduction to Programming

Copyright 1999 by Deitel & Associates, Inc. All Rights Reserved.

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

1. Introduction. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Eng. Mohammed S. Abdualal

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Chapter 1 Introduction to Computers, Programs, and Java

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Basic Programming Language Syntax

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

For the course, we will be using JCreator as the IDE (Integrated Development Environment).

B.V. Patel Institute of BMC & IT, UTU 2014

Introduction to Computer Science I

Lab # 2. For today s lab:

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

Chapter 3 Intro to Java

Chapter 1 Introduction to Computers, Programs, and Java

Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

Chapter 1 Introduction to Computers, Programs, and Java

Programming with Java

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Programming with Java

Introduction to Java

Lecture Set 2: Starting Java

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

2 rd class Department of Programming. OOP with Java Programming

Lecture Set 2: Starting Java

Lecture 7: Classes and Objects CS2301

Introduction to Computers and Java

Section 2.2 Your First Program in Java: Printing a Line of Text

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java

Full file at

Introduction to Computers and Java

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Chapter 2 First Java Programs

Section 2.2 Your First Program in Java: Printing a Line of Text

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

Introduction to Java Programming

CHAPTER 1. Introduction to JAVA Programming

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Chapter 2: Programming Concepts

TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN. Week 12/02/ /02/2007 Lecture Notes:

Objects and Classes Lecture 1

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

Transcription:

1 1 Introduction to OOP Using Java

2 Introduction Sun s implementation called the Java Development Kit (JDK) Object-Oriented Programming Java is language of choice for networked applications Java Enterprise Edition (Java EE) geared toward largescale distributed applications and web applications Java Micro Edition (Java ME) geared toward applications for small, memory constrained devices

Machine Languages, Assembly Languages and High-Level Languages 3 Machine language Natural language of computer component Machine dependent Assembly language English-like abbreviations represent computer operations Translator programs (assemblers) convert to machine language High-level language Allows for writing more English-like instructions Contains commonly used mathematical operations Compiler converts to machine language Interpreter Execute high-level language programs without compilation

4 History of C and C++ C++ evolved from C, which evolved from BCPL and B C C++ Developed at Bell Labs Popularized as the language of the UNIX operating system Deveoped by Bjarne Stroustrup Provides object-oriented programming capabilities Hybrid language

5 History of Java Java Originally for intelligent consumer-electronic devices Then used for creating web pages with dynamic content Now also used to: Develop large-scale enterprise applications Enhance web server functionality Provide applications for consumer devices (cell phones, etc.)

6 Java Class Libraries Java programs consist of classes Include methods that perform tasks Return information after task completion Java provides class libraries Known as Java APIs (Application Programming Interfaces) To use Java effectively, you must know Java programming language Extensive class libraries

7 Software Engineering Observation When programming in Java, you will typically use the following building blocks: Classes and methods from class libraries, classes and methods you create yourself and classes and methods that others create and make available to you.

8 Performance Tip Using Java API classes and methods instead of writing your own versions can improve program performance, because they are carefully written to perform efficiently. This technique also shortens program development time.

9 Portability Tip Using classes and methods from the Java API instead of writing your own improves program portability, because they are included in every Java implementation.

Typical Java Development Environment 10 Java programs go through five phases Edit Programmer writes program using an editor; stores program on disk with the.java file name extension Compile Use javac (the Java compiler) to create bytecodes from source code program; bytecodes stored in.class files Load Class loader reads bytecodes from.class files into memory Verify Bytecode verifier examines bytecodes to ensure that they are valid and do not violate security restrictions Execute Java Virtual Machine (JVM) uses a combination of interpretation and justin-time compilation to translate bytecodes into machine language

11 Fig. 1 Typical Java development environment.

12 What is Object? Objects: Reusable software components that model real-world items Look all around you People, animals, plants, cars, etc. Attributes Size, shape, color, weight, etc. Behaviors Babies cry, crawl, sleep, etc.

13 What is OOP? Object-oriented design (OOD) Models software in terms similar to those used to describe realworld objects Class relationships Inheritance relationships Models communication among objects Encapsulates attributes and operations (behaviors) Information hiding Communication through well-defined interfaces Object-oriented language Programming in object-oriented languages is called objectoriented programming (OOP) Classes are to objects as blueprints are to houses

First Program in Java: Printing a Line of Text 1 // Fig. 2.1: Welcome1.java 2 // Text-printing program. 3 4 public class Welcome1 5 { 6 // main method begins execution of Java application 7 public static void main( String args[] ) 8 { 9 System.out.println( "Welcome to Java Programming!" ); 10 11 } // end method main 12 13 } // end clazss Welcome1 14 Welcome to Java Programming!

First Program in Java: Printing a Line of Text (Cont.) 15 1 // Fig. 2.1: Welcome1.java Comments start with: // Comments ignored during program execution Document and describe code Provides code readability Traditional comments: /*... */ /* This is a traditional comment. It can be split over many lines */ 2 // Text-printing program. Another line of comments Note: line numbers not part of program, added for reference

First Program in Java: Printing a Line of Text (Cont.) 16 3 Blank line Makes program more readable Blank lines, spaces, and tabs are white-space characters Ignored by compiler 4 public class Welcome1 Begins class declaration for class Welcome1 Every Java program has at least one user-defined class Keyword: words reserved for use by Java class keyword followed by class name Naming classes: capitalize every word SampleClassName

First Program in Java: Printing a Line of Text (Cont.) 17 4 public class Welcome1 Java identifier Series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) Does not begin with a digit, has no spaces Examples: Welcome1, $value, _value, button7 7button is invalid Java is case sensitive (capitalization matters) a1 and A1 are different

18 Good Programming Practice By convention, always begin a class name s identifier with a capital letter and start each subsequent word in the identifier with a capital letter. Java programmers know that such identifiers normally represent Java classes, so naming your classes in this manner makes your programs more readable.

First Program in Java: Printing a Line of Text (Cont.) 19 7 public static void main( String args[] ) Part of every Java application Applications begin executing at main Parentheses indicate main is a method Java applications contain one or more methods Exactly one method must be called main Methods can perform tasks and return information void means main returns no information For now, mimic main's first line 8 { Left brace begins body of method declaration Ended by right brace } (line 11)

First Program in Java: Printing a Line of Text (Cont.) 20 9 System.out.println( "Welcome to Java Programming!" ); Instructs computer to perform an action Prints string of characters String series of characters inside double quotes White-spaces in strings are not ignored by compiler System.out Standard output object Method System.out.println Displays line of text This line known as a statement Statements must end with semicolon ;

First Program in Java: Printing a Line of Text (Cont.) 21 11 } // end method main Ends method declaration 13 } // end class Welcome1 Ends class declaration Can add comments to keep track of ending braces

1 // Fig. 2.4: Welcome3.java 2 // Printing multiple lines of text with a single statement. 3 4 public class Welcome3 5 { 6 // main method begins execution of Java application 7 public static void main( String args[] ) 8 { 9 System.out.println( "Welcome\nto\nJava\nProgramming!" ); 10 11 } // end method main 12 13 } // end class Welcome3 Welcome to Java Programming! Outline Welcome3.java 1. main 2. System.out.println (uses \n for new line) 22 Program Output A new line begins after each \n escape sequence is output.

23 Escape sequence Description \n Newline. Position the screen cursor at the beginning of the next line. \t Horizontal tab. Move the screen cursor to the next tab stop. \r Carriage return. Position the screen cursor at the beginning of the current line do not advance to the next line. Any characters output after the carriage return overwrite the characters previously output on that line. \\ Backslash. Used to print a backslash character. \" Double quote. Used to print a double-quote character. For example, System.out.println( "\"in quotes\"" ); displays "in quotes"

24 Introduction to Java technology The Java programming language is a high-level language that can be characterized by all of the following buzzwords: Simple Object oriented Distributed Multithreaded Dynamic Portable

25 Why Java is OOP? Encapsulation--implements information hiding and modularity (abstraction) Polymorphism--the same message sent to different objects results in behavior that's dependent on the nature of the object receiving the message Inheritance--you define new classes and behavior based on existing classes to obtain code re-use and code organization

26 Why Java is considered portable? Portable: The primary benefit of the interpreted byte code approach is that compiled Java language programs are portable to any system on which the Java interpreter and run-time system have been implemented.

27 Typical Java Development Environment Integrated development environments (IDEs): Provide tools that support the software-development process, including editors for writing and editing programs and debuggers for locating logic errors errors that cause programs to execute incorrectly. Popular IDEs Eclipse (www.eclipse.org) NetBeans (www.netbeans.org) JBuilder (www.codegear.com) JCreator (www.jcreator.com) BlueJ (www.bluej.org) jgrasp (www.jgrasp.org)