powerpoint 1.txt

  1. In Java, every program must have at least one _______.
  2. The _________________ is where the program starts executing.
    main method
  3. Java is/is not case sensitive.
  4. Every statement ends in a ___________.
  5. Java has logical blocks enclosed by ________.
    curly braces {}
  6. The method block is always included in a ___________ block.
  7. Indentation does/does not affect the execution of a program.
    does not
  8. Indentation does/does not affect the style of a program.
  9. When might it be usefule to use indentation?
    To show nesting structure, in if statements, etc.
  10. What information should be in a header comment?
    • Name of Java Class
    • Author
    • Date
    • Description of the class
  11. List three ways of denoting comments in Java.
    • 1) //
    • 2) /* */
    • 3) /** */
  12. Name and describe the three types of errors.
    • 1) Syntax errors - program cannot compile as something is wrong with your code syntax
    • 2) Runtime errors - program compiles but something goes wrong while it's running
    • 3) Logic errors - hardest to catch, program doesn't do what you wanted it to do
  13. A variable is...
    • a Name
    • for a Place
    • to store a Value
    • of some Type
  14. Variables appear in different structures. List the two types of variables.
    • 1) instance variable - appears within a class/object. Represents the object.
    • 2) (method) variable - appears within a method. A value used in performing an action.
  15. List four of the reasons variables are most frequently used.
    • 1) most recent value (value just read as input)
    • 2) most wanted value (max, min)
    • 3) gatherer (sum, count)
    • 4) temporary
  16. A java identifier (variable) must use only letters, numbers, underscore and $ (but don't use $). T/F
  17. A java identifier (variable) can start with a number. T/F
  18. A java identifier (variable) is case sensitive. T/F
  19. Although java identifiers (variables) cannot be a reserved word, you can use true or false as an identifier. T/F
  20. What is the naming convention for java regarding upper and lower case?
  21. In java, variables are declared before they are used. T/F
    T, but you can declare and instantiate them at the time of their first use.
  22. A type is
    • a Name
    • for a Set of Values
    • or a Set of Operations
  23. Why are types used in programming languages?
    Types are used to make it easier to interpret the meaning of statements.
  24. There are two "types" of variables in java, primitive (simpler than objects), and _______.
    class type - data type for objects in a class
  25. List the primitive data types in java.
    • byte integer 1 byte
    • short integer 2 bytes
    • int integer 4 bytes
    • long integer 8 bytes
    • float real 4 bytes
    • double real 8 bytes
    • char single character 2 bytes
    • boolean 1 bit
  26. Which primitive data types in java would you be comfortable using in most applications?
    int for integers, double for real numbers (numbers with precision).
  27. What is the syntax for casting a variable?
    • (type) expression
    • where type is the desired output type, and expresseion evaluates to a value compatible with that variable type
    • Ex (int)3/5 outputs 0
  28. If a variable is being cast to an integer type (byte, short, int, long), and the expression evaluates to a real number, what value is stored?
    • The fractional part is truncated, the whole number is stored in the variable
    • Ex (int) a = 5/2
    • The value of a is 2
  29. Know the primitive data types.
    • byte integer 1 byte -128 to 127
    • short integer 2 bytes -32,678 to 32,767
    • int integer 4 bytes about -2 billion to +2 billion
    • long integer 8 bytes big enough
    • float real 4 bytes generally big enough
    • double real 8 bytes definitely big enough
    • char single char 2 bytes a single character
    • boolean Boolean values 1 byte True or False
  30. What is the statement used to output something to the screen?
    • System.out.print(expression);
    • System is a class
    • out is a 'special' object of the class System
    • print is a method
  31. How is System.out.println() different from System.out.print()?
    println puts an end-of-line character at the end of the line after outputting it, moving the cursor to a new line
  32. What is the syntax for declaring a named constant?
    • public static final type name = constant;
    • public - can be used 'everywhere'
    • static - there will be only one copy
    • final - the value assigned to this 'variable' will not be changed
    • type - variable type
    • name - variable name (CAPITALIZE)
    • constant = value of constant
  33. Will java let you change the value of a variable that has been declared as a constant?
  34. What is the order of algebraic precedence?
    • ()
    • multiplication division modulo
    • addition subtraction
  35. What is the order of operations?
    • ++,-- pre- and post-fix increment, decrement
    • +,- UNARY +,- (as in making a number negative)
    • ()
    • multiplication division modulo
    • addition subtraction
    • + -----> string concatenation
    • <,<=,>,>=
    • ==, !=
    • = -----> assignment
    • *****When operations are on the same level, they are carried out in order left to right.
  36. What is modulo?
    It is the remainder from division. It can never be larger then the number you are dividing by.
  37. Can increment / decrement operators be used on numbers?
    No, only on variables. But it can be used on integer or real values.
  38. What is the difference from a prefix incremented variable and a postfix incremented variable?
    • Prefix, i.e., ++a, adds one to the value of a, then uses the updated value in the statement.
    • Prefix, i.e., a++, uses the old value in the statement then adds one to the value of a.
  39. When two integers are divided, and the result is stored in an integer-type variable, the result is an _______.
  40. When two integers are divided, and the result is stored in an float-type variable, the result is an _______.
  41. Casting with floats is wierd because floats are capricious. Use this variable type instead: _________.
Card Set
powerpoint 1.txt
Diane cs140 powerpoint1