Tuesday, June 2, 2009

Java Basics Using Qt Jambi Tutorial

Operators, Expressions, Statements and Blocks

  1. Operators – Operators are symbols that do something on operands.

Ex. 1 + 2

operator +

operands 1, 2

Operands can be variables with values in them.

int a = 1; //assign a to 1 called, which = is called assignment operators.

int b = 2; //assign b to 2

int c = a + b; //add a and b and give the result to c which is also type int.

System.out.println(c); //print result which is 3.

There are two kinds of operators:

    1. Equality and Relational

== equal to

!= not equal to

> greater than

>= greater than or equal to


<= less than or equal to

    1. Conditional

&& Conditional-AND

|| Conditional-OR

  1. Expressions – Expressions are made up of variables, operators or method calls.

Ex. int a = 1; //data type of a is int.

int b = 2; //data type of b is also int.

int c = a + b; //data type of c must be int.

  1. Statements – Statements are logical lines which ends with a semi-colon.

Ex. int a = 1; //one statement

System.out.println(“Hello World!”); //one statement.

Note: A Statement always ends with a semi-colon.

  1. Blocks – Blocks are made up of statements within curly braces:


public static void main(String[] args){

int a = 1;

int b = 2; This is a block.

int c = a + b;




if (condition){

System.out.println(“Condition is true.”); This is a block.



System.out.println(“Condition is false.”); else block


to be continued...

No comments: