Custom Search

Wednesday 7 November 2012

Java Program for stop clock showing seconds, minutes & hours, Java Program clock


Java Program for stop clock showing seconds, minutes & hours, Java Program clock


import java.applet.*;
import java.awt.*;
/*
<applet code="Clock" width=250 height=100>
</applet>
*/

public class Clock extends Applet implements Runnable
{
int counter;
        int min;
        int hr;
        int sec;
Thread t;
public void init()
{
counter=0;
                int sec=0;
                int min=0;
                int hr=0;
t=new Thread(this);
t.start();
}

public void run()
{
try
{
while(true)
{
                        setForeground(Color.green);
repaint();
Thread.sleep(25);
counter++;
                       
                      if(counter == 60)
                     
                       {
                        counter=0;
                        sec++;
                       setForeground(Color.red);
                       setBackground(Color.blue);                    
                       
                        if(sec==60)
                          {
                           setForeground(Color.cyan);
                           setBackground(Color.red);
                           sec=0;
                         
                           min++;
                            if(min==60)
                              {
                                min=0;
                                hr++;
                                   if(hr==12)
                                    { hr=0;
                                    }
                               }
                          }


                       }
}
}
catch(Exception e)
{
}
}

public void paint(Graphics g)
{
g.setFont(new Font("Arial",Font.BOLD,36));
FontMetrics fm=g.getFontMetrics();
String str="=>> "+hr+":"+min+":"+sec+":"+counter;

Dimension d=getSize();
int x=(d.width-fm.stringWidth(str))/2;
g.drawString(str,x,d.height/2);
}
}

Sunday 4 November 2012

What are the Benefits of Java Language? , What are the Features of java language?


What are the Benefits of Java Language? , What are the Features of java language?


a. Java is Platform Independent

b. Java is Portable – Java code can be transferred from one machine to another machine

c. Java is distributed – Java code is capable to run on Multiple JVM environment

d. Network Centric – Using network classes java.net package (e.g. Socket & ServerSocket) classes) java programmer can very easily write program for network application. It is unbelievably easy to write any network related application using java
.
e. Security – Java is designed and created with security features in mind. It allows user to download un trusted code from internet and run in on the machine without any harm. It cannot infect the machine with virus etc.

f. Dynamic and Extensible – Java Code is extensible and dynamic as java is object oriented language. Classes are stored in separate files and they are loaded only when need using JRE.

g. Performance – Java language allows programmer to write thread based program which essentially allow better utilization of resources (i.e. CPU, memory etc.). Java consume much lesser resource due to light weight thread concepts. As java’s bytecode is interpreted by JRE at run time, its performance is slightly slower compare to other language e.g. C / C++.

h. Java is Open Source – Development cost of creating java based software is much lower compare to other languages like .net as java is freely downloaded and most of the tools around developing java based application are free. Programmer can also get benefit of looking at the java code as java source code is accessible to programmers.

Sunday 16 September 2012

Java Program to explain randomaccessfile class, Write an application that that use randomaccessfile class


Java Program to explain  randomaccessfile class, Write an application that that use randomaccessfile class

Program
import java.io.*;

class Tail
{
public static void main(String args[])
{
try
{
RandomAccessFile raf=new RandomAccessFile(args[0], "r");

long count=Long.valueOf(args[1]).longValue();

long position=raf.length();

position-=count;
if(position<0)
position=0;

raf.seek(position);

while(true)
{
try
{
byte b=raf.readByte();

System.out.print((char)b);

}
catch(EOFException eofe)
{
break;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Friday 14 September 2012

Whai is Degree of a Relationship Set in Datanase Management System(DBMS)?, What is binart, ternary & n-ary relationship?

Whai is Degree of a Relationship Set in Datanase Management System(DBMS)?, What is binary, ternary & n-ary relationship?

Definition
Degree of Relationship Set refers to number of entity sets that participate in a relationship
set.
1) Relationship sets that involve two entity sets are binary (or degree two). Generally, most relationship sets in a database system are binary.
2) Relationship sets may involve more than two entity sets.
E.g. Suppose employees of a bank may have jobs
(responsibilities) at multiple branches, with different jobs at
different branches. Then there is a ternary relationship set
between entity sets employee, job and branch
3) Relationships between more than two entity sets are rare. Most
relationships are binary. 

Binary Vs. Non-Binary Relationships
 Some relationships that appear to be non-binary may be better
represented using binary relationships
 E.g. A ternary relationship parents, relating a child to his/her father and
mother, is best replaced by two binary relationships, father and mother
 Using two binary relationships allows partial information (e.g. only
mother being know)
 But there are some relationships that are naturally non-binary
 E.g. works-on

Thursday 13 September 2012

Define Relationship & Relationship Set in Database Management System(DBMS)

Ques:- Define Relationship & Relationship Set in Database Management System(DBMS)

Answer: A relationship is an association among several entities
Example:
Hayes  
customer entity 

depositor
relationship set

A-102
account entity

A relationship set is a mathematical relation among n >=2 entities,each taken from entity sets
{(e1, e2, … en) | e1 belongs to E1, e2 belongs to E2, …, en belongs to En}
where (e1, e2, …, en) is a relationship

 Example:
(Hayes, A-102) belongs to depositor 



=>>An attribute can also be property of a relationship set.
=>> For instance, the depositor relationship set between entity sets
customer and account may have the attribute access-date

Wednesday 12 September 2012

Java Program for an application that explain super keywords, WAP in Java for super keywords


Java Program for an application that explain super keywords, WAP in Java for super keywords

Program
class base
{
int i;
base(int a)
{
i=a;
}
void show()
{
System.out.println("Base:"+i);
}

}
class derived extends base
{
int i,j;
derived(int a,int b,int c)
{
super(a);
i=b;
j=c;
}
void show()
{
super.show();
System.out.println("Base i:"+super.i);
System.out.println("Derived i:"+i);
System.out.println("Derived j:"+i);
}

}
class superEx
{
public static void main(String args[])
{
derived d = new derived(10,20,30);
d.show();
}
}

Monday 3 September 2012

Write a linux Shell Script to find Greatest and Smallest number in an Array, shell script for maximum & minimum value

Write a linux Shell Script to find Greatest and Smallest number in an Array, shell script for maximum & minimum value


Program
echo "please enter size of an array"
read n

#for loop for taking input from user
for((i=0;i<n;i++))
do
echo " enter $((i+1)) number"
read nos[$i]
done

#for loop for printing the entered number
echo "number entered are"
for((i=0;i<n;i++))
do
echo ${nos[$i]}
done

#main loop
small=${nos[0]}
greatest=${nos[0]}
for((i=0;i<n;i++))
do
#logic for smallest number
if [ ${nos[$i]} -lt $small ]; then
small=${nos[$i]}

#logic for greatest number
elif [ ${nos[$i]} -gt $greatest ]; then
greatest=${nos[$i]}
fi
done

#printing smallest and greatest number

echo "smallest number in an array is $small"
echo "greatest number in an array is $greatest"

Write a linux program in Shell Script to count number of files in a directory


Write a linux program in Shell Script to count number of files in a directory


Program
echo "enter the complete path of your directory"
read n
if [ -z $n ]; then
#print number of files in current directory
ls -l | grep "^-" | wc -l
fi
#first check whether directory exist or not
test -d "$n" && echo -e "number of files in $n is `ls -l $n | grep "^-" | wc -l`\n" || echo -e "not a directory\n"

Write a Linux shell script for Insertion Sort, Write a program in pl/sql program for insertion sorting


Write a Linux shell script for Insertion Sort, Write a program in pl/sql program for insertion sorting


Program

echo "please enter the number"
read n
echo "please enter number in an array"
for((i=0;i<n;i++))
do
read arr[$i]
done

#logic for insertion sort

for((i=1;i<n;i++))
do
j=$i-1
temp=${arr[$i]}
while((j>=0 && arr[j]>temp))
do
arr[$j+1]=${arr[$j]}
j=$j-1
done
arr[j+1]=$temp
done

#printing sorted array

echo "printing sorted array"
for((i=0;i<n;i++))
do
echo ${arr[$i]}
done




Click here to check the output

Write a Linux shell script for Selection Sort, Write a program in pl/sql program for sorting


Write a Linux shell script for Selection Sort, Write a program in pl/sql program for sorting


Program
echo "please enter the number"
read n
echo "please enter number an array"
for((i=0;i<n;i++))
do
read arr[$i]
done

#process for selection sort

for((i=0;i<n-1;i++))
do
small=${arr[$i]}
index=$i
for((j=i+1;j<n;j++))
do
if((arr[j]<small))
then
small=${arr[$j]}
index=$j
fi
done
temp=${arr[$i]}
arr[$i]=${arr[$index]}
arr[$index]=$temp
done

#printing sorted array

echo "printed sorted array is:"
for((i=0;i<n;i++))
do
echo ${arr[$i]}
done

Click here to check the output

Write a linux Shell Script to swap two numbers without using third variable, Swapping in shell script


Write a linux Shell Script to swap two numbers without using third variable, Swapping in shell script


Program
echo "please enter first number"
read a
echo " please enter second number"
read b
echo " value of a before swapping is $a and value of b before swapping is $b"

#swapping
a=$((a+b))
b=$((a - b))
a=$((a-b))

echo "value of a after swapping is $a and value of b after swapping is $b"

Monday 27 August 2012

Java Program that explain the Gregorian calendar class and display current year, current month, current date and also test if is a leap year or not.

Java Program that explain the Gregorian calendar class and display current year, current month, current date and also test if is a leap year or not.

Program

import java.util.*;
class grCalander
{
public static void main(String args[])
{
GregorianCalendar gc = new GregorianCalendar();
int year= gc.get(Calendar.YEAR);
System.out.println(year);
System.out.println(gc.isLeapYear(year));
System.out.println("Month:"+gc.get(Calendar.MONTH));
System.out.println("Week of Year:"+gc.get(Calendar.WEEK_OF_YEAR)); System.out.println("Week of Month:"+gc.get(Calendar.WEEK_OF_MONTH));
System.out.println("Day of year:"+gc.get(Calendar.DAY_OF_YEAR));
System.out.println("Day of week:"+gc.get(Calendar.DAY_OF_WEEK));
}
}

Java Program that add n or 100 number of days to the current date & display new date & time

Java Program that add n or 100 number of days to the current date & display new date & time

Program

import java.util.*;
class Add100days
{
public static void main(String args[])
{
Date date=new Date();
long msec=date.getTime();
msec+=100*24*60*60*1000L;
date.setTime(msec);
System.out.println(date)
}
}

Java Program that generate 30 random numbers, Write java code to generate random numbers


Java Program that generate 30 random numbers, Write java code to generate random numbers

Program
import java.util.*;
class randomnos
{
public static void main(String args[])
{
Random R = new Random();
for(int i=0;i<30;i++)
System.out.println(R.nextInt()%30);
}
}

Java Program that generates custom exception or user define exception, Write a java code to illustrate custom exception or user define exception


Java Program that generates custom exception or user define exception, Write a java code to illustrate custom exception or user define exception


Program
class negativeArgExc
{
public static void main(String args[])throws NegativeArgumentException
{
int i;
i=Integer.parseInt(args[0]);
if (i<0)
throw new NegativeArgumentException("Negative Commandline Argument");
}
}
class NegativeArgumentException extends Exception
{
public NegativeArgumentException(String str)
{
super(str);
}
}

Java Program to explain different methods of catch class


Java Program to explain different methods of catch class


Program
class catchMethod
{
public static void main(String args[])
{
int i,j,ans;
i=1;
j=0;
try
{
ans=i/j;
System.out.println("Ans is:"+ans);
}
catch(ArithmeticException e)
{
System.out.println("filIn: " + e.fillInStackTrace());
System.out.println("cause: " + e.getCause());
System.out.print("trace: "); 
e.printStackTrace();
System.out.println("messa: " + e.getMessage());
}

}
}


Java Program to explain the concept of throw clause


Java Program to explain the concept of throw clause


Program
class throwClause
{
public static void main(String args[]) throws Exception
{
int no=24,i,quot;
for(i=0;i<=5;i++)
{
try
{
quot=no/(i-2);
System.out.println("Quotient:"+quot);
}
catch(ArithmeticException e)
{
System.out.println("Exception Occure at i:"+i);
}
}
}
}

Java Program to explain Super Keyword, write a program in java using super keyword through extend class of class inheritance


Java Program to explain Super Keyword, write a program in java using super keyword through extend class of class inheritance

Program
class base
{
int i;
base(int a)
{
i=a;
}
void show()
{
System.out.println("Base:"+i);
}

}
class derived extends base
{
int i,j;
derived(int a,int b,int c)
{
super(a);
i=b;
j=c;
}
void show()
{
super.show();
System.out.println("Base i:"+super.i);
System.out.println("Derived i:"+i);
System.out.println("Derived j:"+i);
}

}
class superEx
{
public static void main(String args[])
{
derived d = new derived(10,20,30);
d.show();
}
}

Java Program to explain Method Modifier using Extend Class & Abstract Class


Java Program to explain Method Modifier using Extend Class & Abstract Class

Program
abstract class A
{
int a;
public abstract void show();
}
class B extends A
{
int b,c;
B(int i,int j,int k)
{
a=i;
b=j;
c=k;
}
public void show()
{
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
}
final void disp()
{
System.out.println("Inside B Class Final Method");
}
}
class C extends B
{
static int i=10;
C(int i,int j,int k)
{
super(i,j,k);
}
public static void prt()
{
i=i*100;
System.out.println("Static Method:"+i);
}
private void display()
{
System.out.println("Private Method");
}
protected void msg()
{
System.out.println("Proctected Method");
}
/* void disp()
{
System.out.println("Final");
} Not Possible bcoz it is declared as final in the base class*/
}
class Methodmodi
{
public static void main(String args[])
{
B b = new B(10,20,30);
C c= new C(10,20,30);
c.show();
C.prt();
//c.display();Not possible bcoz it is private
c.msg();
c.disp();
}
}

Java Program to illustrate Variable modifier like Public, Private, Protected, Java code to explain any three modifier


Java Program to illustrate Variable modifier like Public, Private, Protected, Java code to explain any three modifier


Program
class var
{
public int a;
final int b=24;
static int c;
private int d;
protected int e;

public void show()
{
System.out.println("Public:"+a);
System.out.println("Private:"+d);
System.out.println("Protected"+e);
System.out.println("Final:"+b);
System.out.println("Static:"+c);
}
}
class variablemodi
{
public static void main(String args[])
{
var v=new var();

v.a=10;
//v.d=20; bcoz it is private variable cant access outside the class
v.e=30;
//v.b=40; bcoz it is final variable so it is constant
var.c=50;
v.show();
}
}

Java Program to find area of circle using Final Class, Write a java program to find area of circle using final keyword


Java Program to find area of circle using Final Class, Write a java program to find area of circle using final keyword


Program
final class Fincircle
{
double area;
double radius;
final double PHI=22.0/7.0;
Fincircle(double r)
{
radius =r;
}
double Area()
{
area=PHI*radius*radius;
return area;
}
}
class finalcls
{
public static void main(String args[])
{
double ar;
Fincircle F=new Fincircle(3.5);
ar=F.Area();
System.out.println("Area of Circle is:"+ar);
}
}

Java Program to find area of Rectangle & circle using Abstract Class, Write a program in java explaining program Abstract Class, class modifiers


Java Program to find area of Rectangle & circle using Abstract Class, Write a program in java explaining program Abstract Class, class modifiers 


Program
/*  This is a example of Abstract  Class */
abstract class shape
{
double area;
final double PHI=22.0/7.0;
abstract double Area();
}
class Rectangle extends shape
{
double length,breadth;
Rectangle(double x,double y)
{
length=x;
breadth=y;
}
double Area()
{
area=length*breadth;
return area;
}
}
class Circle extends shape
{
double radious;
Circle(double r)
{
radious=r;
}
double Area()
{
area=PHI*radious*radious;
return area;
}
}
class Abscls
{
public static void main(String args[])
{
Rectangle rec=new Rectangle (6.0,4.0);
double ar;
ar=rec.Area();
System.out.println("Area of Ractangle is:"+ar);
Circle cir = new Circle(5.25);
ar=cir.Area();
System.out.println("Area of Circle is:"+ar);
}
}

Saturday 25 August 2012

Java Program for Matrix Multiplication, Write a program in java language for Matrix Multiplication


Java Program for  Matrix Multiplication, Write a program in java language for Matrix Multiplication

Program
class multi
{
public static void main(String args[])
{
int k=1;
int arr[][],arr2[][],arr3[][];

arr= new int[3][3];
arr2=new int[3][3];
arr3=new int[3][3];

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
arr[i][j]=k;
arr2[i][j]=++k;
k++;
}

}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
for(int p=0;p<3;p++)
{
arr3[i][j]+=arr[i][p]*arr2[p][j];
}

}
}

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+arr[i][j]);
}
System.out.println();

}
System.out.println();
System.out.println();

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+arr2[i][j]);
}
System.out.println();
}
System.out.println();
System.out.println();
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+arr3[i][j]);
}
System.out.println();
}
}
}

Java Program for printing pyramid of 10 numbers, Write a java program that display pyramid of 10 numbers


Java Program for printing pyramid of 10 numbers, Write a java program that display pyramid of 10 numbers


Program
class pyramid
{
public static void main(String args[])
{
for(int i=1;i<=10;i++)
{
for(int s=20;s>=i;s--)
{
System.out.print(" ");
}
for(int j=1;j<=i;j++)
{
System.out.print(" "+j+" ");
}
System.out.println();
}
}
}

Java Program to find square root and power, Write a java program that finds square root and power


Java Program to find square root and power, Write a java program that finds square root and power


Program
class powsq
{
public static void main(String args[])
{
int i=Integer.parseInt(args[0]);
int j=Integer.parseInt(args[1]);

double sq=Math.sqrt(i);
double pw=Math.pow(i,j);

System.out.println("Square root is:"+sq);
System.out.println("Power is:"+pw);
}
}

Java Program for wrapper class. Write a java program for using any five methods for wrapper class.


Java Program for wrapper class. Write a java program for using any five methods for wrapper class.


Program
class Wrappercls
{
public static void main(String args[])
{
double no1=0;
double no2=0;
double no3=no1/no2;
System.out.println("no3:"+no3);
System.out.println("isInfinite:"+Double.isInfinite(no3));
System.out.println("isNaN:"+Double.isNaN(no3));
System.out.println("Max Value:"+Double.MAX_VALUE);
System.out.println("Min Value:"+Double.MIN_VALUE);
System.out.println("Positive Infinity:" + Double.POSITIVE_INFINITY);
System.out.println("Negative Infinity: " + Double.NEGATIVE_INFINITY);
}
}

Java Program to find Radius of a circle, Write a java Program that finds a radius using this variable


Java Program to find Radius of a circle, Write a java Program that finds a radius using this variable


Program
class radius
{
double pie,area,r;
radious(double p,double a)
{
this.pie=p;
this.area=a;
}
void calculate()
{
r=(area/(2*pie));
System.out.println("Radius of circle is: "+r);
}
}
class Test
{
public static void main(String args[])
{
radius rd=new radius(3.14,22.24);
rd.calculate();
}
}

Java Program to perform Stack operations like Push, Pop, Peep, Change, Write a java Program for stack using constructor, define methods with parameter etc


Java Program to perform Stack operations like Push, Pop, Peep, Change, Write a java Program for stack using constructor, define methods with parameter etc

Program
class stack
{
int stck[] = new int[10];
int top;

stack() //Default Constructor
{
top=-1;
}
void push(int item)
{
if(top==9)
System.out.println("Stack is Overflow");
else
top++;
stck[top]=item;
}
int pop()
{
if(top<0)
{
System.out.println("Stack is Underflow");
return 0;
}
else
{
return stck[top--];
}
}
void peep(int l)
{
if(top-l+1<=0)
System.out.println("Stack Underflow");
else
System.out.println(" The value of "+l+" location in stack::"+stck[top-l+1]);
}
void change(int l,int x)
{
if(top-l+1<=0)
System.out.println("Stack Underflow");
else
stck[top-l+1]=x;
}
}

class MyStack
{
public static void main(String args[])
{
stack Mystack1 = new stack();
stack Mystack2 = new stack();
//Push
for(int i=0;i<10;i++)
Mystack1.push(i);
for(int i=10;i<20;i++)
Mystack2.push(i);

//Peep Operation
Mystack1.peep(5);
Mystack2.peep(4);

//Change Operation
Mystack1.change(5,25);
Mystack2.change(4,50);

//Peep Operation
Mystack1.peep(5);
Mystack2.peep(4);

//Pop
System.out.println("Stack in Mystack1");
for(int i=0;i<10;i++)
System.out.println(Mystack1.pop());

System.out.println("Stack in Mystack2");
for(int i=0;i<10;i++)
System.out.println(Mystack2.pop());
}

Java Program that illustrate StringBuffer class & using different method like append, insert, capacity, lenth, charat etc.


Java Program that illustrate StringBuffer class & using different method like append, insert, capacity, lenth, charat etc.


Program
class stBuffercls
{
public static void main(String args[])
{
StringBuffer sb = new StringBuffer("Delhi");

//Length
System.out.println("Length of Buffer String:"+sb.length());
//Capacity
System.out.println("Capacity of Buffer String:"+sb.capacity());
//charAt
System.out.println("CharAt(3) from Buffer String:"+sb.charAt(3));
//Append
System.out.println("String After Append Operation:"+ sb.append(" Hai Meri Jaan"));
//Insert
sb.insert(0,"Yeh ");
System.out.println("String After insert operation:"+ sb);
}
}

Laptops