+ All Categories
Home > Documents > R:\ap java\class slides\chapter 1\1 2 java development

R:\ap java\class slides\chapter 1\1 2 java development

Date post: 05-Dec-2014
Category:
Upload: ken-kretsch
View: 945 times
Download: 0 times
Share this document with a friend
Description:
 
11
Running a program • Compiling A program, called a compiler, translates the source code into machine code The CPU then executes the machine code C, FORTRAN, Pascal, COBOL, BASIC • Interpreting A program, called an interpreter, reads the source code and executes the instructions BASIC, LISP, Perl, Python
Transcript
Page 1: R:\ap java\class slides\chapter 1\1 2 java development

Running a program

• Compiling– A program, called a compiler, translates the source

code into machine code– The CPU then executes the machine code– C, FORTRAN, Pascal, COBOL, BASIC

• Interpreting– A program, called an interpreter, reads the source

code and executes the instructions– BASIC, LISP, Perl, Python

Page 2: R:\ap java\class slides\chapter 1\1 2 java development

Java Code Execution

• Compiler (javac) translates source code (.java file) to byte code (.class file)

• Byte code is machine independent• Byte code is interpreted by the Java run-time

program program (java), the IDE (BlueJ), the appletviewer, or the web browser.

• The program can be compiled on one machine and interpreted on another.

Page 3: R:\ap java\class slides\chapter 1\1 2 java development

Java Pyramid

Application or Applet

Class Class

Project

Data Methods

Data Instructions

Page 4: R:\ap java\class slides\chapter 1\1 2 java development

Java Development

• JDK 1.6.20 SE Development Kit (JDK)– http://java.sun.com/javase/downloads/index.jsp– Includes compiler, interpreter, and libraries

• BlueJ– Version 3– IDE (Integrated Development Environment)– Tools for designing, developing, and testing Java

software.– http://bluej.org

Page 5: R:\ap java\class slides\chapter 1\1 2 java development

Hello, world!!

• Class• Methods

– main

• Comments– javadocs

• Blocks

Page 6: R:\ap java\class slides\chapter 1\1 2 java development

Classes and Objects

• A class is a definition of a (complex) data type• An object is an instantiation of a class• A Java program is a set of interacting objects• Everything in Java is an object

Page 7: R:\ap java\class slides\chapter 1\1 2 java development

Special method: main

• Methods– A collection of data and instructions– Has a specific purpose

• public static void main(String args)– The start of a Java application– It must belong to a class– (We will cover applets after we’ve covered objects

and classes)

Page 8: R:\ap java\class slides\chapter 1\1 2 java development

Comments

• Notes to other readers of your software (including your teacher and yourself).

• Ignored by the machine.• Two formats:

– “/*” starts a comment, ‘*/’ finishes it. These comments can span multiple lines.

– ‘//’ starts the comment, EOL (end-of-line) finishes it.

• Comments can be inserted anywhere, but there are some common locations.

Page 9: R:\ap java\class slides\chapter 1\1 2 java development

Blocks

• A section of code; a set of instructions or statements.

• A block starts with ‘{‘, and ends with ‘}’• Blocks are written for:

– Method definitions– Class definitions– Loops – ‘then’ and ‘else’ bodies

• Blocks also define scope for variables.

Page 10: R:\ap java\class slides\chapter 1\1 2 java development

Lab 0: Hello, world

Page 11: R:\ap java\class slides\chapter 1\1 2 java development

Lab 0 debrief: What have we discovered?

• We created an application called Hello• The software was created in a folder in My

Documents also called Hello• The folder has a file called Hello.java

containing:– A Class called Hello– The main method, the applications starting point.

• The compiler creates a file called Hello.class containing the program’s byte code.

• We were able to do everything using BlueJ


Recommended