Top Banner
Computer Programming 12 Mr. Jean March 19 th , 2013
24

Computer Programming 12 Mr. Jean March 19 th, 2013.

Dec 30, 2015

Download

Documents

Dwayne Anderson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computer Programming 12 Mr. Jean March 19 th, 2013.

Computer Programming 12

Mr. Jean

March 19th, 2013

Page 2: Computer Programming 12 Mr. Jean March 19 th, 2013.

The plan:

• Video clip of the day

• Why Java

• More simple programs

Page 3: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.1 Why Java?

• Java is the fastest growing programming language in the world.

• Java is a modern object-oriented programming language.

• Java has benefited by learning from the less desirable features of early object-oriented programming languages.

Page 4: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.1 Why Java?

• Java is ideally suited to develop distributed, network-based applications because it:

– Enables the construction of virus-free, tamper-free systems (security)

– Supports the development of programs that do not overwrite memory (robust)

– Yields programs that can be run on different types of computers without change (portable)

Page 5: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.1 Why Java?

• Java supports advanced programming concepts such as threads.

– A thread is a process that can run concurrently with other processes.

• Java resembles C++, the world’s most popular industrial strength programming language.

• Java however, runs more slowly than most modern programming languages because it is interpreted.

Page 6: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.2 The Java Virtual Machine and Byte Code

• Java compilers translate Java into pseudomachine language called java byte code.

• To run java byte code on a particular computer, a Java virtual machine (JVM) must be installed.

Page 7: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.2 The Java Virtual Machine and Byte Code

• A Java virtual machine is a program that acts like a computer. It is called an interpreter.

• Disadvantage:– Runs more slowly than an actual

computer• To combat slower processing, some JVMs

translate code when first encountered. This is known as just-in-time compilation (JIT).

Page 8: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.2 The Java Virtual Machine and Byte Code

• Advantages:

– Portability. Any computer can run Java byte code.

– Applets. Applets are small Java programs already translated into byte code.

• Applets run in a JVM incorporated in a web browser• Applets can be decorative (like animated characters on

a web page.)• Applets can be practical (like continuous streams of

stock market quotes.)

– Security. It is possible to limit the capabilities of a Java program since it runs inside a virtual machine.

Page 9: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.3 Choosing a User Interface Style

• There are two types of user interfaces available to use to create Java programs.

– Graphical User Interface (GUI)– Terminal I/O interface

• Figure 2-1 illustrates both interfaces used to create the same program.

Page 10: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.3 Choosing a User Interface Style

Page 11: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.3 Choosing a User Interface Style

• There are 3 reasons for beginning with terminal I/O:

– It is easier to implement than a GUI– There are programming situations that

require terminal I/O– Terminal-oriented programs are similar in

structure to programs that process files of sequentially organized data. (What is learned here is easily transferred to that setting.)

Page 12: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.4 Hello World

• Figure 2-2 displays the results of a small Java program, entitled “hello world”

Page 13: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.4 Hello World

• A program is a sequence of instructions for a computer.

• The following is the bulk of instructions, or source code, for the “hello world” program.

Page 14: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.4 Hello World

• Sending messages to objects always takes the following form:

<name of object>.<name of message>(<parameters>)

Page 15: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.4 Hello World

• The original “hello world” program needs to be embedded in a larger framework defined by several additional lines of code, in order to be a valid program.

Page 16: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.5 Edit, Compile, and Execute

• Figure 2-3 illustrates the edit, compile and execute steps.

Page 17: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.5 Edit, Compile, and Execute

• Development environments:– Unix

• standard text editor• command line activation of compiler and JVM

– DOS, using Microsoft Windows and NT OS• notepad text editor• command line activation of compiler and JVM

from a DOS window– Integrated development environment, using

Windows, NT, or MAC OS• Examples: Symantec’s Visual Café, Microsoft’s

Visual J++, or Borland’s J Builder

Page 18: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.5 Edit, Compile, and Execute

• Preparing your development environment:

– Create a directory, open a terminal window, use the cd command to move to your new directory

– Open notepad, create the file HelloWorld.java, type in the lines of code

– Save the file, go back to the terminal window, compile the program

– Run the program

Page 19: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.5 Edit, Compile, and Execute

• The following figures illustrate the steps necessary for preparing your development environment.

Page 20: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.5 Edit, Compile, and Execute

Page 21: Computer Programming 12 Mr. Jean March 19 th, 2013.

2.5 Edit, Compile, and Execute

Page 22: Computer Programming 12 Mr. Jean March 19 th, 2013.

Today’s Task:

• Create a program which completes the following task.

• Output Display needed:

a = 30b = 40a * b = 1200

Page 23: Computer Programming 12 Mr. Jean March 19 th, 2013.

Today’s Task:

• Build Program #2

• Build Program #3

• Using what we have seen in programs #2 & #3, build a program which successfully asks for your name, what class your are in and today’s date.

Page 24: Computer Programming 12 Mr. Jean March 19 th, 2013.