| Author |
Objective 4.1
|
Aleks V. Pascoal
Ranch Hand
Joined: Apr 21, 2002
Posts: 72
|
|
Hey guys, here are my thoughts about this topic. Please post comments. Assignment Atributte a value to a variable. It may be a literal, a primitive or a reference to an object. Operator: "=". Ex: int i = 10; name = new String("Aleks"); long l = i; i++; // same as i = i + 1; i+=2; // same as i = i +2; Conditional Check the value of an expression and made a decision about witch peace of code execute if-else: check logical expressions true/false if (expression) { doThis} //if expression true doThis else if (expression2) {doThat} //if expression2 true doThat else { doThose } //otherwise doThose switch: compare variable with values to make a decision switch(variable){ // byte, short, int, char or Enum. case value1: //Must be a constante value doThis; break; case value2: doThat; break; default: //just in case variable is diferent of all values doDefault; break; } ?: ternary operador, it's almost a resume of if-else variable = expression ? return1: return2; //if expression true returns return1, else returns return2. Logical operators: "==", "!=", "&&", "||". Iteration Executes repeateddly the same code while some conditions are mantained. Obs: break exits any loop and continue jumps to the next step of the loop. while: while (condition){ //while contidion is true continues ...code... } do-while: always executed at least once do{ } while(condition) for: loop determined. //declaration/inicialization = executed once before the loop //condition = tested on each iteration, repeated while it's true //increment = repeated after each loop for (declaration/inicialization; condition ; increment ){ } for-each: enhaced loop, used with arrays or Collections //declaration - variable with the same type of elements //colection - Collection or array //On each iteration take the next elementof the collection e assign to //the variable. for (declaration : colection){ ...code... } [ June 29, 2005: Message edited by: Aleks V. Pascoal ]
|
 |
Nicholas Cheung
Ranch Hand
Joined: Nov 07, 2003
Posts: 4982
|
|
For assignment part, don't miss the difference between i++ and ++i. Nick
|
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
|
 |
 |
|
|
subject: Objective 4.1
|
|
|