Tag Archives: java

Java Classes [Java]

In real life, we know that many objects are similar. For example, every car shares some similarities. We can use a basic blueprint and modify it to make other cars. A class in java is the blueprint you use to make objects. Here is an example:

class Car{

    int speed = 0
    int gear = 1;
    void changeGear(int value) {
         gear = value;

    void speedUp(int amount) { 
         speed = speed + amount; 

    void slowDown(int amount) {
         speed = speed - amount;

    void printInfo() {
         System.out.println("Gear:" + gear + " Speed:" + speed);


In this we setup basic variables and created a few methods to change those variables.… View full post

Conditional Statements [Java]

There are a few operators used to compare two values.

==      equal to
!=      not equal to
>       greater than
>=      greater than or equal to
<       less than
<=      less than or equal to

Using ‘if’, ‘elseif’ and ‘else’ statements to we can carryout the comparisons. Examples are given below.

int a = 2;
int b = 3;

// If a is less than b
if (a < b) {
     // Do something here
// If above is not true, then check if a is equal to b
elseif (a == b) {
     // Do something here
// If both of the above are not true
else {
     // Do something here

In the above code, Java will only go to the second statement if the first is false.… View full post