Tuesday, December 4, 2007

Prime Number Program : Java Programming

This program explain you how to check the number is prime or not if user input the value from keyboard. Here is the source code :

import java.io.*;

class PrimeNumber {

public static void main(String[] args) throws Exception{

int i;

BufferedReader bf = new BufferedReader(

new InputStreamReader(System.in));

System.out.println("Enter number to Check:");

int num = Integer.parseInt(bf.readLine());

System.out.println("Prime number: ");

for (i=1; i < num; i++ ){

int j;

for (j=2; j<i; j++){

int n = i%j;

if (n==0){




if(i == j){

System.out.print(" "+i);





Thursday, November 29, 2007

Explanation : public static void main(String args[])

What is the work of public static void main(String args[]) method in Java. Here is the explanation :
  • public : The public method can be accessed outside the class
  • static : We must have an instance to access the class method.
  • void : There is no need by application to return value. JVM launcher do this with it exists.
  • main() : It is the entry point for the java application.
  • String args[] : It holds optional arguments passed to the class.

Tuesday, November 27, 2007

First Program in Java

Before writing java code, please be careful when you write the java code because it is case sensitive language. I will explain later about "String[] args".

class HelloWorld {

public static void main(String[] args){

System.out.println("My First Program:Hello World!");


Thursday, November 22, 2007

Introduction : Java Programming

Java Language :

It is high-level object-oriented programming language developed by Sun Microsystems in 1995. It is very similar to C++. It was used for the project set top box, was created by James Gosling in 1991. It is the modified from the language Oak. Oak was unsuccessful in the market. So Sun modified this language and changed its name to Java.

It is very one of the popular programming language because of platform independent nature and used in both computer and electronic devices. Platform independent means write once and run anywhere, only Java Virtual Machine needed to run Java program on any platform.