18
Creating Your First Computer Program in Java Margaret Yau

Creating Your First Computer Program in Java Margaret Yau

Embed Size (px)

Citation preview

Page 1: Creating Your First Computer Program in Java Margaret Yau

Creating Your First Computer Program in Java

Margaret Yau

Page 2: Creating Your First Computer Program in Java Margaret Yau
Page 3: Creating Your First Computer Program in Java Margaret Yau

Impacts of Software

- Microsoft: the world’s largest software company- company worth $36 billion (2008)

- over 400 million copies of Windows XP sold

- the largest social networking site- company worth $3.75 – 5 billion- more than 200 million active users

Can you even imagine a day without using software?

- over 21 million iPhones sold- 50,000 applications available for download

The InternetWWW

- over 109.9 million active websites- estimated 1.5 billion Internet users

(~ 5 x U.S. Population)- 14.3 billion searches by Americans in May 09

Page 4: Creating Your First Computer Program in Java Margaret Yau

Computer programming is fun and powerful

"I'm not coming down for dinner, didn't you read my blog ?!?!"

And it is not just for nerds

Page 5: Creating Your First Computer Program in Java Margaret Yau

Creating Your First Program in

• Java– High-level– Object-oriented programming (OOP) language– Platform-independent– Free and open-source

Page 6: Creating Your First Computer Program in Java Margaret Yau

Three Important Parts of Computer Programming

• Coding• Compiling• Testing

Page 7: Creating Your First Computer Program in Java Margaret Yau

1. Coding

• Source Code: collection of statements or declarations written in some human-readable computer programming language

• A high-level way of communicating with the computer

Java: System.out.println(“How are you?");

English: Print the string “How are you?” to the computer screen.

Page 8: Creating Your First Computer Program in Java Margaret Yau

class Hello {

public static void main ( String[] args ) {

System.out.println("Hello World!");

} }

Define a type of object (class)

Class name

Define the main behavior (method)

A statement that prints “Hello World!” to the main output device

Coding Your “Hello World!” Java Program

Page 9: Creating Your First Computer Program in Java Margaret Yau

<class name>.java

Page 10: Creating Your First Computer Program in Java Margaret Yau

2. Compiling

• A compiler translates source code in a high-level language to code in a low-level language that a particular type of machines understands (often binary form)

Source code(Hello.java)

Compiler(javac)

Object code(Java bytecodes:

Hello.class)

class Hello { public static void main { System.out.println…

10001010 0101001101010011 1111010111110101 1001010110010101 10010101

Page 11: Creating Your First Computer Program in Java Margaret Yau

Compiling Your Java Program

Hello.java javac Hello.class

Source Code Compiler Object Code

javac <source file name>

Page 12: Creating Your First Computer Program in Java Margaret Yau

3. Testing• Execute the program

• Find software bugs (error, mistake, or failure)

• Verify that the program meets its requirements

Machine

Processor

Object code

Page 13: Creating Your First Computer Program in Java Margaret Yau

3. Testing• Execute the program• Find software bugs (error, mistake, or failure)

• Verify that the program meets its requirements

Page 14: Creating Your First Computer Program in Java Margaret Yau

Executing (Running) Your Java Program

java <class name>

Yay! I ran my first Java program!

Page 15: Creating Your First Computer Program in Java Margaret Yau

You have coded, compiled, and tested your first computer program

in Java.

Page 16: Creating Your First Computer Program in Java Margaret Yau

What’s Next• Software can be designed to perform almost

anything computable.• Observe and ask what people need, and use your

imagination…

e.g. program - that really understands natural language- that computes one quadrillion (1015) digits of π- that reads your mind- that creates original and artistic songs and poetry

Page 17: Creating Your First Computer Program in Java Margaret Yau

And you may be the next …

Mark ZuckerbergFacebook

Bill GatesMicrosoft

Steve JobsApple

Larry Page Sergey Brin

Google

Page 18: Creating Your First Computer Program in Java Margaret Yau

Questions?