Saturday, March 13, 2010

GUI INPUT

GUI INPUT

import javax.swing.*;

public class Guiinput
{
public static void main(String args[])
{
int a,b,c;
String r,s;
r = JOptionPane.showInputDialog("Enter First Number: ");
a = Integer.parseInt(r);
s = JOptionPane.showInputDialog("Enter Second Number: ");
b = Integer.parseInt(s);
c=a+b;
JOptionPane.showMessageDialog(null,"The Sum of "+a+" and "+b+" is: "+c);
}
}



Friday, March 12, 2010

First GUI Program

First GUI Program

import javax.swing.*;
public class gui
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null,"First Java GUI Program");
}
}

NOTE: THIS WILL SIMPLY PRINT THE MESSAGE IN A DIALOG BOX.

Tuesday, March 9, 2010

Temperature Converter

Temperature Converter


public class Temprature
{
public static void main(String args[])
{
final double fahrenheit = 95.0;
double celsius;
celsius = (5.0/9.0) * (fahrenheit - 32.0);
System.out.println("\n\t\t\t::Fahrenheit -> Celsius::");
System.out.println("\tFahrenheit "+fahrenheit+" = "+celsius+" Celsius");
System.out.println("\n\t\t\t***THE END***");
}
}

NOTE: IN THIS PROGRAM WE USE "FINAL DOUBLE". FINAL KEYWORD IS USE TO DECLARE ANY CONSTANT.


SCALE CONVERTER

SCALE CONVERTER

import java.util.Scanner;
class Scale
{
public static void main(String args[])
{
double feet,meter;
System.out.println("\t\t\t\t::Feet To Meter::\n");
Scanner input = new Scanner(System.in);
System.out.println("Enter Number of Feet: ");
feet = input.nextDouble();
meter=0.305*feet;
System.out.println(feet+" Feet = "+meter+" Meters.");
}

}


Saturday, March 6, 2010

First Input

First Input
import java.util.Scanner;
public class Input
{
public static void main(String args[])
{
Scanner input= new Scanner(System.in);
int var;
System.out.println("Enter any Integer: ");
var = input.nextInt();
System.out.println("Your Entered: "+var);
}
}
"input.nextInt()" is used to specify that the input we will be taking is an Integer value. You can also try it with other data types like Double, Float, etc.
To take any string value use "input.nextLine()"
Note: input IS ANY VARIABLE YOU CAN NAME IT YOURSELFE.

Quadratic Equation Solving

Quadratic Equation Solving
public class Quadratic
{
public static void main(String args[])
{
double b, a, c, inSqr, total1, total2, toSqr; a = 5;
b = -7;
c = 2;
toSqr = (b*b)-(4*a*c); inSqr = Math.sqrt(toSqr);
total1 = ((-1*b)+inSqr)/(2*a);
total2 = ((-1*b)-inSqr)/(2*a);
System.out.println("\n\n\n\t\t\t::QUADRATIC EQUATION::");
System.out.println("Varibles");
System.out.println("\t-> a = "+a);
System.out.println("\t-> b = "+b);
System.out.println("\t-> c = "+c);
System.out.println("\n\nResult of Quadratic Equation [with +]: "+total1);
System.out.println(" ______________");
System.out.println("(-b)+/(b*b)-(4*a*c)");
System.out.println("-------------------- = "+total1);
System.out.println(" 2a ");
System.out.println("\n\nResult of Quadratic Equation [with -]: "+total2);
System.out.println(" ______________"); System.out.println("(-b)-/(b*b)-(4*a*c)");
System.out.println("-------------------- = "+total2); System.out.println(" 2a ");
System.out.println("\t\t\t***THE END***");
}
}

Friday, March 5, 2010

First Program

First Program
public class First
{
public static void main(String args[])
{
System.out.println("Hello Java.");
}
}
Save this program with the file name as "First.java"
This simple program will just show {Hello Java.} on screen.

Starting Java Programming

Starting Java Programming
To start making java programs, first of all you should install JDK [Java Development Kit] and JRE[Java Runtime Environment].
Now it is important to know why should you these. Actually Java programs run on those machine which have Java supported software like JRE. And as we are here to program in Java so JDK must be installed to compile those program.
Java program can be written in any simple text editor like Notepad in Windows. Or you can also use any IDE. I will recommend you Eclipse or Netbeans. Both of these are freeware and provides good environment for development. But remember these are advanced tools. I will use simple Windows Notepad to make your concepts clear.
You can download these compilers from there websites.
As I said i will take you to Java programming using Notepad, so lets start how to start your Java program after having jdk.
First of all you have to save the file with the extension of " .java " and the name must be same as of the class in the program.
To compile this program go to cmd and type { javac FILENAME.java }
After Compiling and to run type { java FILENAME}.
This how you will get to your program.

Thursday, March 4, 2010

Java Programs

Its all about java programming. It will start from basic java programs to high level programs. Covering all main topics like swing, applets and some small application making. I hope you will enjoy java programming with me. I will appreciate your comments.


Java Programs


Its all about java programming. It will start from basic java programs to high level programs. Covering all main topics like swing, applets and some small application making. I hope you will enjoy java programming with me. I will appreciate your comments.