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.

Laptops