If statement is not always followed by a condition in java

This code will compile and run. Notice the assignment operator(=) in the condition.

boolean a;
boolean b = true;
if(a=b){
   //do anything;
   //this compiles
}

But this won’t compile

int a;
int b = 5;
if(a=b){   
   //notice its still = not ==
   //do anything;
   //this does not compile
}

The reason is because the previous code’s a is of

boolean
type and the latter’s is of
int
type.

if
statement is not necessarily followed by a condition.
a=b
is not a condition. Its an assignment. But it works if the left variable (i.e. a) is of a boolean type.

So its better if we think

if(boolean)
instead of
if(condition)
. Anyway, a condition like a==b or a>b etc will result a boolean result.

Simple Java Minesweeper Game.

This was the final assignment for JAC444 at Seneca. Its a simple minesweeper java applet game. Kyle and I worked on this together. I realized team of 2 is better than 1 or 2+. In pair programming, one of the programmer types the codes while the other look over his mistakes and makes sure they are working in right direction. Sort of like rally driving, one person drives while the other gives navigation information. This game could use some improvement for rendering. Download Source

Absolute beginner’s guide to Eclipse

Following article is a part of my Lab exercise for Eclipse course I am taking during Winter2011.

Click here for the java files used to create this tutorial When Eclipse is run, it asks for a workspace location. I will use ./wksp/basics/labs. You can choose to use this workspace by default by ticking the checkbox. Eclipse starts with the Welcome tab. On this window, you can get more information about using Eclipse. Close the Welcome tab. [Read more…]