arrowThe Left Navigation Bar:
Links to examples, tutorials, web tools, downloads, & more (possibly useful) information.


 
This is a list of programming/problem solving concepts that you need to "own" as your set of "knowledge tools" that you will bring with you to Programming II (CS 200).

This list can also serve as a checklist for your success with the Progamming I (CS 200) Final Exam.

blocks

THE LIST:

  1. Programming Rule #1! The processing of programming commands is linear.
    Thus, you cannot use a variable until you have made storage space for the value, and you cannot perform calculations on variables until usable data has be placed in those variable's storage space.
    - F. Porps
  2. The information processing cycle of the CPU (Central Processing Unit) reinforces Programming Rule #1!
    The Control unit of the CPU fetches and decodes an instruction and then the ALU (Arithmetic and Logic Unit) executes the command. This process is then repeated with the next instruction, etc. until the program is terminated.
    - J. Anderson
  3. General programming form:
    Step 1: Declare variables (make storage space for data)
    Step 2: Explain the program to the user via output display
    Step 3: Prompt for (output display) and get input (from keyboard) from the user
    Step 4: Perform the required computational tasks on the data
    Step 5: Display the results of the computation via output display
    - L. Maneva
  4. Algorithms must be linear and precise (no step missing a detail).
    Algorithms can be expressed in pseudocode (English-like statements), in the form of a flow chart (graphical display of the process), or in programming language.
    - M. Ford
  5. Flowcharting illustrates the linear flow of the process from start to stop.
    The elongated oval notes the start and stop of the process, and arrows are used to show the direction of the flow from start to stop.
    The rectangle is used to note a computational process, for example, c = a + b.
    The parallelogram is used for note data input and outputs (prompts for data, and display of information as the result of processing data).
    The diamond is used for a decision, and two arrows will flow from the this shape, one noting if the conditional statement is true, and another path if it is false. The diamond is used for branching, and for the stopping condition in a loop structure.
    See illustration of symbols...
    - H. Patel
  6. When solving a difficult problem, break it into smaller parts that are easier to manage and solve them one at a time.
    This makes working easier while actively solving the problem, but the separate parts will be easy to trace later (when you or anyone else needs to review the program). Your program will be especially easy to trace if you properly format your code with indentation, line spacing and useful comments.
    - J. Anderson
  7. Key words are words that have a special meaning in a programming language. They may be used for their intended purpose only.
    Key words are also known as reserved words.
    See the list of Java reserved words.
    - C. Perea
  8. The semi-colon (;) is used to mark the end of a statement in Java.
    They are NOT used with decision structures (if-else) or repetition structures (for and while) as placing one at the end of these statements will cause an "empty statement" to be processed.
    The semi-colon is found at the end of a do/while loop, though.
    - C. Perea
  9. In order to reinforce Programming Rule #1, objects, variables and constants should be declared at the start of the main body of the program.
    It is in good programming form, as you can verify that you have declared appropriate storage space with a quick glance at the start of the code.
    - M. Ford
  10. What's the difference between a variable and an identifier?
    The difference between a variable and an identifier is that the variable is the thing that holds data (memory storage space), whereas the identifier is the name defined by the programmer to label/reference that data being held in storage. Note: Identifiers are also used to label constants, parts of a program, and the file itself.
    - J. Anderson
  11. A variable's identifier should be descriptive of what the variable contains
    (e.g. a 'double' that holds the width of something would be appropriately called 'dWidth' rather than 'x').
    - J. Anderson
  12. variable ranking chart
  13. Remember that you can go from a lower ranking data type (int) to a higher data type (float), it's called widening conversion, but not the other way around.
     
    And on that note, remember to check your data types when writing a program as trying to use one with another can cause logical errors due to numbers being truncated when you don't want them to be.
    -G. Kasmer (CS 200 alumnus)
  14. Comments are used by programmers to leave notes about the code process for themselves or others who may modify the code.
    //Single line comment (may be placed after a Java command on the same line)
    /*comment marked to span
    multiple lines*/
    Comments are not read by the compiler.
    - M. Ford
  15. Java is case sensitive.
    int a = 3;
    int A = 5;
    System.out.print(a + "A" + A); //The middle U.C. "A" is a String literal, and not a variable.
    output:
    3A5
    - M. Ford
  16. An API is a pre-written library of classes for use in programs.
    API is short for Application Programming Interface. The API contains methods for commonly used programming tasks, and expand the functionality of the programming language. For example, the String class is an API that we use very often in our programs. Note: The String class is part of the Java.lang API and is imported by default into our programs, thus, no "import" statement is required.
    Learn more...
    - M. Ford
  17. Another useful API is the Scanner class, when a program requires input from the user at the keyboard.
    The Scanner class requires an import statement: import java.util.Scanner;
    The import statement is written outside and above the public class.
    To use the Scanner for keyboard input, the object must be created:
    Scanner keyboard = new Scanner(System.in);
    The identifier "keyboard" may then be used with pre-written methods also found within the Scanner class to get specific types of data from keyboard input.
    Learn more about the Scanner class and its pre-written methods for data input from the keyboard...
    - S. Miller
  18. A prompt is an output statement to the user.
    Utilize descriptive and "user friendly" prompts when asking the user to enter data.
    If you need the user to provide a positive integer value, don't just ask for a number, instead:
    System.out.println("Please enter a POSITIVE INTEGER value: ");
    - A. Guerrero
  19. Strings are stored as a series of characters.
    The first character in a string is at index (0). The length method counts the spaces (alpha characters, spaces, and non-alpha characters) starting with the number 1.
    - M. Ford
  20. The char data type stores a single character value as can be seen in the ASCII table.
    Example:
    char letter; //variable declaration
    letter = 'A' ; //variable initialization of the character literal uppercase A - note the single quotes (') are used to mark char literals.
    - C. Perea
  21. Escape sequences are used as part of a String to display special characters that are reserved for coding like the single and double quotes, and plus sign.
    Here is a partial list of commonly used escape sequences:
    \' single quote
    \n advances cursor to a new line
    \" causes double quote
    \+ horizontal tab
    \b backspace
    \r return to start of current line
    \\ backslash printed
    - M. Ford
  22. The empty string is a string with zero characters and is written as a pair of adjacent double quotes, like so: "". Note that the string " " is not empty, because it consists of one blank character.
    - L. Maneva
  23. When the + operator is used with strings, it is known has the string concatenation operator.
    Concatenate means to append, so the string concatenation operator appends one string to another.
     
    Example 1:
    int number = 5;
    int anotherNumber =2;
    System.out.println("The value is " + number);
    The output displayed will be: The value is 5
    Although number is not a string, the + operator converts its value to a string and then concatenates that value with the first string.
     
    Example 2:
    int number = 5;
    int anotherNumber =2;
    System.out.println("The value is " + number + anotherNumber);
    The output displayed will be: The value is 52
    Again, the + operator is being used as a string concatenator, because of the initial "The value is" string that is included as part of the output. To actually add number and another number use parenthesis in the output statement like this:
    System.out.println("The value is " + (number + anotherNumber) );
    instead.
     
    Example 3:
    int number = 5;
    int anotherNumber =2;
    System.out.println(number + anotherNumber);
    The output displayed will be: 7
    since there is no string to start the output, the + operator is treated as the addition operator in this example.
    - C. Perea
  24. print vs. println!
    Print prints output and leaves cursor on the same line. Println prints and then moves cursor to the start of the next line.
    example of print:
    int a = 3;
    int b = 4;
    System.out.print( a );
    System.out.print( b );
    output:
    34
     
    example of println:
    a = 3;
    b = 4;
    System.out.println( a );
    System.out.println( b );
    output:
    3
    4
    - M. Ford
  25. The Decimal Format Class allows for the creation of a formatting template for output.
    # // A number of any number of characters can be placed where the # is
    0 // a place holder for a single character
    , // outputs a comma symbol
    $ // outputs the dollar sign
    % // converts value to a percentage ( *100) and outputs the percent symbol
    Example for money formatting:
    DecimalFormat formatter1 = new DecimalFormat("$#.00");
    double number = 321.760304;
    System.out.println(formatter1.format(number));
    Output:
    $321.76
    - K. Blanchette
  26. The printf method allows for formatted output, too.
    Examples:
    double number = 21.5;
    System.out.printf("%7.3f", number);
    //Output: 21.500
    //A space is added in front of the 2 because %7.3f formats the output to hold 7 characters and 3 digits after the decimal point
    The other format specifiers are:
    %5c // Outputs a character in a field of 5 spaces (holds 5 characters)
    %5d// Outputs a decimal integer in a field of 5 spaces (holds 5 characters)
    %e// Outputs in exponential format: 5.000000e+00
    %5s// Outputs a string in a field of 5 spaces (holds 5 characters)
    - K. Blanchette
  27. A byte the smallest addressable unit, collection of 8 binary digits (bits).
    The primitive data-type 'byte' can hold 256 unique values, ranging from -128 to 127.
    - J. Anderson
  28. Two's Complement Method:
    Integers are stored using fixed point binary representation. If the number is positive, you have only to convert it to binary. If it's negative, you have to convert its positive equivalent to binary, flip all 0's to 1's and 1's to 0's, then add 1.
     
    Examples using byte datatype (8 bits):
    byte x = 39;
    39 converts to 100111 in binary,
    stored as: 00100111 (padding of leading zeros is needed to fill storage)
    byte x = -39;
    -39 converts to 00100111 in binary,
    flip bits: 11011000
    add 1: 00000001
    stored as: 11011001
    - J. Anderson
  29. Math Operator Precedence Rules: from highest to lowest precedence.
    The unary operators: +, -, !, ++, and –
    The binary arithmetic operators: *, /, and %
    The binary arithmetic operators: +, and -
    Operators that are higher on the list are said to have higher precedence. When the order is not dictated by parentheses, the computation begins with the operation having higher precedence and then performs the one having lower precedence. Some operators have equal precedence, in which case the order of operations is determined by where the operators appear in the expression. Binary operators of equal precedence are performed in left to right order. Unary operators are performed in right to left order.
    Example:
    7 + 10 / 5 * 2 - -9;
    The computation would be performed in the following order:
    first division: 10 / 5 = 2
    second multiplication: 2 * 2 = 4
    third addition: 7 + 4 = 11
    fourth subtraction: 11 - - 9 = 20
    The final result of the computation is 20
    - L. Maneva
  30. The Math Class holds powerful computation tools, and is imported into every program by default.
    z = Math.pow(x, y); // x is raised to the power ‘y’ and the result is stored in z
    z = Math.abs (x);// the absolute value of x is taken and the result is stored in z
    maxVal = Math.max(arg1, arg2); // Finds the maximum of 2 numbers and the result is stored in maxVal
    minVal = Math.min(arg1, arg2);// Finds the minimum of 2 numbers and the result is stored in minVal
    Math.PI // is a constant for Pi=3.14...
    z = Math.sqrt(x); // the square root of the number x is stored in the value z
    z = Math.floor(x); // the floor of x is stored in z
    z = Math.cei(x); // the ceiling of x is stored in z
    z = Math.round(x); // x is rounded to the nearest integer and the result is stored in z
    z = Math.random(); // There is no argument for this method. The method selects a random number that is 0 <= random number < 1 and the result is stored in z

    - K. Blanchette
  31. How do I test to determine if a value is even or odd?
    When 'i' is an integer and evaluating ' i % 2 == 0 ' evaluates to true then 'i' is even, otherwise it is odd.
    Thus, the test for odd is ' i%2 !=0 ' if this evaluates to true the value is odd, otherwise it is even.
    - N. Daringer
  32. How do I test to determine if my program will try to divide by zero, thus causing a run-time error?
    Use the if-else statement as it will execute one group of statements if its boolean expression is true, or another group if its boolean expression is false.
    Code example:
    int num1 = 10, num2 = 4, quotient;
    if(num2 > 0)
    {
    quotient = num1 / num2;
    System.out.println("num1 divided by num2 is: " + quotient);
    }
    else
    {
    System.out.println("Division by 0 is not possible.");
    }
    output:
    num1 didived by num2 is 2. //Note: integer division was performed here, and the result is truncated to an integer

    - N. Baron
  33. Swapping two variables means mutually exchanging their values.
    Method 1 : Swapping two variables by using a third temporary variable.
    Example:
    int x = 2;
    int y = 5;
    System.out.println("Initial value: " + x + "and " + y);
    //Swap process:
    int temp = x; //temp is the 3rd variable: move val1(x) into temp
    x = y; //move val2(y) into val1(x)
    y = temp ;// move temp(contains val1: x) into Val2(y)
    System.out.println("Swapped value: " + x + " and " + y);
    Output:
    Initial value: 2 and 5
    Swapped value: 5 and 2
    Method 2: Swapping by addition and subtraction (this method swaps two variables by adding and subtracting their values).
    Example:
    int a = 10;
    int b = 5;
    System.out.println("Initial value: " + a + "and " + b);
    //swap process
    a = a + b; //a now contains both a and b
    b = a - b; //b contains a and b - b, so just a remains
    a = a - b;// a contains a and b - b(which now only contains a), so just b remains
    System.out.println("Swapped value: " + a + "and " + b);
    Output:
    Initial value: 10 and 5
    Swapped value: 5 and 10
    - L. Maneva
  34. The Assignment Operator Vs. The Logical Equals!
    The assignment operator (=) assigns the value on the right (rval), to the storage space on the left (lval).
    lval = rval;
    This is in contrast to the Logic Equivalence Operator ( ==), which compares to values to determine if they are logically equivalent. This expression evaluates to true or false.
    Example:
    int a = 1;
    int b = 2;
    (a == b) //evaluates to false
    - S. Miller
  35. The modulus operator computes the remainder after division.
    It is usually used with integer operands but it can be used with floating-point operands as well.
    Example:
    14/4 evaluates to 3, because integer division truncates the result.
    14 % 4 evaluates to 2, because the modulus operator captures only the remainder after doing the division.
    - L. Maneva
  36. The typecast operation changes the data type of a value from its normal type to the type specified the typecast operator.
    Example:
    double guess = 4.7;
    int answer = (int)guess;
    The value stored in answer will be: 4, because the fractional portion will be truncated.
    As for guess, it still contains: 4.7
    On that note, see how important typecasting is, as related to integer division...
    float x = 5/2; //x will contain: 2.0 as integer division is performed on 2 integers
    float y = (float)5/2; //y will contain 2.5 as 5 was typecast as a float, thus normal floating point division was performed.
    - L. Maneva
  37. The increment operator(++) which adds 1 to the variable, and decrement operator(--) which subtracts 1 to the variable, evaluate differently in an expression, depending on if they are using prefix or postfix notation.
    Postfix mode causes the increment or decrement to happen after the value of the variable is used in the expression.
    Prefix mode causes the increment or decrement to happen 1st in the expression.
    Example:
    int number =4;
    int answer = ++number; //answer contains 5, and number contains 5
    int value =4;
    answer = value++; //answer contains: 4, and value contains 5
    Note: The decrement operator works in the same way, except it subtracts 1 from the value.
    - C. Perea
  38. Curly braces should be written in pairs and labeled, prior to placing commands within the braces.
    Example:
    public static void main (String[] args)
    {
    } //closing main method
    - M. Ford
  39. Short circuit evaluation refers to the condition where a conditional expression is not completely evaluated since further evaluation cannot change the value of the compound expression.
    Example:
    For a boolean expression of the form (x > y) || (y > z), if expression (x > y) is evaluated as true, Java then concludes that the entire expression is true without evaluating (y > z).
    Likewise, for an expression of the form (x < y) && ( y < z), if expression (x < y) is evaluated as false, Java concludes that the entire expression is false without evaluating the rest of the expression.
    - L. Maneva
  40. The value of a boolean expression can be stored in a boolean variable. Then boolean variable can be compared to true/false in a logic expression to control an if-else statement.
    In this example, the String pw is being tested for an upper case letter:
    boolean uc = false;
    String pw;
    pw=keyboard.nextLine();
    int i=0;
    while(i < pw.length())
    {
    if ((pw.charAt(i)>='A') && (pw.charAt(i)<='Z'))
    {
    uc = true;
    }
    i++;
    }
    if (uc ==true)
    {
    System.out.println("Success:contains an upper case letter!");
    }
    else
    {
    System.out.println("Fail: no upper case letter found!");
    }

    - M. Ford
  41. A loop is a programming construct that repeats a task some number of times.
     
    Pre-test loops – the condition is evaluated before the body of the loop is executed. If the condition is true, the code is then executed until the condition becomes false. Since the test is prior to the entrance of the body of the loop, it is possible that the loop body may NOT be executed.
    Syntax: for and while loops
     
    Post-test loops – the condition is verified after the body of the loop is executed at least once. If the condition is true the code is executed again. This repeats until the condition becomes false.
    Syntax: do/while loop
    - L. Maneva
  42. Loops can also be categorized by their stopping condition.
     
    Conditional loops excute as long as a particular condition remains true.
    A count-controlled loop repeats a specifified number of times.

    - C. Perea
  43. Key components to a repetition structure (loop):
     
    Starting value (entrance to loop) – a value that will be used in the stopping condition to start the execution of the loop when the value allows the stopping condition to evaluate to true. Note: a starting value may cause the stopping condition of a pre-test loop, to evaluate to false, thus, the loop body will not be executed.
    The body of the loop – the step or steps of the algorithm that are repeated within the loop. Note: The body can contain only 1 statement, thus if multiple statements are to be executed within the body, curly braces { } are used to encapsulate the group of statements.
    Stopping condition (exit to loop) – a conditional statement that when it evaluates to false, terminates the loop
    MOE (method of egress) - the most critical part to a repetition structure, a statement within the body of the loop that will eventually cause the stopping condition to evaluate to false, thus terminating the execution of the loop. Without MOE, an infinite loop (run-time error) is certain.
    Example:
    for(x = 10; x > 0; x--)
        System.out.println(x);
     
    x = 10; is the starting value
    x > 0; is the stopping condition
    x-- is MOE
    System.out.println(x); is the body of the loop
    - L. Maneva
  44. The for loop and how its commands are executed.
    The for loop is ideal for performing a known number of iterations of the loop body.
    Sequence of events with the for loop in code:
     
    Example code for 5 iterations of loop body:
    for(number = 1; number <= 5; number++)
    {
    System.out.println(number + " ");
    }
    How the for loop works:
    for(Step 1; Step 2; Step4)
    {
    System.out.println(number + " ") //Step 3
    }
    Step 1: Performs the intialization expression
    Step 2: Evaluates the test expression. If it is true, go to step 3, otherwise it terminates the loop.
    Step 3: Execute the body of the loop
    Step 4: Perform the update expression, then go back to Step 2

    - C. Perea
  45. Nested for loops:
    Nested loops are necessary when a task performs a repetitive operation and that task itself must be repeated. a good example was the multiplication table. The inner loop creates a row of values, and the outer loop advances to the next line and the starting value for the next row of values to be created by the inner loop.
    Code Example:
    for(int i =1; i <= 12; i++)
    {
    for(int j = 1; j <= 12; j++)
    System.out.print(i *j + " ");
    }
    system.out.println();
    -N.Baron
  46. break statement:
    We've seen the break statement in the switch case. The break statement causes the program to jump out of the switch statement and resume processing at the statement following the switch/case. The break statement should be avoided in loops because it bypasses the normal condition that is required to terminate the loop, and it makes code difficult to understand and debug.
    -N.Baron
  47. continue statement:
    The continue statement causes a loop to stop its current iteration and begin the next one. When encountered all the statements in the body of the loop that appear after it are ignored and the loop prepares for the next iteration. The continue statement should be avoided, just like the break statement it bypasses the loop's logic and makes the code difficult to understand and debug.
    -N.Baron
  48. A sentinel value is a value that is used to mark the end of a list.
    A sentinel value must be different from all possible actual data values, so it cannot be a potential member of a list. Sentinel values are often used to terminate a repetition structure.
    Example:
    To end a sequence of positive integers, a negative integer could be used as the sentinel value.
    - L. Maneva
  49. The syntax for creating an array of elements of a data type:
    datatype[ ] identifier = new datatype[Length];
    The data type can be any of the primitive data types or an object.
    Example (the following creates an array named car that contains 30 variables of type int):
    final int SIZE = 30; //It is good programming form to use a constant to declare the size of the array
    int[ ] car = new int[SIZE];
    In this example array car has length 30, which means it has indexed variables car[0] through car [29]. There will not be an index variable 30 because the indices start at 0, thus, the last index is at SIZE -1.
    - S. Miller
  50. The three ways to use square brackets [ ] with an array:
    a. When you declare an array, the brackets note an array declaration. Example: double [ ] velocity;
    b. To surround an integer expression when creating the storage space for a new array.
    Example: velocity = new double[10]; //allocates storage for 10 doubles referenced by 'velocity'
    c. To reference a particular element within the array.
    velocity[2]= 100.5; //The value 100.5 is placed in the 3rd storage space for the array 'velocity'.
    - S. Miller
  51. An array size can be initiallized with data:
    You can initialize an array with values when you declare it. Just enclose the values for the individual indexed variables in braces and put them after the assignment operator.
    Example: int[ ] pin = {9, 3, 11};
    The array size would then be set to 3, the number of values in the initiallization.
    - S. Miller
  52. Java provides bounds checking with arrays.
    An index expression that evaluates to some other integer other than zero through (length -1) of the array is invalid. You will receive an error message when you run your program.
    - S. Miller
  53. The for loop is the best way for stepping through elements of an array.
    This example sums the values in the array:
    double myArray[10];
    double sum;
    int index; //by declaring index outside of the for loop it remains in scope for the entire main method
    for(index = 0; index < myArray.length(); index ++)
    {
    myArray[index] = keyboard.nextDouble();
    sum = sum + myArray[index];
    }
    - S. Miller
  54. The type of data stored in an array must be the same for any specific array.
    For example, you could use an array to store a list of values of type int that holds the tire pressure of each tire on a car. You could also use an array to store a list of objects of a class called Dogs that holds various dogs.
    - S. Miller
  55. Determining the array size from user input at the keyboard:
    If you have no clue as to how large to make an array, but the user may determine it, when you write a program, get the array's size from the keyboard.
    Example:
    char[ ] letters; //declare an array
    int size; //declare an integer variable to store the size of the array
    System.out.println("How many letters do you have?");
    int size = keyboard.nextInt(); //get size of array from user atk
    vows = new char [size]; //create the required storage space
    - S. Miller
  56. Types of errors:
    A syntax error is a grammatical mistake in a program, and is detected by the compiler.
         Example: omitting a required punctuation mark or switching case on the an identifier (width Vs. Width)
    A run-time error is an error occurring during execution. The program stops mid-execution and an error message would be displayed. You can locate the run-time error by the when the program stopped successfully outputting information.
         Example: trying to divide a number by zero
    A logic error is a conceptual error in a program. The program compiles and runs, but produces inaccurate results. For this reason, programs should be run with all the possible sets of input to verify their accuracy.
         Example: mistakenly using a minus sign instead of a plus sign or creating an "empty statement" with a decision or repetition structure.
    - L. Maneva
  57. The Java compiler translate Java source code into bytecode, and the Java Virtual Machine intreprets the bytecode to execute the program.
    This makes Java different from other high-level-languages like C++, which require a different compiler for every platform, making Java a more portable language (write once, execute anywhere).
    Remember: Java is a high-level language. It's statements are written in English-like form.
    - J. Anderson
  58. There can be only 1 public class in a Java file, and it must be the same name as the file that contains it.
    Also, the convention is that the filename should start with an uppercase letter.
    - J. Anderson
  59. All programs need a main method.
    The program executes from the beginning of 'main' and stops at the end of 'main'. If any other classes or methods need to be used (CS 207), they must be invoked within 'main' directly or indirectly through another method.
    - J. Anderson
  60. The main method's return type is 'void' (it doesn't return anything).
    (Instructor Note: In CS 207, Programming II, you will write methods in addition to 'main' that may return values to the the calling method. Keep this in mind, for the future. -F.P.)
    - J. Anderson
  61. Integer division produces an integer quotient!
    If you divide two integer types then the result of that division will also be an integer, even if it's being stored in another data type, such as double. Some situations only need to work with integers, but if you wish to work with the true value of that division, you either need to divide by a decimal point value or typecast.
    -Dividing by a decimal point is useful is you are working with at least one literal number rather than all variables.
    For example, if you want to divide the integer variable x by the literal 3, but you want the quotient to be stored as a double, simply perform x/3.0 instead of just coding x/3
    -Type casting changes the data type to the type specified in parentheses, for example:
    double y = 7/ 3; //y will be computed as 2 because both dividend and divisor are integers, however, if you do:
    double y = (double)7 / 3; //y will be computed as 2.33 because 7 will be treated as a double value for the division process
    - S. Summers
  62. Methods can be used to define reusable code and organize and simplify coding.
    A method definition consists of its method name, parameters, return value type, and body.
    The method header specifies the modifiers,return value type, method name, and parameters of the method.
     
    modifier returnValueType methodName(list of parameters) {
    // Method body;
    }
    In order for a value-returning method to return a result, a return statement using the keyword return is required. The method terminates when a return statement is executed.
    - J. Groner
     
    Notes: Use only one return statement, to avoid ambiguous code.
    Do not re-declare the parameters within the body of the method, as the items within the () are storage space declaration statements.
    Do note write over the arguments being sent from the calling method, as the data being sent is what you are to process for the task of the method, unless the task of the method is to change values in an array that has been sent.
  63. Placement of Methods:
    Methods are placed outside main() method but before closing the class.
     
    Return value:
    Whenever there is a call to a method from any portion of the program it will return value to that particular calling portion of the program.
     
    Scope of variables:
    Variables declared in method header are local to that particular method. Its value does not reflect in main();
    M. Begum
  64. Global variables,
    Global variables are those variables that can be accessed across all the classes. Java does not support global variables explicitly, you need to create a class and global variables can be part of this class. You can use static variables to create global variables. "static" variables belong to the class and can be accessed across all instances of the class.
    I. Syed
  65. Q1. What is meant by method Overloading?
    It is a feature that allows a class to have many methods with the same name but different argument lists.
    same method name
    different argument types
    different return types
    Example:
    public class MyClass{
    public void add(){....}
    public void add(int a, int b){....}
    public void add(float x, float y){....}
    public void add(int p, float q){.....}
    }

    MAK
  66. Q2. What is a Jagged Array?
    It is an array of arrays such that member arrays can be of different sizes. It is a two-dimensional array with a variable number of columns in each row.
    Example:
    int table[][] = new {
    new int[] {1, 2, 3, 4},
    new int[] {5, 6, 7|,
    new int[] {8, 9, 10, 11, 12},
    new int[] {13, 14, 15}
    };

    MAK

 

 

blog RSS feed FAP's Blog - Really Simple Syndication (RSS) :: NEIU Home :: NEIU A to Z :: NEIUport

web page updated: 4.27.22