My other sites |
New Summer Look :)
| if-else | while [initialization] |
| if ( boolean-expression ) statement1; [ else statement2; ] |
while ( boolean-expression ) { [statements] [iteration] } |
| switch-case | for loops |
| switch ( int-value ) { case int-value1: break; case int-value2: break; default: } |
for ([initialization]; [ boolean-expression ]; [iteration]) { [statements] } |
![]() |
- Arrays in Java are considered to be objects - Arrays can contain any simple or complex type - c++ like declaration : type t[]; - java declaration : type[] t; - Multidimensional Arrays : type[][]..[] t; - Subscripts begin at zero - Out of bounds access throws an Exception |
![]() |
public class InitArrays {
|
![]() |
<modifiers> <return_type>
<name> ( <args> ) <block> modifiers : public, private, protected, static, final return_type : any type and void for nothing name : Identifier - Method's name args : Argument list block : block of code starting with '{' end finishing with '}' |
| Examples : public int getSize(); private byte[] getBuffer(); public void printNums( int[] theArray ) |
![]() |
by Value : What would you do to pass simple datatypes by reference? |
public class PassingArguments {
public void test(int x, int y, int[] array) {
x=1; y=2; array[0] = 5;
System.out.println("inside test method x:" + x + " y:" + y +
" array[0]:" +array[0] );
}
public static void main(String[] argv) {
int a = 5; int b = 10 ;
int[] ar = {15 };
System.out.println(
|
|
|
Before the test call: a:5 b:10 ar[0]:15 inside test method: x:1 y:2 array[0]:5 After the test call: a:5 b:10 ar[0]:5 |
![]() |
String, is a container type for 16-bit Unicode chars
|
public class StringExample {
public static void main(String[] argv) {
String str = new String("my name is Thanassis");
System.out.println("The string contains:" + str );
System.out.println("its length is :" + str.length() + " chars");
System.out.println("uppercase :" + str.toUpperCase());
System.out.println("lowercase :" + str.toLowerCase());
System.out.print("-is- starts at :" + str.indexOf("is") );
if (str.equals("my name is Thanasis"))
System.out.println("Yes")
else System.out.println("No")
}
}
|
![]() |
- Any simple numeric to String : |
|
Which of the following statements are correct ?
|
![]() |
1. Write the HelloWorld program, compile and execute it. After
executing successfully, try to alter both the process and the code
to get as many errors as possible :) I challenge you. Can you achieve
20 different errors? - the following pattern in all possible directions with the least
possible code - the ASCII table ( chars 32-255 ) |