1 / 14

Introduction to Computers and Java

Introduction to Computers and Java. Chapter 1.3. A Sip of Java: Outline. History of the Java Language Applets A First Java Program Compiling a Java Program or Class Running a Java Program Objects and Methods A Sample Graphics Applet. History of Java.

Télécharger la présentation

Introduction to Computers and Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computers and Java Chapter 1.3

  2. A Sip of Java: Outline • History of the Java Language • Applets • A First Java Program • Compiling a Java Program or Class • Running a Java Program • Objects and Methods • A Sample Graphics Applet

  3. History of Java • In 1991, James Gosling and Sun Microsystems began designing a language for home appliances. • In 1994, Gosling realized that his language would be ideal for a Web browser that could run programs over the Internet.

  4. History of Java, cont. • Programs were translated first into an intermediate languagecommon to all appliance processors. • Then the intermediate language was translated into the machine language for a particular appliance’s processor.

  5. Two Kinds of Java Program • applications • meant to be run on your computer • applets • meant to be sent to another location on the Internet and run there

  6. Creating a Java Program or Java Class • A Java program consists of one or more classes, which must be compiled before running the program. • Each class should be in a separate file. • The name of the file should be the same as the name of the class.

  7. Hello World public class HelloWorld { public static void main(String[ ] args) { System.out.println("Hello World!"); } } • In what file should we store this program?

  8. A First Java Application • class FirstProgram

  9. Printing to the Screen System.out.println (“Whatever you want to print”); • System.outis an object for sending output to the screen. • printlnis a method to print whatever is in parentheses to the screen.

  10. Compiling and Running • We will simply use a text editor and a command-line program. • When a Java program is compiled, the byte-code version of the program has the same name, but the ending is changed from.javato .class.

  11. Errors three kinds or errors • syntax errors • runtime errors • logic errors

  12. Syntax Errors • grammatical mistakes in a program • The compiler catches syntax errors and prints an error message. • example: using a period where a program expects a comma

  13. Runtime Errors • errors that are detected when your program is running, but not during compilation • When the computer detects an error, it terminates the program an prints an error message. • example: attempting to divide by 0

  14. Logic Errors • errors that are not detected during compilation or while running, but which cause the program to produce incorrect results • example: an attempt to calculate a Fahrenheit temperature from a Celsius temperature by multiplying by 9/5 and adding 23 instead of 32

More Related