1. Logistics & Setup

    • Welcome Introduction to Java Programming! The course website: http://computerscience.qvsd.org
    • Schoology: For end of chapter quizzes we will utilize Schoology
    • Server Accounts: ftp://computerscience.qvsd.org Filezilla: Download Filezilla Filezilla settings Directions for connecting to filezilla are within Schoology.
    • IDEs for Java (Integrated Development Environment): Textpad; Sublime; Eclipse -- We will utilize Textpad 8 on the computers in the lab
    • More IDEs: Repl.it (java compiler) -- Sign Up using QV mail account (More on this later)
      The name REPL stands for Read-Eval-Print-Loop - an interactive, typically console-based, programming environment but online (ipad)!
    • Notes and Coding: We will utilize the following book for the course: Java programming however I have created the following notes to
      Copy, Visualize and sometimes sample Run the code examples.
    • You MUST stay organized in saving/storing files throughout course!

    • We will code all these examples in Textpad.

      Note: You might need to type or modify the code when utilize the visualization buttons within each code snippet.
      Students should type all programs into Textpad save them as the correct name, compile and run each program.

    1. First order of business is create a Chapter 1 folder on your desktop to save all your documents for Chapter 1 within this folder
    2. Click on desktop, right click, choose New, choose Folder. Name the Folder Java. (Looks like this)

    3. Second, download the pdf book and save it within the java folder you created. Right click and choose 'save as' on the book link: Java programming Book (Looks like this)

    4. Third, turn on Textpad Comments: To turn on comments within Textpad you need to check the correct box.
    5. Open Textpad--->Configure---->Preferences---->View (on left side)---->Line Numbers (Check box on right side)--->Click Apply & then Ok.

    6. Fourth, favorite the course website. Navigate to http://computerscience.qvsd.org and save this URL to your favorites.


    Line Numbers & Comments in Textpad
    <---Each Java document starts with line number 1 and continue down left side, 2, 3, etc...   <--- These are LINE NUMBERS for tracking/discussing code!   <--- They do not effect the code nor execute - only for programmer!


  2. Hello World

    public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
  3. Your First Program: Do for each program

    For each Java Program you need to type the program and then compile the program so the computer understands machine language to execute the program.

    Java Source Code you write (saved as .java)---->Compile Program (into .class file)
    Compiler creates bytecode that is stored with the .class extension & java virtual machine/interpreter executes the file.

    File----->Save as---->name the file and add the .java extension. (Change the type to 'All Files).
    Tools--->Compile Java (You will receive a notice in the Tool output if successful or errors).
    Tools--->Run Java Application (Your program will execute).
  4. Comments


    Comments: End of Line
    public class MyCode { public static void main(String[] args) { System.out.println("Howdy!"); // this is an end-of-line comment <--- Single Comment // (but not a very good one!) <--- Single Comment // The next line is commented out, so it is ignored!<--- Single Comment // System.out.println("This will be ignored");<--- Single Comment System.out.println("And howdy on line #2"); } }
  5. Comments: Block
    public class MyCode { public static void main(String[] args) { System.out.println("Howdy!"); /* The preceding comments end at the end of the line, but this<--- Block Comments (Multiple Lines) is a block comment, started with a slash-star, which will continue <--- Block Comments (Multiple Lines) across new lines until a star-slash (on the next line):<--- Block Comments (Multiple Lines) */<--- Block Comments (Multiple Lines) System.out.println("And howdy on line #2"); /* another block comment! */ } }
  6. Error Types

    Error: Syntax Error (Compile-Time Errors) Misspellings
    public class MyCode { public static void main(String[] args) { System.out.println("Uh oh!); // ERROR! missing close-quote } }
    Compiler output:
    MyCode.java:3: unclosed string literal
    System.out.println("Uh oh!); // ERROR! missing close-quote


  7. Error: Runtime Error (Crash) (Program does NOT Run!)
    public class MyCode { public static void main(String[] args) { System.out.println(1/0); // ERROR! Division by zero! } }
    Runtime (Console) output:
    Exception in thread "main" java.lang.ArithmeticException: / by zero
    at MyCode.main(Foo.java:3)

    Error: Logical Error (Compiles & Runs, but is WRONG!) DOESN'T MAKE SENSE!
    public class MyCode { public static void main(String[] args) { System.out.println("2+2=5"); // ERROR! Untrue!!! } }
    Runtime (Console) output:
    2+2=5
  8. Basic Console Output: Print vs Println, Numbers & Strings

    print vs println
    public class MyCode { public static void main(String[] args) { System.out.print("This is"); // Line 3 & 4 are different System.out.print("a test"); System.out.println("that will run, albeit"); // than Lines 5, 6 & 7 System.out.println(); System.out.println("with some problems..."); // Print outputs whats in quotes and cursor remains on same line // Println output whats in quotes and cursor goes to next line. } }
  9. Printing Numbers (not Strings)
    public class MyCode { public static void main(String[] args) { System.out.println(1); // prints the number one System.out.println(1 + 2); // prints the sum of one plus two } }
    Printing Numbers and Strings
    public class MyCode { public static void main(String[] args) { System.out.println("1 + 2 = " + (1 + 2)); System.out.println("1 + 2 = " + 1 + 2); // Surprised? } }
  10. Variables and Expressions

    public class MyCode { public static void main(String[] args) { int x = 5; int y = 3; int sum = x + y; System.out.print(x); System.out.print("+"); System.out.print(y); System.out.print("="); System.out.println(sum); } }
    Once again, but more concisely:
    class class MyCode { public static void main(String[] args) { int x = 5; int y = 3; int sum = x + y; System.out.println(x + "+" + y + "=" + sum); } }
  11. Basic Console Input

    import java.util.Scanner;// Notice Import Statement for keyboard input public class MyCode { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Scanner used for keyboard input System.out.println("Enter an integer for x: "); int x = scanner.nextInt();// integer variable x stored input answer System.out.println("Enter an integer for y: "); int y = scanner.nextInt();// integer variable y stored input answer int sum = x + y; System.out.println(x + "+" + y + "=" + sum); // Output sum of x plus y } }
    Once again, but with nicer prompts and more operators:
    import java.util.Scanner; public class MyCode { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter an integer: "); int x = scanner.nextInt(); System.out.print("Enter another integer: "); int y = scanner.nextInt(); int sum = x + y; System.out.println(x + "+" + y + "=" + sum); int difference = x - y; System.out.println(x + "-" + y + "=" + difference); int product = x * y; System.out.println(x + "*" + y + "=" + product); int quotient = x / y; System.out.println(x + "/" + y + "=" + quotient); int remainder = x % y; System.out.println(x + "%" + y + "=" + remainder); } }
Are you READY to move foward? Ask yourself, DID YOU?

  1. Create a folder named Java on your desktop?
  2. Download the book and save it to your java folder?
  3. Turn on Line numbers in Textpad?
  4. Favorite Dr. Mariano's website: http://computerscience.qvsd.org in your web broswer?
  5. Read, type/copy code, compile--->execute and understand this page of notes?
If you can answer YES, to each of these question, you are READY to move FORWARD, otherwise, go back
to the top of the page and read/follow directions to complete each of these tasks!
If YES, your ready to start with the course!
Welcome to Introduction to Java Programming!