Monday, 30 March 2015

Saturday, 28 March 2015

Hello World in JAVA

It is the trend to write the program to print "Hello World" while starting with any language. We will also do the same.

Below is the program and I will also explain useful things used in program.

class Hello{
 public static void main(Strings[] args){
   System.out.println("Hello World!!!");
 }
}
Open any text editor and write the above program. Note that some are in capital letters.
Now save the file with name Hello.java
Open command prompt and browse the location where the file is located.
For eg: If the file is located in c:/javatut/ then goto the same folder location in cmd.
Now type javac Hello.java
This command will compile your java file and creates class file.
Now type java Hello
If the compilation worked then you will get the output.

Some explanations


The first statement defines the main class which is required and the class name should be in initial capital letter.
The second statement defines the main function or method of the class. The first letter of String is capitalized as it

is the class name.
The third statement is used to display output. First letter of System is capitalized and the println statement creates

new line after the output. You can also sumply use print only.

Some basic rules while programming in JAVA


There are some of the ground rules while you are programming in JAVA. Before we start on writing the first program we will talk about common rules you must follow, which you must mock up.

The file name must be same as the main class name you used.
Class name must be start with the initial capital letter. Java is case sensitive language.
Any classes you used in the program must start with the capital letter and the method name with small letter.
The class file is obtained after the compilation of the program and it is the bytecode that can run in any platform which hava JDK.
We will start with the first program and syntax in out next post.

Wednesday, 25 March 2015

How to set path for JDK

In the previous post i have mentioned about the software and hardware requirements to get started with java programming. Only having those requirements is not enough. We need to set path of the JDK as the environment variables. There are two ways for doing this.

Process 1
We can set the path from the command prompt. The steps are mentioned below.
Open the command prompt.
Type javac and press enter.
If the result is shown as the command is not recognized, that means path is not set. Or if some help commands are shown then path is already set.
To set path first you need to copy the location of jdk installed in your drive.
Goto c:\program files and find java folder. Inside the java folder search for folder with jdk and its version. Inside it goto bin folder. And click on any file and view properties and there copy the path. It looks like this "C:\Program Files\Java\jdk1.5.0_09\bin" . Copy it.
In the command prompt, type "set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin" without the double quotes. The path is only sample example. It may vary according to the JDK version.
Now to check whether the path is set correctly or not, type javac and press enter. Now the results are shown instead of showing error. Now you can run the java program.
Process 2
Goto the windows properties.
Click on advanced system setting.
Click the environment variables.
In the system variables, click on add new.
Then enter "PATH" in variable name and in the variable value enter the path that is copied as in process 1.
To check do as in process 1.
Sometimes following process 2 may not work properly, so process 1 is followed mostly. In the next post I will write the first program and ways to run in the command prompt.

JAVA Introduction

Java is one of the object oriented programming language which is used to make complex programs and applications. Java has many features which you will learn through out this tutorials. I here present the basic syntax, codes, program examples for you. Java is platform independent language so you can run this in any machine.

There are some of the requirements to run the java program and I will tell you what.

You need to install Java Development Kit(JDK) in your machine before you run program and you also need to set path which I will show you later.
You need a java editor like eclipse, netbeans or you can simply use notepad for writing the codes.
You need computer system with pentium processor.
You can download the JDK from the java site http://www.oracle.com/technetwork/java/javase/downloads/index.html and select one that is compactible with your machine. In next post i will write about how to code your first program and run in command prompt.

Trapezoidal

Program:
#include
#include
#include
#define f(x) sqrt(sin(x))
#define pi 3.1415926
#include
void main()
{
clrscr();
float a,b,h, fa, fb, I,fx[10];
float sum=0.0,sum1=0.0,sum2=0.0,fn;
char k;
int c,n,i;
a=0;
b=pi/2;
fa=f(a);
fb=f(b);
do{
clrscr();
printf("\n 1) Trapezoidal\n 2) Comp.Trapezoidal\n 3) Simpson's 1/3\n 4) Comp.simpson's 1/3\n 5) Simpson's 3/8\n 6) Boole's\n 7) Comparison Table");
printf("\nENTER YOUR CHIOICE:");
scanf("%d",&c);
switch(c)
{
case 1:
printf("\n\tTrapizoidal");
h=b-a;
I=h*((fa+fb)/2);
printf("\n\tThe result is %.4f",I);
break;

case 2:
printf("\n\tComposite trapezoidal:");
printf("\n\tEnter n:");
scanf("%d",&n);
h=(b-a)/n;
for(i=1;i<=n-1;i++)
{
fx[i]=f(a+i*h);
sum=sum+fx[i];
}
fn=f(a+n*h);
I=(h/2)*(fa+2*sum+fn);
printf("\n\tThe result is: %.4f",I);
break;

case 3:
printf("\n\tSimpson's 1/3");
h=(b-a)/2;
fx[1]=f(a+h);
I=(h/3)*(fa+4*fx[1]+fb);
printf("\n\tThe result is: %.4f",I);
break;

case 4:
printf("\n\tComposite Simpson's 1/3:");
printf("\n\t Enter n:");
scanf("%d",&n);
h=(b-a)/n;
for(i=1;i<=(n/2);i++)
{
 fx[i]=f(a+(2*i-1)*h);
 sum1=sum1+fx[i];
 }
for(i=1;i<=((n/2)-1);i++)
{
fx[i]=f(a+2*i*h);
sum2=sum2+fx[i];
}
I=(h/3)*(fa+4*sum1+2*sum2+fb);
printf("\n\tThe result is: %.4f",I);
break;

case 5:
printf("\n\tSimpson's 3/8");
h=(b-a)/3;
for(i=1;i<=2;i++)
{
fx[i]=f(a+i*h);
sum=sum+fx[i];
}
I=(3*h/8)*(fa+3*sum+fb);
printf("\n\tThe result is: %.4f",I);
break;

case 6:
printf("\n\tBoole's Rule:");
h=(b-a)/4;
for(i=1;i<=3;i++)
{
fx[i]=f(a+i*h);
}
I=(2*h/45)*(7*fa+32*fx[1]+12*fx[2]+32*fx[3]+7*fb);
printf("\n\tThe result is: %.4f",I);
break;

case 7:
printf("\n\t RULE \t n\t RESULT");
printf(“\n\t----------------------------“);
printf("\n\t TRAPEZOIDAL\t 1\t0.78540");
printf("\n\t COMP. TRAPEZOIDAL\t 2\t1.05314");
printf("\n\t SIMPSON's 1/3\t 2\t1.14238");
printf("\n\t COMP. SIMPSON's 1/3\t 4\t1.17823");
printf("\n\t SIMPSON's 3/8\t 3\t1.16104");
printf("\n\t BOOLE's RULE\t 4\t1.18062");

break;
default:

exit(0);
}
printf("\n\t Continue??[y/n]");
k=getch();

}
while(k=='y'||k=='Y');



getch();


}

Monday, 23 March 2015

Friday, 20 March 2015

Bagchal

Bagchal is an ancient two player Nepali board game used to play in various part of Nepal. Bagchal is a strategic, two player board game that originated in Nepal. The game is believed to have been created by Mandhodari, wife of Ravan.
The game is asymmetric in that one player controls four tiger and the other player controls the 20 goats. The tiger hunts the goats while the goats attempt to block the tigers’ movements. The game is played on as five by five point grid. Pieces are positioned at the intersection of the lines and not inside the areas delimited by them. Directions of valid movements between these points are connected by lines. The game play takes places in two phases. In first phase, the goats are placed on the board while tigers are moved. In the second phase both goats and tigers are moved. For the tigers the objective is to capture five goats to win. Capturing is performed by jumping over the goats. The goats win by blocking all the tigers’ legal move.

This game software is an application based on the c programming language. It is also uses the basic operation of the graphics. This game is a very interesting game for all the age group of people.