Archive for June, 2012

Close Friends Can Now Track Your Fitness Successes (And Failures) On Path, With A Daily Sparkline From Nike+ Fuelband

Blavatar
Close Friends Can Now Track Your Fitness Successes (And Failures) On Path, With A Daily Sparkline From Nike+ Fuelband

Leave a comment

YouTube’s Next New Creator Program Is Meant To Bring In The LOLs

Blavatar
YouTube’s Next New Creator Program Is Meant To Bring In The LOLs

Leave a comment

Google Analytics Goes Mobile With App Analytics And An Android App

Google Analytics now on Android App !

Leave a comment

Google Pumps Up Jelly Bean’s Face Unlock Feature With A New ‘Liveness Check’

Google Pumps Up Android’s (Jelly Bean) Face Unlock Feature With A New ‘Liveness Check’

Leave a comment

YouTube And Google+ Grow Closer: All Users Can Now Switch Their Usernames To Their Google+ Profiles

All Users Can Now Switch Their Usernames To Their Google+ Profiles

Leave a comment

Java Tutorial 12 – Constructors

constructors are a special type of method which we can use to initialize Objects when we create it. If u do not use constructor, objects contains all the variables and methods, But Using constructor you can initialize values of variables. For example you can initialize some variables to zero or Strings to default values and etc. Lets Clear this with an example. Create two classes Tom and Jerry.

Tom:

public class Tom {

public static void main(String[] args){
Jerry object = new Jerry();
object.print();
}
}

Jerry:

public class Jerry {
int a;
String b;

public void print(){
System.out.println(“int a = “+a);
System.out.println(“String b = “+b);
}
}

Now if u run the Tom.java you will see the output like:

int a = 0
String b = null

Now if you want to initialize String b to some text say “Hi” and int a to value 5 whenever the new object is created, you can do it by creating constructor. There are some rules for it:

  • Name of the constructor must be same as name of class.
  • there is no other rule 😛

Now lets create constructor for Jerry class and initialize variables.

Jerry:

public class Jerry {
int a;
String b;

Jerry(){
a=5;
b = “Hi”;
}
public void print(){
System.out.println(“int a = “+a);
System.out.println(“String b = “+b);
}
}

 

!!!!! yap writing return type and access modifiers is optional. We can define Constructor by just Jerry(){ … }.

Now if you run the Tom.java you will see the output like:

int a = 5
String b = Hi

Here constructor initialized both variables when we created an object of Jerry.

catch you again later…

doubts are invited.

have a nice day.

Peace.

, , , , , ,

Leave a comment

Gmail Now Has 425 Million Users, Google Apps Used By 5 Million Businesses And 66 Of The Top 100 Universities

Leave a comment

Google Drive Now Has 10 Million Users: Available On iOS and Chrome OS

Leave a comment

Google Launches Compute Engine To Take On Amazon Web Services

Leave a comment

Java Tutorial 11 – Inheritance

inheritance means Inheritance ! (hehe you know that )

i mean consider two classes one is parent and second is child class and if you inherits child from parent class that child class can access all the variables and methods which are public in parent.

Let we have 2 classes Car and TataNano:

Car:

public class Car {
    public void breaks(){
    // breaks the car
}
    public void Speedup(){
        // speed up the car
    }
    public void indicator(){
        // indicator operation
    }
}
Now we have a model car which has functions like break speedup and indicator.
now consider for a while that you are making a Racing game and that has lots of different cars, but this break and indicators will be common in each of the cars. So you have to define all this three methods in each car.
Instead what u can do is throw common methods in one class called car and all the different cars will be inherited from it so all the cars automatically has all the three methods.
In short in this example Car is parent and specific car like Tata, Nissan, etc are childs and so it contains all the public methods of car.
How to inherit? :
if you want to inherit Tata from Car all you have to say is:
public class Tata extends Car {}
now you can directly call all three method of Car inside Tata class without creating object of Car.
Again doubts are invited.
have a good1, Peace.

, ,

1 Comment

Design a site like this with WordPress.com
Get started