Java Programming Pancakes In one bowl mix: sequence of 1 cup - - PowerPoint PPT Presentation

java programming
SMART_READER_LITE
LIVE PREVIEW

Java Programming Pancakes In one bowl mix: sequence of 1 cup - - PowerPoint PPT Presentation

Hello Hello World World What is a program? Definition: a Java Programming Pancakes In one bowl mix: sequence of 1 cup flour instructions telling TOPICS CS 160, Fall Semester 2012 CS 160, Fall Semester 2012 1 tbsp sugar a


slide-1
SLIDE 1

Hello World

Java Programming

CS 160, Fall Semester 2012 CS 160, Fall Semester 2012 TOPICS

  • Computer Programs
  • Using Eclipse
  • Hello World Program
  • Program Components

1 CS 160, Summer Semester 2016 Hello World

What is a program?

■ Definition: a

sequence of instructions telling a computer what to do

■ Analogy: cooking

recipes

Pancakes In one bowl mix: 1½ cup flour 1 tbsp sugar 1 tsp salt 1 tsp baking powder

CS 160, Summer Semester 2016 2 Hello World

Programs as Recipes

Recipes specify

1.

What ingredients to use

2.

What to do with them

Sometimes conditional: “bake until golden brown”, “salt to taste”

Programs specify

1.

What information (data) to use

2.

What operations to apply

Sometimes conditional: “while file is not empty”, “for every element in array”

CS 160, Summer Semester 2016 3 Hello World

Programs ≠ Recipes

At some point the analogy breaks down:

■ Recipes are read by people

■ People can make inferences. ■ If something goes wrong, people react. ■ People sometimes make mistakes.

■ Programs are read by machines

■ Machines do exactly what they are told! ■ No matter how badly things go wrong. ■ But, they never make mistakes or get tired.

CS 160, Summer Semester 2016 4

slide-2
SLIDE 2

Hello World

Definitions

■ program

■ a set of directions telling a computer exactly what to do

■ programming languages

■ precise languages for specifying sequences of directions to a computer ■ unlike English -- no ambiguities! no nuances!

■ algorithm

■ a sequence of steps to be followed to solve a problem ■ independent of any programming language

CS 160, Summer Semester 2016 5 Hello World

Object-oriented programming

■ Java programs use objects and methods

■ An ‘object’ is a collection of code and data that you

treat as a unit.

■ Objects have ‘methods’ – code that implements

actions that apply to the object.

■ Objects have ‘members’ – data that is associated

with the object.

■ A Java cooking program might have a line like

‘egg.scramble()’ to scramble an egg…

CS 160, Summer Semester 2016 6 Hello World CS 160, Summer Semester 2016 7 Hello World

■ ■

■ ■

CS 160, Summer Semester 2016 8

slide-3
SLIDE 3

Hello World CS 160, Summer Semester 2016 9 Hello World

Hello World Program

// HelloWorld // Author: Gareth Halladay // Date: 6/13/2016 // Class: CS160 // Email: gareth@rams.colostate.edu import java.lang.*; public class HelloWorld { public static void main(String[] args) { System.out.println( "Hello World!" ); } }

CS 160, Summer Semester 2016 10 Hello World

Import directive

▪ ▪ ▪ ▪

CS 160, Summer Semester 2016 11 Hello World

▪ ▪ ▪ ▪

CS 160, Summer Semester 2016 12

slide-4
SLIDE 4

Hello World

▪ ▪

CS 160, Summer Semester 2016 13 Hello World

▪ ▪ ▪

CS 160, Summer Semester 2016 14 Hello World

▪ ▪ ▪

CS 160, Summer Semester 2016 15 Hello World

▪ ▪ ▪ ▪

CS 160, Summer Semester 2016 16

slide-5
SLIDE 5

Hello World

▪ ▪

▪ ▪

▪ ▪

CS 160, Summer Semester 2016 17 Hello World

▪ ▪ ▪ ▪

CS 160, Spring Semester 2016 18 Hello World

CS 160, Summer Semester 2016 19