To Lecture Notes

IT 313 -- Jan 14, 2020

Review Exercises

  1. What does the IntelliJ shortcut psvm mean?
    Ans: public static void main
  2. Use method calls needed to convert between these datatypes: String, int, double, char. A complete answer lists 4 * (4 - 1) = 12 method calls. You already know how to convert from String to int (Integer.parseInt) and from String to double (Double.parseDouble). Ans:
      You can use casts to convert one numeric type to another. For example:
    double x = 65.3782732;
    int n = (int) x;
    char c = (char) n;
    
    char counts as a numeric type because it contains the Unicode numeric code of a character.
    Ans: Here is a diagram of the methods needed to convert between the datatypes String, int, double, char. Here are the meanings of the arrow labels:
    1: Integer.parseInt
    2: Double.parseDouble
    c: Use cast, for example  int n = (int) x;
    v: Use String.valueOf
    *: char ch = s.charAt(0);
  3. Define these object oriented programming terms:
        class   instance variable   local variable   instance method   constructor
    Ans:
    object:   a person, account, organization, ledger line, vehicle, or other entity that contains data and has methods for performing actions.
    class:   The blueprint or design from which objects are created (instantiated).
    local variable:   a variable that is only defined within the method where it is declared.
    instance variable:   a variable that is defined anywhere within the class where it is declared.
    An instance variable can be public (accessable anywhere) or private (only accessable in the class where it is declared). An instance variable is always called by an object.
    static variable:   a variable that is called from a class (not an object).
    constructor:   A special method that creates an object. A constructor is called using the new operator.
    startup method:   The first method that starts running when a Java class file is executed.
    Java startup methods are always called main.
  4. Look up the String class in the Java 11 Documentation. Select and test five String methods. Ans:
     public class Main {
        public static void main(String[ ] args) {
    
            // Test these String methods:
            // indexOf isBlank isEmpty length toUpperCase
    
            String s = "umbrella";
            String t = " \n \t ";
            String u = "";
    
            System.out.println(s.indexOf("bre"));
            // Output: 2
    
            System.out.println(s.isBlank( ) + " " +
                t.isBlank( ) + " " + u.isBlank( ));
            // Output: false true true
    
            System.out.println(s.isEmpty( ) + " " +
                t.isEmpty( ) + " " + u.isEmpty( ));
            // Output: false false true
    
            System.out.println(s.length( ) + " " +
                t.length( ) + " " + u.length( ));
            // Output: 8 5 0
    
            System.out.println(s.toUpperCase( ));
            // Output: UMBRELLA
        }
    }

Built In Classes and Methods

For Loops

Project 2a

Defining and Using Arrays

Sequential Processing