Java examples: Enhanced For Loop


public static void enhancedForLoop(){
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
System.out.println("\nEXAMPLE: Enhanced For Statement");
for (int temp: arr){ // Create a temporary variable, same type as array values. For
// loop assign array value to the temporary variable
System.out.println("Enhanced = " + temp);
}
}

Java examples: Switch Statement


public static void witchStatment(int num) {
System.out.println("\nEXAMPLE: Switch Statement");
switch(num){ //Check the value
case 0:
System.out.println("Case = " + num); // Execute this if 'case' matches the 'value'
break; // Stop the statement
case 1:
System.out.println("Case = " + num); // Execute this if 'case' matches the 'value'
break; // Stop the statement
case 2:
System.out.println("Case = " + num); // Execute this if 'case' matches the 'value'
break; // Stop the statement
case 3:
System.out.println("Case = " + num); // Execute this if 'case' matches the 'value'
break; // Stop the statement
case 4:
System.out.println("Case = " + num); // Execute this if 'case' matches the 'value'
break; // Stop the statement
default:
System.out.println("Default = " + num);
}
}

Java examples: While Loop vs ‘do’-while loop


While Loop

public static void whileLoop(){
System.out.println("\nEXAMPLE: While Loop");
int num = 0;
while(num <= 20) { // Check the while condition first, Then execute the loop
// Then while 'l' is less than or equal to '0'
System.out.println("num = " + num);
num++; //increment 'l' by 1
}
}

‘do’-while loop

public static void doWhileLoop() {
System.out.println("\nEXAMPLE: Do While Loop");
int num = 0;
do {
// DO the work... Execute the loop first
System.out.println("num = " + num);
num++; //increment 'l' by 1
} while(num <= 20); // Check the conditions
}

Back to school


Finally I am doing MSc. I didn’t do quite well in BEng as I hoped. I didn’t listen to my lecturer at the time.

You can’t look after anyone else if you don’t look after your self

Those were her exact words and something that failed to listen at the time but never forget any more. It’s been haunting me forever. Hopefully MSc in BioInformatics would allow me to put that right. Leave the nightmare behind.

I think I was quite lucky to get in to MSc. I got  ripped apart in my interview. My references came in very late. I am still not properly enrolled because I am waiting for the documents to come through. So I got to make the most of this. But this would be just the beginning.  2 evenings per week (learn Unix, Perl and Java). It’s going to be fun. Brings back some some bad memories and some good memories. Oh and I am totally not using the MSc as an excuse to break my bank to buy one of those Alienware :D.

In the coming weeks I will be putting up the Tutorials I’ve learnt here. Mainly as a personal record and also hope it would be use to someone.

 

Advertisement

Java Tutorial – Installing JAVA SE Development Kit (JDK)


Before writing a JAVA program first need to download JDK which allows write JAVA and compile the code.

  1. Download appropriate JAVA SE Development Kit (JDK) for your operating system
  2. Run the Installation
  3. Navigate to C:\Program Files\Java\jdk1.7.0\bin (this location may change in any instance you want to navigate to bin in JDK installation) make sure you have the .exe files there.
  4. copy the location of the bin C:\Program Files\Java\jdk1.7.0\bin
  5. Right click on computer and select properties > Advanced System settings > Environment variablesenvironment variables location
  6. Click on New and Variable name as Path and variable value as location of the bin so in my case it would be C:\Program Files\Java\jdk1.7.0\binUser Variable
  7. Click OK  OK
  8. To make sure compiler is working and ready for JAVA programming open cmd and run JavaC and if Java Compliler is working should get some random code as belowJavaC Working
Special thanks to Bucky Roberts for the clear accompanying video tutorial