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 expression 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: _________.
  42. What variable type is used for a collection of characters?
    String (note the capital S)
  43. To determine if the + operator is being used for addition or concatenation, you must move from left to right. As soon as you '+' a String, you change from __________.
    addition to concatenation
  44. Name two methods that are used to convert the case of a String.
    String.toUpperCase(), String.toLowerCase
  45. What string method could you use to find a specified character within a String?
    indexOf(A_String) where A_String is the string you are trying to find. Returns -1 if the string is not found
  46. What string method could you use to find the character that is at a position that you specify?
    charAt(index), where index is the position desired within the string (0 based)
  47. Can you use == to compare Strings?
    No. you must use .equals. E.g. if (dayOfWeek.equals("Tuesday")...
  48. What String method would you use to remove whitespace from beginning and end of a string?
  49. To output single quotes, double quotes, or backslashes within a String, you must use an ____________.
    escape character (typically the backslash) e.g. sout("They call me \"Dragon\"");
  50. Escape characters can be used to format output. What do \n, \r, and \t do?
    • \n - new line
    • \r - carriage return - go to the beginning of the current line
    • \t - tab - add whitespace up to the next tab stop
  51. What methods can you use to get numeric input from the user using the keyboard?
    • nextByte() integer
    • nextShort() integer
    • nextInt() integer
    • nextLong() integer
    • nextFloat() real
    • nextDouble() real
  52. What methods can you use to get string input from the user using the keyboard?
    • next() String
    • nextLine() reads a String from the cursor's current location to the end of the line
  53. What placeholders can you use in printf() for number values?
    • %d for integers
    • %f for float or double (real)
    • %e for floats in scientific notation
  54. What placeholders can you use in printf() for character and string values?
    • %c for char values
    • %s for string values
  55. What placeholders can you use in printf() for boolean values?
  56. How do you specify that the information in a placeholder be left justified?
  57. What does %6.2f do in a printf()?
    • It allocates 6 spaces for a floating point number in the output. The 6 spaces include the decimal point and 2 digits of precision.
    • e.g., 3.5 would be right justified so padded with 2 spaces on the left, then 3.50
  58. What does %-10s do in a printf()?
    It allocates 10 spaces for a string. The output will be left-justified.
  59. What does %2c do in a printf()?
    It allocates 2 spaces for a single character. It will be right justified, so it will be preceded by a space.
Card Set
powerpoint 1.txt
Diane cs140 powerpoint1