Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Monday, 18 May 2015

java program to build calculator



import java.util.Scanner;
public class Calculator{
  public static void main(String[] args){
     System.out.println("Enter integers x,y");
     Scanner in = new Scanner(System.in);
     int a,b;
     a = in.nextInt();
     b = in.nextInt();
     int r=0;
     System.out.println(" CALCULATOR ");
     r=a+b;
     System.out.println("a + b = "+r);

     r=a-b;
     System.out.println("a - b = "+r);

     r=a*b;
     System.out.println("a * b = "+r);

     r=a/b;
     System.out.println("a / b = "+r);
  }
}

Write a program to find the largest of 3 numbers.



import java.util.Scanner;

class LargestOfThreeNumbers
{
   public static void main(String args[])
   {
      int x, y, z;
      System.out.println("Enter three integers ");
      Scanner in = new Scanner(System.in);

      x = in.nextInt();
      y = in.nextInt();
      z = in.nextInt();

      if ( x > y && x > z )
         System.out.println("First number is largest.");
      else if ( y > x && y > z )
         System.out.println("Second number is largest.");
      else if ( z > x && z > y )
         System.out.println("Third number is largest.");
      else  
         System.out.println("Entered numbers are not distinct.");
   }
}

java program to add two numbers using different Methods


simple arithmetic using command line argument
1    
      class CommanLine

  {  public static void main(String args[]){  
     int a,b,c=0;
      a=Integer.parseInt(a[0]); 
       b=Integer.parseInt(a[1]); 
     c=a+b;
5 System.out.println("sum is"+c);  
     
7  }  

8  }  

using scanner 

import java.util.Scanner;
class Add_CMD {
  public static void main(String[] args){
   int a,b,c;
   System.out.println("Enter integers ");
   Scanner in = new Scanner(System.in);
   a = in.nextInt();
   b = in.nextInt();
   c=a+b;
   System.out.println("Sum of "  + a+ " and " + b + " is " +c);

  }
}

 using BufferedReader
import java.io.*;
class Arithmatic
{
public static void main(String args[])throws IOException
{
try
{
int a,b,c,ae,nfe;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
a=Integer.parseInt(br.readLine());
b=Integer.parseInt(br.readLine());
c=a/b;
System.out.println("Result="+c);
}
/*catch(ArithmeticException ae)
{
System.out.println("eror due to"+ ae.getMessage());
}
catch(NumberFormatException nfe)
{
System.out.println("error due to"+ nfe.getMessage());
}*/
catch(Exception nfe)
{
System.out.println("error due to"+ nfe.getMessage());


}

}}


Wednesday, 13 May 2015

simple java applet example of adding components

import java.awt.*;
import java.applet.*;
public class Applet3 extends Applet
{
Label l1,l2,l3;
Choice c1,c2;
List lst;
int i;
public void init()
{
l1=new Label("Select Train Name");
l2=new Label("Select Seats             ");
l3=new Label("Cause Of Visit       ");
c1=new Choice();
c1.addItem("Rajdhani Express");
c1.addItem("GT Express");
c1.addItem("Link Express");
c1.addItem("Mussoorie Express");
c1.addItem("Shatabdi Express");
c2=new Choice();
for(i=1;i<=50;i++)
c2.addItem(String.valueOf(i));
lst=new List(6);
lst.addItem("Official");
lst.addItem("Personal");
lst.addItem("Educational");
lst.addItem("Tourism");
lst.addItem("Research");
lst.addItem("WildLife");
setBackground(Color.cyan);
add(l1);
add(c1);
add(l2);
add(c2);
add(l3);
add(lst);
}
}
/*
<applet code=Applet3 height=250 width=270></applet>
*/

mutithreding in java :create thread using Runnable


class RunnableThread implements Runnable{

 Thread runner;
 public RunnableThread() {
 }

 public RunnableThread(String threadName) {
        runner = new Thread(this, threadName);   // (1) Create a new thread.
        System.out.println(runner.getName());
        runner.start();                          // (2) Start the thread.
 }

 public void run(){
  //Display info about this particular thread
  System.out.println(Thread.currentThread());
 }


}
public class RunnableExample{
 
 public static void main(String[] args){
     Thread thread1 =  new Thread(new RunnableThread(),"thread1");
     Thread thread2 =  new Thread(new RunnableThread(),"thread2");
     RunnableThread thread3 = new RunnableThread("thread3");

//Start the threads
     thread1.start();
     thread2.start();
     try{
       //delay for one second
       Thread.currentThread().sleep(1000);
     }catch(InterruptedException e){}

     //Display info about the main thread   
     System.out.println(Thread.currentThread());       
 }
}

java applet example of drawing diffrent shapes using Graphics



import java.applet.*;
import java.awt.*;
public class  fillColor extends Applet{
   public void paint(Graphics g){
      g.drawRect(300,150,200,100);
      g.setColor(Color.yellow);  
      g.fillRect( 300,150, 200, 100 );
      g.setColor(Color.magenta);
      g.drawString("Rectangle",500,150);
   }
}
 

java applet example of changing background color on button click event

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class ColorApplet extends Applet implements ActionListener
{
 Button b1,b2,b3;

 public void init()
 {
  b1 = new Button("Red");
  b2 = new Button("Green");
  b3 = new Button("Blue");
 
  add(b1);add(b2);add(b3);
   
  b1.addActionListener(this);
  b2.addActionListener(this);
  b3.addActionListener(this);
  setBackground(Color.yellow);
 }

 public void actionPerformed(ActionEvent ae)
 {
  if(ae.getSource()==b1)
   setBackground(Color.red);
  if(ae.getSource()==b2)
   setBackground(Color.green);
  if(ae.getSource()==b3)
   setBackground(Color.blue);
 }
}


/*<applet code=ColorApplet height=300 width=300></applet>*/