Exposure Java Slides

Exposure Java Slides

Exposure Java 2014 Chapter 2 Slides For AP CS Edition Introduction to Java PowerPoint Pre sentation created by: Mr. John L. M. S chram and Mr. Leon S chram Authors of Exp osure Java Section 2.3 A Visit to the

United Nations A Visit to the United Nations At the UN some 200 different languages are spoken. To illustrate the complex task of allowing all of the world leaders to communicate, the example on the next slide simply shows 12 world leaders. Prime Minister David Cameron President Barack Obama United States English President Xi Jinping

China Chinese Prime Minister Mark Rutte Netherlands Dutch President English Franois Hollande Great France Britain French For example: President Obama would need different translators for Dutch, President Juan Manuel Santos

Colombia Spanish President Vladimir Putin Russia Russian German, Spanish, French, Italian, Russian, Chinese, Japanese, and Prime Minister Shinz Abe Japan Japanese Afrikaans. President Joachim Gauck Germany German

President Giorgio Napolitano Italy Italian President Jacob Zuma South Africa Afrikaans President Enrique Pea Nieto Mexico Spanish Prime Minister David Cameron

President Barack Obama United States English President Xi Jinping China Chinese Prime Minister Mark Rutte Netherlands Dutch President English Franois Hollande Great France Britain French

With 200 world leaders, if we want to be able to translate instantly (as in one single step) from any President Juan Manuel Santos Colombia Spanish President Vladimir Putin Russia Russian language to any other language about 20,000 translators would be Prime Minister Shinz Abe Japan Japanese

needed. President Joachim Gauck Germany German President Giorgio Napolitano Italy Italian President Jacob Zuma South Africa Afrikaans President Enrique Pea Nieto Mexico

Spanish Prime Minister David Cameron President Barack Obama United States English President Juan Manuel Santos Colombia Spanish President Vladimir Putin Russia Russian

President Xi Jinping China Chinese Prime Minister Mark Rutte Netherlands Dutch President English Franois Hollande Great France Britain French The solution is not to try to translate in one step, but to allow the translation to occur in two steps. Every world leader brings one

translator that knows their native language, and English. President Joachim Gauck Germany German President Giorgio Napolitano Italy Italian President Jacob Zuma South Africa Afrikaans Prime Minister Shinz Abe

Japan Japanese President Enrique Pea Nieto Mexico Spanish Prime Minister David Cameron President Barack Obama United States English President Xi Jinping China Chinese

Prime Minister Mark Rutte Netherlands Dutch Translator Translator President Juan Manuel Santos Colombia Spanish President Vladimir Putin Russia Russian Translator Translator President

Joachim Gauck Germany German President English Franois Hollande Great France Britain French Translator Translator H S I L G

EN Translator President Giorgio Napolitano Italy Italian Translator Translator Translator President Jacob Zuma South Africa Afrikaans Prime Minister Shinz Abe Japan Japanese

President Enrique Pea Nieto Mexico Spanish Section 2.4 Java Bytecode What does the UN have to do with Java? Compiler BY MAC Interpreter E D

O C TE Compaq Interpreter HP Interpreter Platform Independence A programming language is considered platform independent or portable if program source code created on one type of computer platform can execute on another computer platform without any difficulty. Bytecode Bytecode is a low level-level code file that cannot execute as a regular machine code file.

Bytecode is understood, and executed, by a Java interpreter, called a Java Virtual Machine (JVM). Java Uses a Compiler AND an Interpreter Java uses a compiler to translate the program source code (.java file created by the programmer) into bytecode (.class file). Java then continues and uses an interpreter to translate the bytecode into machine code line by line during execution. Section 2.5 Applications and Applets Applet or Application? A Java program designed to operate inside a web page is called an applet.

A Java program designed to operate in a stand-alone environment is called an application. Section 2.6 Using Java Software The Basic Java Tools A text editor to write Java program source code. A compiler to translate source code into bytecode. An interpreter to translate and execute bytecode. Important Java IDEs Note Separate files are provided for installing Java software. The Java JDK and JRE come from Oracle. There are many choices for an IDE, such as: jGRASP, BlueJ, DrJava, Eclipse,

JBuilder, NetBeans, JCreator JRE vs. JDK Many computers may already have the Java Runtime Environment (JRE) installed. This allows you to execute Java programs, but it does not allow you to compile them. This is why we need to install the Java Development Kit. With the JDK, we can do both. Instructions on how to install the Java software are provided in a special PowerPoint presentation in the InstallingJava folder. Remember that jGRASP will not function unless the JDK (Java Development Kit) is installed first. Instructions on how to install the Java software are provided in 3 different PowerPoint presentations. If necessary, your teacher will tell you which to use. Remember that JCreator will not function unless the

JDK (Java Development Kit) is installed first. Section 2.7 Text Output With print & println // Java0201.java // This program demonstrates text output with println. // Note how the file name, Java0201, is the same as the // class identifier Java0201. // Make sure that you observe "case-sensitivity". public class Java0201 { public static void main (String[] args) { System.out.println("Hello World!"); } }

Hello World! Remember to Re-Compile! After any change to a program, no matter how small, you must recompile the program before testing the execution! Java Keywords and Program Statements A Java keyword is a word that has a special meaning in the program or performs a special function. One or more keywords combine to make a program statement. Keywords in Java are case-sensitive. This means that System is a Java keyword, which is not the same as system. // Java0202.java // This program demonstrates how to display four lines of text

// using the keyword. public class Java0202 { public static void main(String[] args) { System.out.println("Line 1"); System.out.println("Line 2"); System.out.println("Line 3"); System.out.println("Line 4"); } } Line Line Line Line 1 2 3 4

// Java0203.java // This program demonstrates the difference between // and . The command adds a // "line feed" after the output display. public class Java0203 { public static void main(String[] args) { System.out.print("Line 1"); System.out.print("Line 2"); System.out.println("Line 3"); System.out.println("Line 4"); } Line 1Line 2Line 3 } Line 4 // Java0204.java // This program shows how to skip a line between statements.

// Using with empty parentheses will generate // a carriage-return/line-feed. public class Java0204 { public static void main (String[] args) { System.out.println("Text Output on Line 1"); System.out.println(); System.out.println("Text Output on Line 3"); } Text Output on Line 1 } Text Output on Line 3 System.out.print & System.out.println Both keywords println and print generate an output display of characters contained between double quotes. Both println and print follow keywords System.out. println("Java is an island in Indonesia.") will display:

Java is an island in Indonesia. print("Java is an island in Indonesia.") will also display: Java is an island in Indonesia. The keyword println generates display followed by a carriage-return/linefeed (CRLF). The keyword print generates display without a crlf. The statement System.out.println(); generates a crlf, meaning skip a line, without any other display. Section 2.8 Program Compile Errors // Java0205.java // This program demonstrates that the file name of a program // and the public class name must be identical. // This program will not compile. public class Boohiss { public static void main (String[] args)

{ System.out.println("The bytecode file name"); System.out.println("will be the same as the"); System.out.println("public class identifier."); } } File Names and Class Names The external file name of your program needs to be identical to the public class name inside your program, minus the java extension. For example: If you use public class Howdy in your program then you need to save the program with the file name Howdy.java // Java0206.java // This program has an intentional mistake. // The output window indicates an error and the program does not execute. // Many error messages provide important clues to help fix the problem.

Here is the e A semicolon (;) is public class Java0206 { public static void main (String[] args) { System.out.println("In English..."); System.out.println("Every sentence ends with a period (.)"); System.out.println("In Java...") System.out.println("Every statement ends with a semicolon (;)"); } } 01 02 03 04 05 06

07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 // Java0206.java // This program has an intentional mistake. // The output window indicates an error and the program does not execute. // Many error messages provide important clues to help fix the problem. public class Java0206

{ public static void main (String[] args) { System.out.println("In English..."); System.out.println("Every sentence ends with a period (.)"); System.out.println("In Java...") System.out.println("Every statement ends with a semicolon (;)"); } } NOTE: The error message indicat where the error was found 01 02 03 04 05 06 07 08

09 10 11 12 13 14 15 16 17 18 19 20 21 // Java0206.java // This program has an intentional mistake. // The output window indicates an error and the program does not execute. // Many error messages provide important clues to help fix the problem. public class Java0206 { public static void main (String[] args)

{ System.out.println("In English..."); System.out.println("Every sentence ends with a period (.)"); System.out.println("In Java...") System.out.println("Every statement ends with a semicolon (;)"); } } It even indicates the exact line nu Section 2.9 Program Comments // Java0207.java // This program displays several number words. // The focus now is on program comments. // Program comments aid in "program documentation" and make your program more readable. // Every line that begins with a "double slash" is considered a "comment" by the Java compiler. // The Java compiler ignores all comments. They are not compiled. They are not executed.

// If a line begins with a double slash, it is simply ignored by the compiler. // That is precisely what is happening with the first 12 lines of this program. // Note below that a comment can also be placed in the middle of the program. // They can even be placed right after a program statement on the same line. // Note: The word "Thirteen" is not displayed because it has been "commented-out" // possibly by someone suffering from Triskaidekaphobia (the fear of the number 13). public class Java0207 { public static void main (String[] args) { System.out.println("One"); System.out.println("Two"); System.out.println("Three"); System.out.println("Four"); System.out.println("Five"); System.out.println("Six"); // half a dozen System.out.println("Seven"); System.out.println("Eight"); System.out.println("Nine"); System.out.println("Ten");

System.out.println("Eleven"); System.out.println("Twelve"); // one dozen // System.out.println("Thirteen"); // one baker's dozen } } One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve // Java0208.java

/* This program is very similar to the previous program, but the output will be different. Instead of displaying all number words from "One" through "Thirteen", it will only display some of them. There are actually 2 kinds of comments in Java. "Single-Line Comments" are the type you saw in the last program. They begin with a double slash. Java also has "Multi-Line Comments". To create a multi-line comment, you begin with a slash and an asterisk. You conclude a multi-line comment with an asterisk followed by a slash. This can be very useful in program development. This time the output will not show the words "Seven" through "Eleven" because they have been "commented-out" with a multi-line comment. */ public class Java0208 { public static void main (String[] args) { System.out.println("One"); System.out.println("Two"); System.out.println("Three"); System.out.println("Four"); System.out.println("Five"); System.out.println("Six"); // half a dozen

/* System.out.println("Seven"); System.out.println("Eight"); System.out.println("Nine"); System.out.println("Ten"); System.out.println("Eleven"); */ System.out.println("Twelve"); // one dozen System.out.println("Thirteen"); // one baker's dozen } } One Two Three Four Five Six Twelve Thirteen

/********************************* * Java Program 0209 * * Numbers from 1-13 * * By: John Schram * * 9/12/14 * * * * This program is similar to * * the previous two and shows * * that a comment can be used *

* to create a heading. * *********************************/ public class Java0209 { public static void main (String args[]) { System.out.println("One"); System.out.println("Two"); System.out.println("Three"); System.out.println("Four"); System.out.println("Five"); System.out.println("Six"); // half a dozen System.out.println("Seven"); System.out.println("Eight"); System.out.println("Nine"); System.out.println("Ten"); System.out.println("Eleven"); System.out.println("Twelve"); // one dozen System.out.println("Thirteen"); // one baker's dozen

} } One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen /********************************* * Java Program 0209 *

* Numbers from 1-13 * * By: John Schram * * 9/12/14 * * * * This program is similar to * * the previous two and shows * * that a comment can be used * * to create a heading. * *********************************/ public class Java0209

{ public static void main (String args[]) TRY THIS! { System.out.println("One"); Remove this slash (/) and see what System.out.println("Two"); System.out.println("Three"); happens to the program. System.out.println("Four"); System.out.println("Five"); Remember to put the slash back. System.out.println("Six"); // half a dozen System.out.println("Seven"); System.out.println("Eight"); System.out.println("Nine"); System.out.println("Ten"); System.out.println("Eleven"); System.out.println("Twelve"); // one dozen System.out.println("Thirteen"); // one baker's dozen } }

/********************************* * Java Program 0209 * * Numbers from 1-13 * * By: John Schram * * 9/12/14 * * * * This program is similar to * * the previous two and shows * * that a comment can be used

* * to create a heading. * ********************************* public class Java0209 { public static void main (String[] args) { System.out.println("One"); System.out.println("Two"); System.out.println("Three"); System.out.println("Four"); System.out.println("Five"); System.out.println("Six"); // half a dozen System.out.println("Seven"); System.out.println("Eight"); System.out.println("Nine"); System.out.println("Ten"); System.out.println("Eleven"); System.out.println("Twelve"); // one dozen

System.out.println("Thirteen"); // one baker's dozen } } The comment was never ended So the entire program is now one big comment. 2 Different Types of Comments // This is a single-line comment. System.out.println("Hello!"); /* This is // So is this. /***************** a multi-line

* comment. */ *****************/ So is this. * Section 2.10 Escape Sequences // Java0210.java Program Java0210.java // This program demonstrates escape sequences in Java

ONE TWO THREE public class Java0210 { Paul Programmer is rotten and needs to be thrown public static void main (String[] args) John { Path C:\Java\bin // \n performs a carriage-return and a line-feed Java0210.java\n"); Enter System.out.println("\nProgram the name "Kathy Smith" with double quotes

' // \t performs a horizontal tab System.out.println("\tONE\tTWO\tTHREE\n"); // \r performs only a carriage-return without a line-feed System.out.print("That watermelon is rotten and needs to be thrown out.\r"); System.out.println("Paul Programmer\n"); // \b performs a backspace System.out.println("Joa\bhn \n"); // \\ displays a single backslash System.out.println("Path C:\\Java\\bin\n"); // \" displays double quotes System.out.println("Enter the name \"Kathy Smith\" with double quotes\n"); // \' displays a single quote System.out.println('\''); } } out.

Section 2.11 The AP Java Subset The AP Java Subset The College Board works together with Educational Testing Service to create the AP Computer Science Examination. In an effort to create a standardized test for all students, the College Board and ETS have created an AP Java Subset. The AP Java Subset created by the Test Development Committee of the College Board does not dictate what should be taught in an AP Computer Science course. The AP Java Subset indicates what will be tested. Section 2.12 The Responsible Use

of Computers Protect Your Computer From the Environment Computers and computer information are vulnerable. Computers can be physically damaged. RAM is temporary, save often! Disk, CDs and even hard drives can go bad. Back up your stuff! Blackouts and Power Surges are major problems. Backup Batteries and Surge Protectors are useful. Protect Your Computer From Viruses A virus is a special program that has these two qualities: The ability to duplicate itself

to spread to other systems. The payload it carries, which is a program that will do some type harm to the computer. Protect Your Computer From Improper Access Don't leave your computer unattended and logged in. Information can easily be copied or erased from an unattended computer. Unattended laptops are easily stolen.

Label and guard your stuff! The Ethical Use of Computer Software Copying copyrighted software is illegal. Companies have been sued and people have been arrested for not taking this seriously. Hacking Some confused people think that if you hack into a network, it is fine as long as you don't steal any money or damage any information. WRONG! Just attempting to hack into a computer or network is a misdemeanor. If you actually succeed at getting in, you have already committed a felony.

Yes, high school students have been prosecuted for this! Vandalism Physical computer vandalism is bad, but typically not a problem in high school. You also need to make sure you do not alter ANY settings on the computer or install ANY software unless directed to do so by your teacher. Altering settings can prevent the computer from working properly. Downloading software has legal issues and can also cause the spread of viruses.

Recently Viewed Presentations

  • Wellness - Oregon

    Wellness - Oregon

    Extra Duty Pay(Headmaster's Holiday) Participation in the Wellness course is above and beyond the expectation of North Wasco, of the WOU class. ... DUMAS Sheli - ODE ...
  • Effective Web Searching Strategies - users.miamioh.edu

    Effective Web Searching Strategies - users.miamioh.edu

    Effective Web Searching Strategies John J. Burke, MSLS Ohio Library Support Staff Institute August 4, 2003
  • Acheronte: Nuovo Flusso di Caronte

    Acheronte: Nuovo Flusso di Caronte

    Marco D. Santambrogio: [email protected] Simone Campanoni: [email protected] * Outline Introduction to ILP (a short reminder) VLIW architecture Beyond CPI = 1 Initial goal to achieve CPI = 1 Can we improve beyond this?
  • Introduction to Soils

    Introduction to Soils

    Overview. The purpose of this lesson is to familiarize you, the student, with the classifications, testing procedures, stabilization methods, and dust abatement methods used for soils.
  • 2 and 20 - Home Page | CoastWatch-West Coast

    2 and 20 - Home Page | CoastWatch-West Coast

    NCEI Requirements. Document your data (CF and ACDD, ISO 19115). Format your data (Gridded: .nc, Tabular: .ncCFMA). Ensure data integrity (.sha256). Organize your data (.tar.gz). Archive your data at NCEI (Send2NCEI or ATRAC). NCEI will make it accessible - Metadata...
  • ICT E-SAFETY EVENING - Archibald First School

    ICT E-SAFETY EVENING - Archibald First School

    ICT E-SAFETY ARCHIBALD FIRST SCHOOL ICT Mark Only the 2nd school in Newcastle LA to achieve the award: October 2009 Achieved the award for a second time: October 2012 One of only 785 Primary Schools nationwide to have the award...
  • Other Minds - Michael Johnson

    Other Minds - Michael Johnson

    This would be silly in the first-person case. ... then you know you have hands. The problem of other minds asks: what justifies you in believing other people have minds? Unusual Justification. If there is a justification, it can't be...
  • ATRIAL ESOPHAGEAL FISTULA SECONDARY TO ABLATION FOR ATRIAL

    ATRIAL ESOPHAGEAL FISTULA SECONDARY TO ABLATION FOR ATRIAL

    1University of South Caroline School of Medicine Greenville, Greenville, SC ; 2Division of Thoracic Surgery, Greenville Health System, Greenville, SC. Background. In an era where atrial fibrillation (AF) is increasingly diagnosed, catheter ablation has become the preferred treatment in patients...