Professional Documents
Culture Documents
1. In your browser enter the URL: Java SE 2. In the middle column, choose: Java SE 6 Update 29 and click the Download JDK button. 3. Accept the License Agreement and choose the correct platform (Windows), and click the Download button.. You will be downloading the file jdk-6u29-windows-i586.exe. 4. Save the file (somewhere where you know where you saved it since you will need to run it). 5. Double-click the installer and follow the instructions. 6. You now need to tell your computer where it can find the import Java files. The best instructions to complete your installation can be found at the Sun site: You need to add C:\Program Files\Java\jdk1.6.0_29\bin; to the PATH variable. How you do this will depend on what operating system you are using. i) In Windows 95/98 add or change the PATH statement in the autoexec.bat file ii) PATH current items; C:\Program Files\Java\jdk1.6.0_29\bin iii) In Windows 2000 - Start, Settings, Control Panel, System, Advanced: New or Edit : iv) Add: C:\Program Files\Java\jdk1.6.0_29\bin Click OK v) In Windows XP - Start, Control Panel, double click System icon, open System Control Panel, Advanced, click "Environment Variables", highlight Path, edit, add to path: ;C:\Program Files\Java\jdk1.6.0_29\bin Click OK vi) In Windows Vista - Start, Control Panel, System and Maintenance, System, Advanced system settings, click "Environment Variables", highlight Path, edit, add to path: ;C:\Program Files\Java\jdk1.6.0_29\bin Click OK or Click Start, right-click Computer and choose Properties, Advanced system settings, click "Environment Variables", highlight Path, edit, add to path: ;C:\Program Files\Java\jdk1.6.0_29\bin Click OK vii) Windows 7 - Start, Control Panel, System and Security, System, Advanced system settings (left column), click "Environment Variables", highlight Path, edit, add to path: ;C:\Program Files\Java\jdk1.6.0_29\bin Click OK
or Click Start, right-click Computer and choose Properties, Advanced system settings, click "Environment Variables", highlight Path, edit, add to path: ;C:\Program Files\Java\jdk1.6.0_29\bin Click OK
8. You may have to reboot your computer when the installation is complete.
10. Enter: cd .. as many time as it take to get to C:\> (this should be the folder where you stored hello.java) 11. Enter: javac hello.java There should be a slight pause and the another C:\> should appear Enter: java hello Your program should print out: Hello world! Enter: exit to close the DOS window
and java.
import java.io.*; public class MainClass { public static void main( String args[] ) { Account account1 = new Account( 50.00 ); // create Account object Account account2 = new Account( -7.53 ); // create Account object System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() ); System.out.printf( "account2 balance: $%.2f\n\n", account2.getBalance() ); double depositAmount; // deposit amount read from user depositAmount = 10.10; account1.credit( depositAmount ); // add to account1 balance System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() ); System.out.printf( "account2 balance: $%.2f\n\n", account2.getBalance() ); depositAmount = 12.12; account2.credit( depositAmount ); // add to account2 balance System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() ); System.out.printf( "account2 balance: $%.2f\n", account2.getBalance() ); } }
class Account { private double balance; // instance variable that stores the balance // constructor public Account( double initialBalance ) { if ( initialBalance > 0.0 ) balance = initialBalance; } public void credit( double amount ) { balance = balance + amount; } public double getBalance() { return balance; }}
OUTPUT
OUTPUT:
19648 in binary: 100110011000000 19648 in octal: 46300 19648 in hexadecimal: 4cc0
public static void main(String args[]){ int d,a; try { d=0; a=42/d; System.out.println("This will not be printed."); } catch (ArithmeticException e) { System.out.println("Division by zero."); } System.out.println("After catch statement"); } }
OUTPUT
A superOb = new A(); B subOb = new B(); superOb.i = 10; superOb.j = 20; System.out.println("contents of superOb:"); superOb.showij(); System.out.println(); subOb.i=7; subOb.j=8; subOb.k=9; System.out.println("contents of subOb:"); subOb.showij(); subOb.showk(); System.out.println(); System.out.println("sum of i,j and k in subOb:"); subOb.sum(); } }
OUTPUT
class AcessTest { public static void main (String args[]) { Test ob = new Test (); ob.a = 10; ob.b = 20; ob.setc(100); System.out.println("a,b,and c:" + ob.a + ob.a +" " + ob.b + " " + ob.getc() ); } } class Test { int a; public int b; private int c; void setc (int i) {
OUTPUT
public Sandwich() { System.out.println("Sandwich()"); } } public class MainClass { public static void main(String[] args) { new Sandwich(); } }
} class russia extends Thread { public void run() { for(int i=1;i<=5;i++) { System.out.println("Russia"); } } } class thr1 { public static void main(String a[]) { india i=new india(); china c=new china(); russia r=new russia(); i.start(); c.start(); r.start(); }