introduction to computers and java chapter 1.3. a sip of java: outline history of the java language...
TRANSCRIPT
![Page 1: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/1.jpg)
Introduction to Computers and Java
Chapter 1.3
![Page 2: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/2.jpg)
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
![Page 3: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/3.jpg)
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.
![Page 4: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/4.jpg)
History of Java, cont.
• Programs were translated first into an intermediate language common to all appliance processors.
• Then the intermediate language was translated into the machine language for a particular appliance’s processor.
![Page 5: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/5.jpg)
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
![Page 6: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/6.jpg)
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.
![Page 7: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/7.jpg)
Hello World
public class HelloWorld{ public static void main(String[ ] args) { System.out.println("Hello World!"); }}• In what file should we store this program?
![Page 8: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/8.jpg)
A First Java Application• class FirstProgram
![Page 9: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/9.jpg)
Printing to the Screen
System.out.println (“Whatever you want to print”);
• System.out is an object for sending output to the screen.
• println is a method to print whatever is in parentheses to the screen.
![Page 10: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/10.jpg)
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 .java to .class.
![Page 11: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/11.jpg)
Errors
three kinds or errors1. syntax errors
2. runtime errors
3. logic errors
![Page 12: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/12.jpg)
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
![Page 13: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/13.jpg)
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
![Page 14: 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](https://reader036.vdocuments.us/reader036/viewer/2022082820/56649e9c5503460f94b9d30d/html5/thumbnails/14.jpg)
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