Lecture 3. Review (What is Class and Object ?) The world of JAVA contains objects The world of JAVA.

Slides:



Advertisements
Similar presentations
In Review JAVA C++ GUIs - Windows Webopedia.com.
Advertisements

IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Lecture 2: Do you speak Java?. From Problem to Program Last Lecture we looked at modeling with objects! Steps to solving a business problem –Investigate.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
1 Programming Languages b Each type of CPU has its own specific machine language b But, writing programs in machine languages is cumbersome (too detailed)
Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
Lecture 4. Review (Attributes and Methods) Class will contain –a set of attributes and methods public class Turtle { ///// Field (Attributes) ///// …
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
Lecture 2: Do you speak Java?. From Problem to Program Last Lecture we looked at modeling with objects! Steps to solving a business problem –Investigate.
An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming.
Lecture 5. Review (Attributes and Methods) Class will contain –a set of attributes and methods public class Turtle { ///// Field (Attributes) ///// …
ALGORITHMS CSC 171 LECTURE 1. What is “Computer Science”? What is “Science”? What is a “Computer”? What is “Computation”?
Using the Java programming language compiler. Review of relevant material from previous lectures From previous lectures: A computer can only execute machine.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Marlene Galea.  The JDK (Java Development Kit)  An IDE (Integrated Development Environment) ◦ Different IDEs include:  JCreator  NetBeans  BlueJ.
COMP Computer Basics Yi Hong May 13, 2015.
IB Computer Science II Paul Bui
1 Chapter-01 Introduction to Computers and C++ Programming.
Lecture 1 Introduction to Java MIT- AITI 2004 What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
ITEC 352 Lecture 11 ISA - CPU. ISA (2) Review Questions? HW 2 due on Friday ISA –Machine language –Buses –Memory.
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
Introduction to Programming Writing Java Beginning Java Programs.
BIT 1003 – Presentation 7. Contents GENERATIONS OF LANGUAGES COMPILERS AND INTERPRETERS VIRTUAL MACHINES OBJECT-ORIENTED PROGRAMMING SCRIPTING LANGUAGES.
Programming 1 1. Introduction to object oriented programming and problem-solving.
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Welcome to the Lecture Series on “Introduction to Programming With Java”
First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
UNIT - 1Topic - 3. Computer software is a program that tells a computer what to do. Computer software, or just software, is any set of machine-readable.
Lecture 1 Introduction to Java MIT-AITI Ethiopia 2004.
Object Oriented Programming … and other things you need to program in java.
Methods in Java CSC1401. Overview In this session, we are going to see how to create class-level methods in Java.
COP 3330 Notes 1/12. Today's topics Downloading Java and Eclipse Hello World Basic control structures Basic I/O Strings.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
3/5/2009Computer software1 Introduction Computer System Hardware Software HW Kernel/OS API Application Programs SW.
Lecture 1 Introduction. 1-2 Your world is filled with objects. Many of these objects are controlled by computers. Computers rely on ___________ to determine.
Introduction to Programming Writing Java Beginning Java Programs.
I Power Higher Computing Software Development Development Languages and Environments.
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.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
Chapter 4 Software. Chapter 4: Software Generations of Languages Each computer is wired to perform certain operations in response to an instruction. An.
 Computer Languages Computer Languages  Machine Language Machine Language  Assembly Language Assembly Language  High Level Language High Level Language.
1 Chapter 1 Programming Languages Evolution of Programming Languages To run a Java program: Java instructions need to be translated into an intermediate.
By: Cheryl Mok & Sarah Tan. Java is partially interpreted. 1. Programmer writes a program in textual form 2. Runs the compiler, which converts the textual.
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,
Getting Started With Java September 22, Java Bytecode  Bytecode : is a highly optimized set of instructions designed to be executed by the Java.
Georgia Institute of Technology More on Creating Classes part 3 Barb Ericson Georgia Institute of Technology Nov 2005.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Compilers and Interpreters
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
Lecture 1 Introduction. © 2006 Pearson Addison-Wesley. All rights reserved 1-2 Your world is filled with objects. Many of these objects are controlled.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
Introduction to OO Programming Andy Wang Object Oriented Programming in C++ COP 3330.
Computer Systems Nat 5 Computing Science
Why don’t programmers have to program in machine code?
Computer Systems Nat 5 Computing Science
Introduction to.
TRANSLATORS AND IDEs Key Revision Points.
Assembler, Compiler, Interpreter
Assembler, Compiler, Interpreter
More on Creating Classes
More on Creating Classes part 3
Introduction to Computer Science
Presentation transcript:

Lecture 3

Review (What is Class and Object ?) The world of JAVA contains objects The world of JAVA

Review (What is Class and Object ?) Objects are generated from The world of JAVA classes

Class Car Review (What is Class and Object ?) … HondaFord TOYOTA

Today Let’s write a method in the class Turtle –We are going to write our own methods –So far, we just used methods written by other programmers (e.g. forward(), turnLeft(), etc)

Writing Java program Application (or Software) is written in programming language –Java application is constructed by Java programs written in Java programming language –Generally, when we say that “writing java program”, it means that “writing classes” –i.e. we are writing blueprints for applications

Attributes and Methods Class will contain –a set of attributes and methods Attribute –State of object generated from the class E.g. name, color, size, etc … Methods –Behavior of object generated from the class E.g. moveTo(int x, int y), turnLeft(), etc …

Class Car HondaFord TOYOTA Example (Attributes and Methods) … Attribute color, size, name, etc Methods move, turn, stop, etc

Java Source Code (source file) public class SimpleTurtle { ///// Field (Attributes) ///// … /////// Method /////// … } Each class is programmed in source file named ClassName. java For example, SimpleTurtle.java

How to run the program? How do computers understand source codes written in Java programming language ? Basically, there are 3 steps 1.Edit source code 2.Compile source code 3.Execute the compiled code Repeat!

Compile Once we write source codes (i.e..java file), we have to translate it to the codes which computers can understand –The process of translation is called “compile” Java compiler performs this task The compiled code is called java Bytecode Source code (.java) Bytecode (.class) Java Compiler

Execute (Run) In order to execute bytecodes –bytecode compiler will translate the codes into machine codes (sequences of 0 and 1) Finally, computers understand what we write in Java programming language –i.e. computers understand what we want Bytecode (.class) Bytecode Compiler Machine Code

Level of programming language Java source code –Human readable language –High-level programming language Java bytecode –Human readable notation of machine code Machine code –Binary string (0 and 1) x = x + y.data x:.word 0x42 y:.word 0x43.text start: set x, %r1 ld [%r1], %r2 ! $x$ --> %r2 set y, %r1 ld [%r1], %r3 ! $y$ --> %r3 add %r2, %r3, %r2 ! $x+y$ --> %r2 set x, %r1 st %r2, [%r1] ! $x+y$ --> x end: ta (omit…) Example

Source code Java compiler Java bytecode Java interpreter Bytecode complier Machine code.java file.class file Execute! Summary * We can test (in Interaction panel)

Practice –Let’s write our own method!!!

Edit source code - Open Turtle.java We gonna write Methods Here!!! After this line

Write a method, named drawOne ////////// method ////////// public void drawOne() { }

Write a method, named drawOne ////////// method ////////// public void drawOne() { forward(100); turn(225); forward(40); }

Save source code –Save Turtle.java Note: File name should be the same as Class name Extension of the file is.java

Compile it –Right click on the source file Success?

Let’s Test the compiled code –In an interaction panel, create a turtle in the world, then try to call the method drawOne()

Challenge!!! Write a method for Turtle –The method name is drawSquare –The method draws the one square with size 50