Top Banner
Computer Programming 12 Mr. Jean March 3 rd, 2014
25
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 3 rd, 2014.

Computer Programming 12

Mr. Jean

March 3rd, 2014

Page 2: Computer Programming 12 Mr. Jean March 3 rd, 2014.

The plan:

• Video Clip of the day

• Why Java?

• Using Jcreator

• Learning how to create a project in Jcreator

Page 3: Computer Programming 12 Mr. Jean March 3 rd, 2014.

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 3 rd, 2014.

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 3 rd, 2014.

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 3 rd, 2014.

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 3 rd, 2014.

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 3 rd, 2014.

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 3 rd, 2014.

How to build new projects:

Page 10: Computer Programming 12 Mr. Jean March 3 rd, 2014.
Page 11: Computer Programming 12 Mr. Jean March 3 rd, 2014.
Page 12: Computer Programming 12 Mr. Jean March 3 rd, 2014.
Page 13: Computer Programming 12 Mr. Jean March 3 rd, 2014.
Page 14: Computer Programming 12 Mr. Jean March 3 rd, 2014.
Page 15: Computer Programming 12 Mr. Jean March 3 rd, 2014.
Page 16: Computer Programming 12 Mr. Jean March 3 rd, 2014.

Today’s Goals:

• We will be introduced to classes and static methods and are shown how to compile and run a Java program.

Page 17: Computer Programming 12 Mr. Jean March 3 rd, 2014.

First Program in Java

• This simple program causes the word “Hello” to be printed.

• To start: – Find jcreator on your computer– Open jcreator and copy to code from my PPT

onto your jcreator

Page 18: Computer Programming 12 Mr. Jean March 3 rd, 2014.

J-creator Video:

• http://www.youtube.com/watch?v=Bmryow3NYPE (Getting Started)

• http://www.youtube.com/watch?v=SMHK3oO8zLg (Hello World)

• http://www.youtube.com/watch?v=3u1fu6f8Hto (About Java & Applications)

Page 19: Computer Programming 12 Mr. Jean March 3 rd, 2014.

Compiling & Running a program• A Java program must be compiled before

it can be run by the Java system (Java Virtual Machine). – The complier translates the Java program into

the underlying Java machine language (called Java byte codes) and creates a file containing the result.

– This file (also called the class file) is used by the Java system to run (or execute) the program producing the program output.

Page 20: Computer Programming 12 Mr. Jean March 3 rd, 2014.

• When the program is run the system looks for the main method and begins with the first instruction and then the further instructions in order. Most methods contain many instructions.

• In Java instructions are called statements. – Statements are executed.

• The program above contains the single statement that causes the word (or string) Hello to be printed. – System.out.println("Hello");

Page 21: Computer Programming 12 Mr. Jean March 3 rd, 2014.

Creating an error:

• One of the functions of the compiler is to detect syntax errors.

• Deliberately introduce small syntax errors and observe the results.

Page 22: Computer Programming 12 Mr. Jean March 3 rd, 2014.

Common Errors:

• When using JavaRoom, if the name of the class containing the main method is not the same as the name of the file, the name of the class must be selected before clicking the run button.

Page 23: Computer Programming 12 Mr. Jean March 3 rd, 2014.

About our Program:

• Our program consists of a class containing a main method (a method with the name main). – the name of the class is HelloTester. – the class contains a main method which must be

public (otherwise it will not run)– static(because it is not part of any object) – void (because it does not return any value).

• In this case the method contains only one instruction (statement) which is a call to the println method in the out object in the System class.

Page 24: Computer Programming 12 Mr. Jean March 3 rd, 2014.

Adding information:

• It is important to tell other programmers what you are doing

• In order to do this you must start with start with “/*” and end with “*/”

Page 25: Computer Programming 12 Mr. Jean March 3 rd, 2014.