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

Wednesday 20 May 2015

java program to create thread and set priority ,id,and name

import java.lang.*;

public class ThreadDemo  {

   public static void main(String[] args)  {

Thread t1 = Thread.currentThread();
Thread t2 = Thread.currentThread();
Thread t3 = Thread.currentThread();
Thread t4 = Thread.currentThread();
Thread t5 = Thread.currentThread();
        t1.setName("My Thread1");
    t2.setName("My Thread2");
    t3.setName("My Thread3");
    t4.setName("My Thread4");
    t5.setName("My Thread5");   
    
     t1.setPriority(6);
     t2.setPriority(6);
     t3.setPriority(6);
     t4.setPriority(6);
     t5.setPriority(7);
try
{      
     t3.sleep(2000);
    t5.sleep(2000);
}
catch(Exception ex)
{
System.out.println("exception caught is"+ex);
}
        System.out.println("Thread = " + t1);
    System.out.println("Thread = " + t2);
    System.out.println("Thread = " + t3);
    System.out.println("Thread = " + t4);
    System.out.println("Thread = " + t5);
     int count = Thread.activeCount();
     System.out.println("currently active threads = " + count);
   }
}

Write a Java program to enable the user to handle any chance of divide by zero exception

import java.io.*;
import java.util.*;
class Numz
{
public static void main(String args[])
{
   int i=0,a;
float r;
System.out.println("Enter the number to divide 100:");
Scanner in=new Scanner(System.in);
a=in.nextInt();
try
{
if(a==0)
{System.out.println("Program Terminated Exception Caught");
throw new Exception();
}
if(a!=0)
{
r=100/a;
System.out.println("Result is:"+r);
}
}
catch(Exception e)
{
System.out.println("Exception Caught is Divide By Zero");
}
}
}

Write a java program to throw a exception (checked) for an employee details. If an employee name is a number, a name exception must be thrown. If an employee age is greater than 50, an age exception must be thrown. or else an object must be created for the entered employee details

import java.io.*;
import java.util.*;
class Numx
{
public static void main(String args[])
 {
String name;
int age;
System.out.println("-----ENTER EMPLOYEE DETAILS-----");
System.out.println("Enter Name and Age:");
Scanner in=new Scanner(System.in);

try
{
if(!(in.nextLine().matches("[a-zA-Z]+")))
{throw new IOException();}

age=in.nextInt();
if(age>50)
{
System.out.println("Age greater than 50 Exception");
throw new Exception();
}

Numx x=new Numx();
System.out.println("-----Object Created-----");
}

catch(Exception e)
{
System.out.println("Exception");
}
}
}

java example to show ArrayIndexOutOfBoundsExeption

import java.io.*;
import java.util.*;
class Nums
{
 public static void main(String args[])
 {
   int i=0,j=0;
try
{
   String s[]=new String[9];
   int b[]=new int[10];
   System.out.println("Enter the Name of 10 students:");
   Scanner in=new Scanner(System.in);
        for(i=0;i<10;i++)
    {
    s[i]=in.nextLine();
    }
    }
catch(ArrayIndexOutOfBoundsExeption e)
{
System.out.println("Program Not Terminated Exception Caught\n"+e);
String s[]=new String[10];
int b[]=new int[10];
     System.out.println("----CONTINUE----");
    System.out.println("Enter the Name of 10 students:");
        Scanner in=new Scanner(System.in);
        for(i=0;i<10;i++)
    {
    s[i]=in.nextLine();
    }
    System.out.println("Enter the Roll no of 10 students:");
    for(j=0;j<10;j++)
     {
      b[j]=in.nextInt();
       }

    i=j=0;
    System.out.println("Name and Roll No are:");
    while(i<10&&j<10)
    {
     System.out.println(s[i]+"\t"+b[j]);
     i++;j++;
    }
}

}
}

A java class which throws an exception if operand is nonnumeric in calculating modules

import java.io.*;
import java.util.*;
class Numb
{
 public static void main(String args[])
 {
   int i,j;
float add,sub,mul,div;
System.out.println("CALCULATOR:");
System.out.println("Enter two Operands:");
Scanner in=new Scanner(System.in);
try
{
i=in.nextInt();
j=in.nextInt();
add=i+j;
sub=i-j;
mul=i*j;
div=i/j;
System.out.println("Addition ="+add);
System.out.println("Subtraction ="+sub);
System.out.println("Multiplication ="+mul);
System.out.println("Division ="+div);
}

catch(InputMismatchException e)
{
System.out.println("Program Is Terminated Exception Caught");
}

}
}

example in java to show InputMismatchException

import java.util.Scanner;
import java.util.InputMismatchException;

public class Modulus{
public void calMod(double x) throws InputMismatchException{
Scanner inp= new Scanner(System.in);
System.out.println("Enter The Number You want to Calculate the Modulus Of");
x= inp.nextDouble();
if(x<0){
System.out.println("Modulus of |"+x+"| is");
x=-x;
System.out.println(x);
}
else{
System.out.println("Modulus of |"+x+"| is"+x);
}
}

public static void main(String[] args){
double x=0;
Modulus m= new Modulus();
try{
m.calMod(x);
}
catch(InputMismatchException ie){
System.out.println("Exception: The Entered value is not Numeric Type");
}
}
}

java example to throw a new exception if given condition satisfied

import java.util.Scanner;
import java.io.*;
class Employee{
public static void main(String args[]){
String name;
int age;
System.out.println("ENTER EMPLOYEE DETAILS");
System.out.println("Enter Name and Age Of The Employee:");
Scanner in=new Scanner(System.in);

try
{
if(!(in.nextLine().matches("[a-zA-Z]+"))){
throw new IOException("Please Enter The Name in Aplhabets");
}
age=in.nextInt();
if(age>50){
System.out.println("Age greater than 50 Exception");
throw new Exception("You Are Too Old to Work , Take Retirement");
}
Employee x=new Employee();
System.out.println("Object Created");
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
}
}

example to throw ArithmeticException in java

import java.util.Scanner;

public class Divisor{
public static void main(String[] args){
Scanner inp=new Scanner(System.in);
System.out.println("Enter the First number");
double x=inp.nextDouble();
System.out.println("Enter the Second number");
double y=inp.nextDouble();
Divisor d= new Divisor();
d.divide(x,y);
}
public void divide(double x, double y){
double result=0;
try{
if(y==0){
throw new ArithmeticException("Divisor Cannot Be Zero");
}
}
catch(ArithmeticException ae){
System.out.println("Exception:Divisor Cannot be ZERO "+"\n Enter the Divisor again");
Scanner inp=new Scanner(System.in);
y=inp.nextDouble();
}
result=(x/y);
System.out.println("Result of the divsion is "+result);
}
}

arrays and exception example in java

import java.util.Scanner;

public class DisplayRecords {
public static void main(String[] args){
try{
System.out.println("Enter The Roll Numbers of The Students");
int []a=new int[10];
Scanner input=new Scanner(System.in);
for(int i=0;i<10;i++){
a[i]=input.nextInt();
}
System.out.println("Enter The Name Of The Students");
String []s=new String[10];
for(int i=0;i<10;i++){
s[i]=input.nextLine();
}
System.out.println("Entered Roll No for the Students");
for(int i=0;i<10;i++){
System.out.println(a[i]);
}
System.out.println("Entered Name of The Students");
for(int i=0;i<10;i++){
System.out.println(s[i]);
}
}
catch(ArrayIndexOutOfBoundsException ae){
System.out.println("Caught Exception");
}
}
}

java example to throw exception



import java.util.Scanner;

public class Collision{

public static void main(String[] args){
int x=0;
System.out.println("     ONE WAY \nDo Not Take a U Turn");
Scanner inp=new Scanner(System.in);
x=inp.nextInt();
try{
if(x>0){
throw new Exception("Please Stop Immediately In Order To Avoide Collision");
}
else{
System.out.println("Have a Safe Journey");
}
}
catch (Exception ex){
System.out.println(ex.getMessage());
}
}
}

A very simple example to show the concept of interface in java

interface Test{
public void square(int j);
}

class Arithmetic implements Test{
public void square(int j){
int result;
result=(j*j);
System.out.println("Square Of The Integer Is="+result);
}
}

public class ToTestInt{
public static void main(String[] args){
Arithmetic ar=new Arithmetic();
ar.square(12);
}
}

example of interface in java two add two integers

interface A{
public void meth1(int j, int k);
public void meth2(int x, int y, int z);
}

public class MyClass implements A{
int y,x,z;
public void meth1(int j, int k){
int result;
result=(j+k);
System.out.println("Sum Of The Integers is="+result);
}
public void meth2(int x,int y,int z) {
this.x=x;
this.y=y;
this.z=z;
System.out.println("Entered value of Integers is x="+x+" y="+y+" z="+z);
}
public static void main(String[] args){
MyClass mc=new MyClass();
mc.meth1(12,14);
mc.meth2(14,1,5);
}
}

another example of interface in java to show division

interface Test{
public void division(double x, double y);
public void calMod(double x);
}
public class DivMod{
public void division(double x,double y){
double result;
result=(x/y);
System.out.println("Result for Division is="+result);
}
public void calMod(double x){
if(x<0){
System.out.println("Modulus of |"+x+"| is");
x=-x;
System.out.println(x);
}
else{
System.out.println("Modulus of |"+x+"| is"+x);
}
}
public static void main(String[] args){
DivMod dm= new DivMod();
dm.calMod(-12);
dm.division(14,7);
}
}

java exaple to show the concept on interface



interface KeepValues{
final double pie=3.14;

public double area(int r, int h);

}

class Cone implements KeepValues{
double ar,l;
public double area(int r, int h){
l=Math.sqrt((r*r)+(h*h));
System.out.println("Value of slant height"+l);
ar=((r*r)*pie*l);
return ar;
}
}

class Cylinder implements KeepValues{
double ar;
public double area(int r, int h){
ar=(2*(pie*(r*r)*h));
return ar;
}
}

public class DisplayArea{
public static void main(String[] args){
double a,b;
Cone c= new Cone();
a=c.area(3,4);
Cylinder cl=new Cylinder();
b=cl.area(7, 6);
System.out.println("Area of Cone is="+a+" Area of Cylinder is="+b);
}
}

java inheritance example to show SalriedWorker, DailyWorker salary details


import java.io.*;
import java.util.Scanner;
class Worker{
String name;
double salaryrate;
public void setdata(String s,double a){
name=s;
salaryrate=a;
}
public double ComPany(int hours){
return salaryrate*hours;
}
}
class DailyWorker extends Worker{
public void getsalary(int days){
int k=days*12;
System.out.println("salary of the DailyWorker is"+ComPany(k));
}
}
class SalariedWorker extends Worker{
public void getsalary(int hours)
{ int m=hours;
System.out.println("salary of the SalriedWorker is"+ComPany(m));
}
}
class WorkerMain{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
String n;
double salaryrate;
int days,hours,ch;
System.out.println("Enter 1 for Daily Worker \n 2 for Salried Employee");
ch=in.nextInt();
switch(ch){
case 1:DailyWorker d=new DailyWorker();
System.out.println("enter the Name");
n=in.nextLine();
System.out.println("\nenter the salary rate");
salaryrate=in.nextDouble();
d.setdata(n,salaryrate);
System.out.println("\nenter the no. of days of work");
days=in.nextInt();     
d.getsalary(days);
break;
case 2:
SalariedWorker s=new SalariedWorker();
System.out.println("enter the Name");
n=in.nextLine();

System.out.println("\nenter the salary rate");
salaryrate=in.nextDouble();
s.setdata(n,salaryrate);
s.getsalary(40);
break;
}
}
}


inheritance example in java to show the trunk call ,normal call and Urgent calls rates


import java.util.Scanner;
import java.io.*;
class Trunk_Call{
double rate;
public void setrates(int rate){
this.rate=rate;
}
public double getcharges(double duration){
return rate*duration;
}
}
class Ordinary extends Trunk_Call{
void charges(double time){
double t=time;
System.out.println("charges for ordinary calls are"+getcharges(t));
}
}
class Urgent extends Trunk_Call{
void charges(double time){
double t=time;
System.out.println("charges for Urgent calls are"+getcharges(t));
}
}
class Lightning extends Trunk_Call{
void charges(double time){
double t=time;
System.out.println("charges for Lightning calls  are"+getcharges(t));
}
}
class TrunkMain{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int ch,a,b,rate,time;
System.out.println("Enter 1 for ordinary call \n 2 for Urgent call \n 3 for Lightning");
ch=in.nextInt();
switch(ch){
case 1:Ordinary o=new Ordinary();
      System.out.println("enter the rates");
       rate=in.nextInt();
       o.setrates(rate);
       System.out.println("enter the time in sec. for call");
       time=in.nextInt();      
     o.charges(time);
break;
case 2:Urgent u=new Urgent();
      System.out.println("enter the rates");
       rate=in.nextInt();
       u.setrates(rate);
       System.out.println("enter the timein sec. for call");
       time=in.nextInt();      
     u.charges(time);
break;
case 3:Lightning l=new Lightning();
      System.out.println("enter the rates");
       rate=in.nextInt();
       l.setrates(rate);
       System.out.println("enter the time in sec. for call");
       time=in.nextInt();      
     l.charges(time);
break;
}
}
}

java program to print student details

import java.io.*;
class Student
{
private String  name;
private String SapID;

public void display(){
System.out.println("Hello From Base class");
}
}
class StudentDetail extends Student{
public void setdata(String s,String r){
name=s;
SapID=r;
System.out.println("Name="+name+" SAPID="+SapID);
}

public static void main(String args[]){
StudentDetail d=new StudentDetail();
d.setdata("Nikhil" , "500017137");
d.display();
}
}

java program to show th concept of inheritance

class Player
{
public String name;
public String Country;
public int JersyNo;
public int age;
public void setdata(String a,String b,int c,int d)
{
name=a;
Country=b;
JersyNo=c;
age=d;
}
public void getdata()
{
System.out.println("Name is"+name);
System.out.println("Country is is"+Country);
System.out.println("JersyNo is"+JersyNo);
System.out.println("Age is"+age);
}
}
class Cricket_Player extends Player
{
public void setdata(String a,String b,int c,int d)
{
name=a;
Country=b;
JersyNo=c;
age=d;
}
}
class Football_Player extends Player
{
public void setdata(String a,String b,int c,int d)
{
name=a;
Country=b;
JersyNo=c;
age=d;
}
}
class Hockey_Player extends Player
{
public void setdata(String a,String b,int c,int d)
{
name=a;
Country=b;
JersyNo=c;
age=d;
}

}
class PlayerMain
{
public static void main(String args[])
{
Player p=new Player();
Cricket_Player c=new Cricket_Player();
System.out.println("Detail of Cricket player is");
c.setdata("Rahul Dravid","India",19,40);
c.getdata();
System.out.println("Detail of Hockey player is");
Hockey_Player h=new Hockey_Player();
h.setdata("Sandeep singh","India",4,26);
h.getdata();
System.out.println("Detail of Football player is");
Football_Player f=new Football_Player();
f.setdata("Cristiano Ronaldo","PORTUGAL",23,30);
f.getdata();
}
}

constructor and function example in java

class Employee{
double salary,gross,tax=0;
String name,empid;

public Employee(){
gross=0;
tax=0;
salary=0;
name="null";
empid="null";
}
public Employee(String nme,String eid,double sal){
salary=sal;
empid=eid;
name=nme;
}
public double increase_Salary(double percent){
return salary=(salary+((percent*salary)/100));

}
public double calculate_tax(){

if(salary>=100000&& salary<150000){
tax=(10*(salary/100));
}
else if(salary>=150000){
tax=(20*(salary/100));
}
return tax;

}

public double gross_salary(){
if(salary>=100000&& salary<150000){
gross=(salary-(10*(salary/100)));
}
else if(salary>=150000){
gross=salary-(20*(salary/100));
}
return gross;
}

public void display(){
for (int i=1;i<=12;i++){
if(i==1){
System.out.println(i+" "+name+" "+"JAN"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==2){
System.out.println(i+" "+name+" "+"FEB"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==3){
System.out.println(i+" "+name+" "+"MAR"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==4){
System.out.println(i+" "+name+" "+"APR"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==5){
System.out.println(i+" "+name+" "+"MAY"+" "+empid+" "+salary+" "+(calculate_tax()/12)+" "+(gross_salary()/12)+" "+(increase_Salary(20)/12));
}
if(i==6){
System.out.println(i+" "+name+" "+"JUN"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==7){
System.out.println(i+" "+name+" "+"JUL"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==8){
System.out.println(i+" "+name+" "+"AUG"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==9){
System.out.println(i+" "+name+" "+"SEP"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==10){
System.out.println(i+" "+name+" "+"OCT"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==11){
System.out.println(i+" "+name+" "+"NOV"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
if(i==12){
System.out.println(i+" "+name+" "+"DEC"+" "+empid+" "+(salary/12)+" "+(calculate_tax()/12)+" "+(gross_salary()/12));
}
}
}
public static void main(String[] args){

Employee emp=new Employee("Nikhil Jain","R101",2400000);
emp.display();
}
}

Monday 18 May 2015

java program to show conversion of string to float ,int and vice versa


1) integer
public class Convert{
public static void main(String[] args){
System.out.println("****Conversion of Int to Integer****");
int i=10;
Integer z= Integer.valueOf(i);
System.out.println("Value of z="+i);
System.out.println("****Conversion of Integer to String****");
String s;
s= Integer.toBinaryString(12);
System.out.println("Value of s is "+s);
System.out.println("****Conversion of Integer to Int****");
Integer y= new Integer(12);
int x= y.intValue();
System.out.println("Value of x"+x);
System.out.println("****Conversion of String to Int****");
double a= Double.parseDouble("123.123");
int k=(int)a;
System.out.println("Value of k="+k);
System.out.println("****Conversion of String to Integer****");
short v= Short.parseShort("10011",2);
Integer b= new Integer(v);
System.out.println("Value of b="+b);
System.out.println("****Conversion of Int to String****");
int e=10;
Integer g= new Integer(e);
String f= Integer.toString(213);
System.out.println("Value of f is "+f);
}
}


2)float


public class Conversion{
public static void main(String[] args){
System.out.println("****Conversion of Float to float****");
float f= new Float("123.23");
System.out.println("Value of f="+f);
System.out.println("****Conversion of Float to String****");
Float g= new Float(123.123);
String y= String.valueOf(g);
System.out.println("Value of y is "+y);
System.out.println("****Conversion of String to Float****");
Float k= Float.valueOf("170.78");
System.out.println("Value of k="+k);
System.out.println("****Conversion of String to float****");
float z= Float.parseFloat("71.11");
System.out.println("Value of z="+z);
System.out.println("****Conversion of float to Float****");
float a=122.24f;
Float x= Float.valueOf(a);
System.out.println("Value of x"+x);
System.out.println("****Conversion of float to String****");
float h=18.45f;
String s= String.valueOf(h);
System.out.println("Value of s is "+s);
}

}

java program to check a letter is present in the string or not

import java.util.*;
public class CheckString
{
public static void main(String args[])
{
String s1;
char s2='a';
int count=0,j=0;
int arr[]=new int[25];
System.out.println("Enter your name");
Scanner in=new Scanner(System.in);
s1=in.nextLine();
int len=s1.length();
for(int i=0;i<len;i++)
{
if(s1.charAt(i)==s2)
{
count++;
arr[j]=i;
j++;
}
}
System.out.println("You name contains\t"+count+" times a \n");
System .out.println("a is present at following locations\n");
for(int k=0;k<j;k++)
{
System.out.println(arr[k]);
}
}
}

java program to convert letters in string capital to small and vice versa

import java.util.*;
public class Convert
{
public static void main(String args[])
{
System.out.println("Enter the String");
String s1,s2="";
char ch;
Scanner in=new Scanner(System.in);
s1=in.nextLine();
int len=s1.length();
for(int i=0;i<len;i++)
{
ch=s1.charAt(i);
if(ch>=97 && ch <=122)
{
ch-=32;
}
s2=s2+ch;

}
System.out.println("Converted string is:"+s2);
}
}

java program to show the concept of if.......... else if



import java.util.Scanner;
class Year{
  public static void main(String args[]){
     int i;
     System.out.println("Enter the Number of the year");
     Scanner in=new Scanner(System.in);
     i=in.nextInt();

     if(i==1)
       System.out.println("Month is Janurary");

     else if(i==2)
       System.out.println("Month is Feburary");

     else if(i==3)
       System.out.println("Month is March");

     else if(i==4)
       System.out.println("Month is April");

     else if(i==5)
       System.out.println("Month is May");

     else if(i==6)
       System.out.println("Month is June");

     else if(i==7)
       System.out.println("Month is July");

     else if(i==8)
       System.out.println("Month is August");

     else if(i==9)
       System.out.println("Month is September");

     else if(i==10)
       System.out.println("Month is October");

     else if(i==11)
       System.out.println("Month is November");

     else if(i==12)
       System.out.println("Month is December");

     else if(i==0||i>12)
       System.out.println("Enter valid year Number");
  }
}

java program to print Fibonacci series



class Fibonacci{
  public static void main(String args[]){
    System.out.println(" Fibonacci Series ");
    int a1, a2=0, a3=1;
    for(int i=1;i<=20;i++){
     System.out.print(" "+a3+" ");
     a1 = a2;
     a2 = a3;
     a3 = a1 + a2;
     }
  }
}

java program to print the reverse of a given number


public class Combination
{
 public static int reverseNumber(int no)
 {
  int ono=0,rev=0,rem;
  ono=no;
  while(ono!=0)
  {
    rem=ono%10;
    ono/=10;
    rev= (rev*10)+rem;
  }
  return rev;

 }
 public static void main(String[] args){
 Combination.reverseNumber(123);
 }

}

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>*/







 

java Applet ItemListener example

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ItemLis extends Applet implements ItemListener
{
Label l1,l2,l3,l4,l5,l6;
TextField t1,t2,t3,t4;
Choice ch1,ch2;
int i,qty;
float pri;
public void init()
{
l1=new Label("Item Name");
l2=new Label("Quantity    ");
l3=new Label("Price           ");
l4=new Label("Amount      ");
l5=new Label("Tax              ");
l6=new Label("With Tax     ");
t1=new TextField(15);
t2=new TextField(15);
t3=new TextField(15);
t4=new TextField(15);
ch1=new Choice();
ch1.addItem("Burger");
ch1.addItem("Pizza");
ch2=new Choice();
for(i=1;i<10;i++)
ch2.addItem(String.valueOf(i));
setBackground(Color.green);
t3.setText("12.24%");
add(l1);
add(ch1);
add(l2);
add(ch2);
add(l3);
add(t1);
add(l4);
add(t2);
add(l5);
add(t3);
add(l6);
add(t4);
ch1.addItemListener(this);
ch2.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==ch1)
{
String inm=String.valueOf(ie.getItem());
if(inm.equals("Burger"))
{
t1.setText("Rs.75.00");
pri=75.0f;
}
else if(inm.equals("Pizza"))
{
t1.setText("Rs.125.00");
pri=125.0f;
}
}
if(ie.getSource()==ch2)
{
qty=Integer.parseInt(String.valueOf(ie.getItem()));
float amt=pri*qty;
t2.setText(String.valueOf(amt));
float tamt=amt+.1224f*amt;
t4.setText(String.valueOf(tamt));
}
}
}
/*
<applet code=ItemLis height=300 width=250></applet>
*/

java Applet LayoutExample



import java.awt.*;
import java.applet.*;
public class LayoutExample extends Applet 
    {
     Button okButton1;
     Button okButton2;
     Button okButton3;
     Button okButton4;
     Button okButton5;
     public void init()
     {
  // sets the LayoutManager to BorderLayout
        setLayout(new BorderLayout());
        okButton1 = new Button("Centered Button");
          okButton2 = new Button("Cold North");
          okButton3 = new Button("Go West");
          okButton4 = new Button("At East");
          okButton5 = new Button("Hot South");
  // always says where the component should be placed when adding
  // Options are center,East,West,Nort and South
        add(okButton1,"Center");
          add(okButton2,"North");
          add(okButton3,"West");
          add(okButton4,"East");
          add(okButton5,"South");
        }
    }
/*<applet code="LayoutExample.java" height=200 width=300></applet>*/

java Applet example of EventListeners,ActionListener(Addition ,Subtract,Multiply,Divide)

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
 
public class EventListeners extends Applet implements ActionListener{
   TextArea txtArea;
   String Add, Subtract,Multiply,Divide;
   int i = 10, j = 20, sum =0,Sub=0,Mul = 0,Div = 0;
   public void init(){
   txtArea = new TextArea(10,20);
   txtArea.setEditable(false);
   add(txtArea,"center");
   Button b = new Button("Add");
   Button c = new Button("Subtract");
   Button d = new Button("Multiply");
   Button e = new Button("Divide");
   b.addActionListener(this);
   c.addActionListener(this);
   d.addActionListener(this);
   e.addActionListener(this);
   add(b);
   add(c);
   add(d);
   add(e);
   }

   public void actionPerformed(ActionEvent e){
   sum = i + j;
   txtArea.setText("");
   txtArea.append("i = "+ i + "\t" + "j = " + j + "\n");
   Button source = (Button)e.getSource();
   if(source.getLabel() == "Add"){
   txtArea.append("Sum : " + sum + "\n");
   }
  
   if(i >j){
   Sub = i - j;
   }
   else{
   Sub = j - i;
   }
   if(source.getLabel() == "Subtract"){
   txtArea.append("Sub : " + Sub + "\n");
   }
   Mul = i*j;
   if(source.getLabel() == "Multiply"){
   txtArea.append("Mul = " + Mul + "\n");
   }
   if(i > j){
   Div = i / j;
   }
   else{
   Div = j / i;
   }
   if(source.getLabel() == "Divide"){
   txtArea.append("Divide = " + Div);
   }
   }
 }

java applet example of ActionListener java applet example of ActionListener

import java.awt.*;
import java.applet.*;
// import an extra class for the ActionListener
import java.awt.event.*;

public class ActionExample extends Applet implements ActionListener
{
     Button okButton;
     Button wrongButton;
     TextField nameField;
     CheckboxGroup radioGroup;
     Checkbox radio1;
     Checkbox radio2;
     Checkbox radio3;
     public void init() 
     { 
          setLayout(new FlowLayout());
          okButton = new Button("Action!");
          wrongButton = new Button("Don't click!");
          nameField = new TextField("Type here Something",35);
          radioGroup = new CheckboxGroup();
          radio1 = new Checkbox("Red", radioGroup,false);
          radio2 = new Checkbox("Blue", radioGroup,true);
          radio3 = new Checkbox("Green", radioGroup,false);
          add(okButton);
          add(wrongButton);
          add(nameField);
          add(radio1);
          add(radio2);
          add(radio3); 
          okButton.addActionListener(this);
          wrongButton.addActionListener(this);
         } 
         public void paint(Graphics g)
         {
 
          if (radio1.getState()) g.setColor(Color.red);
 
        else if (radio2.getState()) g.setColor(Color.blue);
          else g.setColor(Color.green);
 
 
          g.drawString(nameField.getText(),20,100);
     }
   public void actionPerformed(ActionEvent evt) 
         { 
              if (evt.getSource() == okButton)  
                   repaint(); 
          else if (evt.getSource() == wrongButton) 
          {
               wrongButton.setLabel("Not here!"); 
               nameField.setText("That was the wrong button!"); 
               repaint();
          }
     } 
}
/*<applet code="ActionExample.java" height=200 width=300></applet>*/

presentation slides (Comparison of Efficient parallel Index Algorithms ) and presentation Moodle Based Skill Development Survey




presentation Moodle Based Skill Development Survey Module Implementation

Moodle is one of the leading web based learning management system with various plugins available for different functionality.This paper proposes the methods to add customized survey modules in Moodle. With this method we tested the  functionality of some soft skills based surveys and their outputs, integrated in Moodle



https://drive.google.com/file/d/0B7SRUSGOtQ9hZFdnY1Aza0JGNG8/view?usp=sharing

Comparison of Efficient parallel Index Algorithms used for RDF data store using Graphical processing unit with CUDA

The exponential growth of semantic web and the resultant generation of large-scale RDF (Resource Description Framework) triples pose new challenges in the domain of RDF-storage and retrieval.Graphical processing units (GPUs) are being actively probed in the area of Big Data study, machine learning, and augmented certainty ever since ,such applications are categorized by massive data spanned and produced over distributed network. GPUs be responsible for a parallel programming agenda using CUDA (Compute Unified Device Architecture) that can be developed to proficiently collected and make inferences on these massive data-sets. 



https://drive.google.com/file/d/0B7SRUSGOtQ9hcGRFaC0weGNOdDg/view?usp=sharing

Seminar Report On Cloud Computing



Contents


















Abstract
During the past years a vast number of online file storage services have been introduced .while several of these services provide basic functionality such as an uploading and retrieving files by a specific user, more advanced services offer features such as shared folders, real-time collaboration ,minimization of data transfers or unlimited storage space. Within this report I am giving an overview of existing file storage solutions, and also try to analyze the Drop-box client software as well as its transmission protocols, show the weaknesses and possible attack vectors. And conclude by discussing the security improvements.
Key words: cloud computing, drop-box, attacks




Tuesday 12 May 2015

JAVA Program to represent Bank System using inheritance function ,constructor and user input


import java.io.*;
/*Base class Account*/
class Account
{
 double accBal;
 Account()
 {
 }
 Account(double d)
 {
  accBal=d;
  if(accBal<1000)
  {
   System.out.println("Invlaid amount. Amount should be > or = 1000");
   accBal=1000;
  }
 }
 
 void credit(double amt)
 {
  accBal=accBal+amt;
 }
 
 void debit(double amt)
 {
  if(amt>accBal)
   System.out.println("Debit amount exceeded account balance");
  else
   accBal=accBal-amt;
 }
 
 double getBalance()
 {
  return(accBal);
 }
}
//Derived class SavingsAccount
class SavingsAccount extends Account
{
 double rate;
 SavingsAccount(double r,double amt)
 {
  super(amt); 
  rate=r;
 }

 public void calculateInterest()
 {
  accBal=accBal*rate;
 }
}
class CheckingAccount extends Account
{
 double fee;
 CheckingAccount(double f,double amt)
 {
  super(amt);
  fee=f;
 }
 void credit(double amt)
 {
  accBal=accBal+amt-fee;
 }
 void debit(double amt)
 {
  if(amt>accBal)
   System.out.println("Debit amount exceeded account balance");
  else
   accBal=accBal-amt-fee;
 }

 
}
class Bank
{
 public static void main(String args[])
 {
  int a,b;
  DataInputStream d= new DataInputStream(System.in);
  double amount,rate =5,fee=100;
 
  try
  {
  System.out.println("Press 1. SavingAccounts 2. Checking Accounts");
  a=Integer.parseInt(d.readLine());
  switch(a)
  {
  case 1:
  System.out.println("Enter amount to open account");
  amount=Double.valueOf(d.readLine());
  SavingsAccount sa=new SavingsAccount(rate,amount); 
  
  System.out.println("Thank you for opening account your Initial Balanceis :"+sa.getBalance());
  do
  {
  System.out.println("Enter choice:\n1.Withdraw\n2.Deposit\n3.CheckBalance\n 4.Exit");
  a=Integer.parseInt(d.readLine()); 
  switch(a)
  {
   case 1:
      System.out.println("Enter amount to withdraw");
      amount=Double.valueOf(d.readLine());
      sa.debit(amount);
      sa.calculateInterest();
      System.out.println("Balance is :"+sa.getBalance());
      break;
   case 2:
      System.out.println("Enter amount to deposit");
      amount=Double.valueOf(d.readLine());
      sa.credit(amount);
      sa.calculateInterest();
      System.out.println("Balance is :"+sa.getBalance());
      break;
   case 3:
      System.out.println("Your balance is"+sa.getBalance());
      break;
  }
  }
  while(a!=4);
  break;
  case 2:
  System.out.println("Enter amount to open account");
  amount=Double.valueOf(d.readLine());
  CheckingAccount ca=new CheckingAccount(fee,amount); 
  
  System.out.println("Thank you for opening account your Initial Balanceis :"+ca.getBalance());
  do
  {
  System.out.println("Enter choice:\n1.Withdraw\n2.Deposit\n3.CheckBalance\n 4.Exit");
  a=Integer.parseInt(d.readLine()); 
  switch(a)
  {
   case 1:
      System.out.println("Enter amount to withdraw");
      amount=Double.valueOf(d.readLine());
      ca.debit(amount);
      System.out.println("Balance is :"+ca.getBalance());
      break;
   case 2:
      System.out.println("Enter amount to deposit");
      amount=Double.valueOf(d.readLine());
      ca.credit(amount);
      System.out.println("Balance is :"+ca.getBalance());
      break;
   case 3:
      System.out.println("Your balance is"+ca.getBalance());
      break;
  }
  }
  while(a!=4);
  break;
  }
  }
  catch(Exception e)
  {}
 }
}

 

java program to check a particular sentence found in the file or not

package newpackage3;


/**
 *
 * @author rajani
 */


import java.io.*;
import java.util.Scanner;
import java.util.regex.MatchResult;
public class Test {
    public static void main(String[] args) throws FileNotFoundException {
        int count=0,count2=0;
        //MatchResult mr;
        Scanner s = new Scanner(new File("amazon.txt"));
         Scanner s1 = new Scanner(new File("amazoncomp.txt"));
        while (null != s.findWithinHorizon("java", 0)) {
            count=1;
            MatchResult mr = s.match();
           // System.out.printf("Word found: %s at index %d to %d.%n", mr.group(),
                  //  mr.start(), mr.end());
        }
        while (null != s1.findWithinHorizon("java", 0)) {
            count2=1;
            MatchResult mr = s1.match();
            //System.out.printf("Word found: %s at index %d to %d.%n", mr.group(),mr.start(), mr.end());
        }
        s.close();
        if(count==1)
        {
         System.out.printf("amazon.txt file data found "); 
        }
        if(count2==1)
        {
         System.out.printf("amazoncomp.txt file data found "); 
        }
    }
}

java program to search Exact data of different files

package newpackage3;
/**
 *
 * @author rajani
 */
import java.io.File;
import org.apache.commons.io.FileUtils;
public class compareFileContent
{
        public static void main(String[] args) throws Exception
        {
                /* Get the files to be compared first */
                File file1 = new File("temp.txt");
                File file2 = new File("amazon.txt");
                File file3 = new File("amazoncomp.txt");
                boolean compareResult = FileUtils.contentEquals(file1, file2);
                boolean compp=FileUtils.contentEquals(file1,file3);
                if(compareResult==true)
                {
                    System.out.println("amazon file");
                }
                if(compp==true)
                {
                   System.out.println("amazoncomp file");
                }
                  
               
        }
}

java program for moving ractangle on left, right, top, down side using KeyboarListner



import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.Rectangle;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
 class Canvas extends JPanel
{
//attributes
private Rectangle sampleObject;
//constructor
public Canvas ( )
{
//initialize object
sampleObject = new Rectangle ( 5, 5, 10, 10 );
//set canavs background colour
setBackground ( Color.black );
//add the key listener in the constructor of your canavas/panel
addKeyListener ( new myKeyListener ( ) );
//ensure focus is on this canavas/panel for key operations.
setFocusable ( true );
}
//painting
public void paintComponent ( Graphics graphics )
{
super.paintComponent ( graphics );
Graphics2D graphics2d = ( Graphics2D ) graphics;
graphics.setColor ( Color.red );
graphics2d.fill ( sampleObject );
}
//function which essentially re-creates rectangle with varying x orientations. (x-movement)
public void mutateRectangleXOrientation ( int mutationDistance )
{
sampleObject.setBounds ( ( int ) sampleObject.getX ( ) + mutationDistance, ( int ) sampleObject.getY
( ), ( int ) sampleObject.getWidth ( ), ( int ) sampleObject.getHeight ( ) );
}
//function which essentially re-creates rectangle with varying y orientations. (y-movement)
public void mutateRectangleYOrientation ( int mutationDistance )
{
sampleObject.setBounds ( ( int ) sampleObject.getX ( ), ( int ) sampleObject.getY ( ) +
mutationDistance, ( int ) sampleObject.getWidth ( ), ( int ) sampleObject.getHeight ( ) );
}
//listener
private class myKeyListener implements KeyListener
{
//implement all the possible actions on keys
public void keyPressed ( KeyEvent keyEvent )
{
switch ( keyEvent.getKeyCode ( ) )
{
case KeyEvent.VK_RIGHT:
{
mutateRectangleXOrientation ( 10 );
}
break;
case KeyEvent.VK_LEFT:
{
mutateRectangleXOrientation ( -10 );
}
break;
case KeyEvent.VK_UP:
{
mutateRectangleYOrientation ( -10 );
}
break;
case KeyEvent.VK_DOWN:
{
mutateRectangleYOrientation ( 10 );
}
break;
case KeyEvent.VK_ESCAPE:
{
System.exit ( 0 );
}
break;
}
repaint ( ); //this is here to ensure that the screen updates per graphics operation
}
public void keyReleased ( KeyEvent keyEvent )
{
}
public void keyTyped ( KeyEvent keyEvent )
{
}
}}
public class Display
{
public static void main ( String [ ] arguments )
{
JFrame frame = new JFrame ( "key listener demo" );
Canvas panel = new Canvas ( );
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
frame.add ( panel );
frame.setContentPane ( panel );
frame.setPreferredSize ( new Dimension ( 800, 600 ) );
frame.setLocationRelativeTo ( null );
frame.setVisible ( true );
frame.pack ( );
}
}