CS212:Data Structure

Similar documents
Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

CS 231 Data Structures and Algorithms, Fall 2016

CS 11 java track: lecture 1


Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Java Bytecode (binary file)

Fundamentals of Programming. By Budditha Hettige

Java Object Oriented Design. CSC207 Fall 2014

Sri Vidya College of Engineering & Technology

CS11 Java. Fall Lecture 1

PROGRAMMING FUNDAMENTALS

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Lecture 1: Overview of Java

Programming Language Concepts: Lecture 2

Programming Language Concepts: Lecture 2

Ticket Machine Project(s)

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Lecture 02, Fall 2018 Friday September 7

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

OOSD. Introduction to JAVA. Giuseppe Lipari Scuola Superiore Sant Anna Pisa. September 29, 2010

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

Pace University. Fundamental Concepts of CS121 1

Games Course, summer Introduction to Java. Frédéric Haziza

Arrays Classes & Methods, Inheritance

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

AP Computer Science A

OOSD. Introduction to JAVA. Giuseppe Lipari Scuola Superiore Sant Anna Pisa. September 12, 2011

CHAPTER 1. Introduction to JAVA Programming

Programming with Java

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

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

Certified Core Java Developer VS-1036

AP Computer Science A: Java Programming

Introduction to Java

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Introduction to Programming Using Java (98-388)

3. Java - Language Constructs I

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

13 th Windsor Regional Secondary School Computer Programming Competition

2 rd class Department of Programming. OOP with Java Programming

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

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

CHAPTER 7 OBJECTS AND CLASSES

Java Primer 1: Types, Classes and Operators

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Computer Programming, I. Laboratory Manual. Final Exam Solution

COP 3330 Final Exam Review

Course Outline. Introduction to java

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

STRUCTURING OF PROGRAM

Chapter 2: Basic Elements of C++

ITI Introduction to Computing II

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

Principles of Object Oriented Programming. Lecture 4

Introduction Basic elements of Java

CSE 421 Course Overview and Introduction to Java

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

CS-202 Introduction to Object Oriented Programming

COMP 250 Winter 2011 Reading: Java background January 5, 2011

Java: introduction to object-oriented features

Introduction to Java

ECOM 2324 COMPUTER PROGRAMMING II

Chapter 6 Introduction to Defining Classes

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

Key Differences Between Python and Java

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

CompSci 125 Lecture 02

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

Getting started with Java

Java Overview An introduction to the Java Programming Language

Index COPYRIGHTED MATERIAL

ITI Introduction to Computing II

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Day 2. COMP 1006/1406A Summer M. Jason Hinek Carleton University

CHAPTER 7 OBJECTS AND CLASSES

Object Oriented Programming

Chapter 4 Defining Classes I

Chapter 2: Java OOP I

COMP 401 Spring 2013 Midterm 1

Basic Programming Language Syntax

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Advanced Computer Programming

Simple Java Reference

Data Structures (list, dictionary, tuples, sets, strings)

Java Programming. Zheng-Liang Lu. Java 301 Summer Department of Computer Science & Information Engineering National Taiwan University

Object-oriented programming in...

Chapter 1. Introduction

EMBEDDED SYSTEMS PROGRAMMING Language Basics

Character Stream : It provides a convenient means for handling input and output of characters.

9 Working with the Java Class Library

Java Professional Certificate Day 1- Bridge Session

Answer1. Features of Java

Transcription:

CS212:Data Structure

Object Oriented Programming (OOP): What, Why, How? Analyzing and Designing OO Programs (Objects & Classes) Java Syntax, Java Program Skeleton Analyzing and Designing a Program Preparing Classes.

Thinking of Objects! What is the form of Things in the world? Define an Object!! It s a thing that have a status and can perform functions

An approach to the solution of problems in which all computations are performed in the context of objects. The objects are instances of classes, which: are data abstractions contain procedural abstractions that operate on the objects A running program can be seen as a collection of objects collaborating to perform a given task

Object-Oriented Programming consists of 3 primary ideas: Data Abstraction and Encapsulation Operations on the data are considered to be part of the data type We can understand and use a data type without knowing all of its implementation details Neither how the data is represented nor how the operations are implemented We just need to know the interface (or method headers) how to communicate with the object Compare to functional abstraction with methods

Inheritance Properties of a data type can be passed down to a subtype we can build new types from old ones We can build class hierarchies with many levels of inheritance Polymorphism Operations used with a variable are based on the class of the object being accessed, not the class of the variable Parent type and sub-type objects can be accessed in a consistent way

Procedural paradigm: Software is organized around the notion of procedures Procedural abstraction Works as long as the data is simple Adding data abstractions Groups together the pieces of data that describe some entity Helps reduce the system s complexity. Such as Records and structures Object oriented paradigm: Organizing procedural abstractions in the context of data abstractions

Animal Bird Human Fish Bird, Human and Fish are all Animals However, an Animal is not necessarily a Bird, Human or Fish

move() move() move()

How To Define Objects in a Program? How dose objects interact? Classes What are they? Skeleton of a class

Objects = nouns Functions to be encapsulated فندق به عدد من الغرف السكنية المخصصه لإليجار اليومي و صاالت أفراح و قاعات إجتمات كلها تؤجر بالساعة المطلوب إعداد برنامج للحجز للفندق بحيث يعرض للمستخدم الغرف أو القاعات المتوفره و يمكن المستخدم من حجز أحدها

نظام الحجز مكان حجز غرفة قاعة صاله

A class: A unit of abstraction in an object oriented (OO) program Represents similar objects Its instances A kind of software module Describes its instances structure (properties) Contains methods to implement their behavior

Two Main Sections Variables: can be a simple data type or another Class Represent the State of the Class Define Data represented in an Class Associations Operations :A procedural abstraction used to implement the behaviour of a class.

class Name { // Attributes Type Name; Constructor { } } Setter { } Getter{ } Operations{ }

Java is a programming language created by James Gosling from Sun Microsystems in 1991. The first public available version of Java (Java 1.0) was released 1995. The target of the Java programming language was that a program can be written once and then runs on multiple operating systems. The Java programming language consists out of a Java compiler, the Java virtual machines, and the Java class libraries. The Java virtual machine is a software implementation of a computer that executes programs like a real machine. The Java virtual machine is written specifically for a specific operating system.

Java tries to deliver the promise of Write once, run everywhere Characteristics: Platform independent Object-orientated programming language Strongly-typed programming language Interpreted and compiled language Automatic memory management Single inheriance The Java programming language is actively developed via the Java Community Process (JCP) Watchout: Java is case-sensitive!!!

Java applications are written as text files The java compiler creates platform independent code which is called bytecode. Bytecode can be executed by the java runtime environment. The Java virtual machine is a program which knows how to run the bytecode on the operating system the JRE is installed upon. The JRE translates the bytecode into native code, e.g. the native code for Linux is different then the native code for Windows. Java code is compiled to produce byte code run by Java Virtual Machine (JVM) to produce results

public class Hello { public static void main(string args[]) { System.out.println("Hello World ); } } /* end of program */

name of class is same as name of file (which has.java extension) body of class surrounded by { } this class has one method called main all Java applications must have a main method in one of the classes execution starts here body of method within { } all other statements end with semicolon ;

keywords appear in bold reserved by Java for predefined purpose don t use them for your own variable, attribute or method names! public visibility could be private static the main method belongs to the Hello class, and not an instance (object) of the class void method does not return a value

String name= ALi ; name is a variable of type String we have to declare variables before we use them unlike C, variables can be declared anywhere within block use meaningful names numberofbricks start with lower case capitalise first letter of subsequent words

int 4 byte integer (whole number) range -2147483648 to +2147483648 float 4 byte floating point number decimal points, numbers outside range of int double 8 byte floating point number 15 decimal digits (float has 7) so bigger precision and range char 2 byte letter String string of letters boolean true or false (not 1 or 0)

Java provides print methods in the class System.out (don t need to import) println(name); prints out what is stored in name, then goes to a new line print(name); prints out what is stored in name, but does not start a new line print("my name is " + name); put text in quotes use + to print more than one item

methods break down large problems into smaller ones your program may call the same method many times saves writing and maintaining same code methods take parameters information needed to do their job methods can return a value must specify type of value returned

signature public static int addnums(int num1, int num2) { int answer = num1 + num2; return answer; } body

visibility [static] returntype methodname(parameterlist) visibility: public accessible to other objects and classes protected accessible to classes which inherit from this one private static keyword: use when method belongs to class as whole not object of the class

visibility [static] returntype methodname(parameterlist) return type: specifies type of information returned can be a simple type int, float, double, char, String, boolean or a class if nothing returned, use keyword void method name: use meaningful name which describes what method does!

parameter list: information needed by method pairs of type name examples: addnums(int num1, int num2) drawperson(boolean isbald, String name, int numearrings) use empty brackets if method has no parameters printheadings()

use curly brackets to enclose method body all your code goes in here write it so the method does what you intended last line should return a value of appropriate type must match type in method header nothing is executed after return statement if method returns void, can omit return statement method will automatically return at closing }

methods will not run unless called from elsewhere a statement in main() method could call another method this method could call a third method... class methods are called with the form: ClassName.methodName(parameters); omit ClassName if called in same class method name and parameters must match the method signature if the method returns a value, it can be stored in a variable or passed to another method

public static void main(string args[]) { int input; input = Console.readInt("Number? "); System.out.print("Your number plus 3 is "); System.out.println(addNums(input, 3)); }

Inheritance in Java is implemented by extending a class public class NewClass extends OldClass { We then continue the definition of NewClass as normal However, implicit in NewClass are all data and operations associated with OldClass Even though we don t see them in the definition

Read Chapter 1 of the Textbook. Install eclipse or any java editor you fancy. Start programming