Object Oriented Programming … and other things you need to program in java.

Slides:



Advertisements
Similar presentations
Introduction to JavaScript
Advertisements

George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Lecture 3. Review (What is Class and Object ?) The world of JAVA contains objects The world of JAVA.
Outline Java program structure Basic program elements
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Lecture 4. Review (Attributes and Methods) Class will contain –a set of attributes and methods public class Turtle { ///// Field (Attributes) ///// …
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
The Java Programming Language
JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in In the Java programming language: A program is made.
POS 406 Java Technology And Beginning Java Code
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
The scope of local variables. Murphy's Law The famous Murphy's Law says: Anything that can possibly go wrong, does. (Wikipedia page on Murphy's Law:
Objective You will be able to define and identify the basic components of a java program by taking notes, seeing examples, and completing a lab. Construction.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
Introduction to programming in the Java programming language.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Identifiers Identifiers in Java are composed of a series of letters and digits where the first character must be a letter. –Identifiers should help to.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Java FilesOops - Mistake Java lingoSyntax
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,
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
1 Introduction to Object Oriented Programming Chapter 10.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Problem of the Day  Why are manhole covers round?
Chapter 1 Object Orientation: Objects and Classes.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
INTRODUCTION Java is a true OO language the underlying structure of all Java programs is classes. Everything must be encapsulated in a class that defines.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Introduction to OO Programming Andy Wang Object Oriented Programming in C++ COP 3330.
Classes, Methods and more
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Review What is an object? What is a class?
Introduction to.
Java Primer 1: Types, Classes and Operators
CompSci 230 Software Construction
Programming Language Concepts (CIS 635)
Lecturer: Mukhtar Mohamed Ali “Hakaale”
String Output ICS 111: Introduction to Computer Science I
Can perform actions and provide communication
Chapter 1: Computer Systems
Chapter 4 Writing Classes.
Implementing Classes Chapter 3.
Can perform actions and provide communication
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Object Oriented Programming in java
Java objects: a first view
Introduction to Object-Oriented Programming
Lecture 8 Object Oriented Programming (OOP)
Presentation transcript:

Object Oriented Programming … and other things you need to program in java.

Compiling a Program You write your source code (or just code) in an editor (JCreator) You click compile and the computer translates the code into bytecode (.class file) that the Java interpreter can understand If you break the rules of the language, the compiler will give you errors.

Compiling & Running Process Source Code Editor Hi h; h=new Hi(); h.hello(); h.bye(); Hi h; h=new Hi(); h.hello(); h.bye(); Compiler Class files Library files Interpreter Hello World! Bye! Java Bytecode Program

Be careful If you compile and there are errors, Java will not create a new.class file So if you click on execute after you have errors, Java might run an older version of your file

Different Types of Errors Compile time errors – the compiler will tell you that the language of your file is wrong. Run time errors – your file compiles, but it does the wrong thing.

Using comments You can add comments in your code to separate things out or to explain what you are doing (the compiler will ignore the comments): Single line comments //here is where draw the roof of the house marker.move(86,86); … Block comments – multiple lines /* marker.forward(300); marker.forward(100);*/

import If I was making a new car would I make tires from scratch or buy them from a tire company? Software developers are lazy import gpdraw.*; Importing in a package or already written code

Methods (behaviors) modifiers return_type method_name ( parameters ) { method_body } Example: public void drawCircle(int radius) { //draws circle … }

Modifiers Example: public void drawCircle(int radius) { //draws circle … } public (everyone can see and use) private (only this class can see it)

Modifiers Example public someone.getName(); private someone.getWeight();

Return Type Example: public void drawCircle(int radius) { //draws circle … } What information comes back from the method String (text) int (integer) double (decimal number) void (nothing)

Return Type Examples What’s the return type? someone.raiseHand(); someone.getAge();

Parameters Example: public void drawCircle(int radius) { //draws circle … } Information that must be given someone.waveRightHand(); someone.call(String name);

Method Body Example: public void drawCircle(int radius) { //draws circle … } How to do the method. Your methods were full of forward, move and turnRight calls.

Declaring an Object DrawingTool pencil; I have a DrawingTool called pencil pencil is an instance of a DrawingTool Person alicia; I have a Person called alicia alicia is an instance of a Person

Instantiating An Object Create and initialize an object pencil = new DrawingTool(poster); Calls the constructor (special method) sending the parameter (argument) poster Person alicia = new Person(“Alicia”);

The Difference Between Classes and Objects Classes are a blueprints for objects A Person will have 2 arms and a name etc. An Arena will have seats, etc Objects are specific instances of a class The specific pe rson with the name Alicia The Staples Center is a specific instance of an Arena