Java: Static Methods and Instance Methods

Static Methods

They are class methods. They are not associated with a particular object. Simply put, you don’t have to declare a new object based on a class to use this method.

Example:

String t = String.valueOf(n);

Instance Methods

This operates on an object (an instance of a class). They utilize the instance variables of that object. Simply put, you need to create a new object to make use of this kind of method.

Example:

String s = new String("Coding is an awesome career!");
int n = s.length();

Further reading:

  1. http://www.dummies.com/how-to/content/what-is-the-static-keyword-in-java.html
  2. http://www.leepoint.net/notes-java/flow/methods/50static-methods.html

 

August 29, 2014

Posted In: Information Technology

Tags: , ,

Leave a Comment

Multiplication Table: Java For Statement

So today I have been trying out the For loops for Java. I am actually sharpening my skills in Java. An interesting thing about the For loops is the nesting property that can be used to come up with a table of values. In this case, I came up with a multiplication table that has a maximum value of 10.

For loop syntax in Java:

for (variable initializer; test condition; increment)

So start up your preffered IDE (Netbeans for my case) and insert the code below:

[cc lang=”java”]

public class multiplicationTable
{

public static void main( String args[] )
{
for ( int i = 1; i <= 10; i++ )
{

for ( int j = 1; j <= 10; j++ ){

System.out.print( i*j + “\t” );
}
System.out.println();
} // end outer for
} // end main
} // end class Printing

[/cc]

 

Results:

Once you execute the code, it should give you the results below:

 

 

 

August 20, 2012

Posted In: Information Technology

Tags: , , ,

One Comment