Showing posts from June, 2011

Java OOP Codes Summary

Clock Applet in java

In this example we will see display the time in an applet in the time format like: hours, minutes and then seconds (hh:mm:ss). Here, the ClockApplet is a class name extends from the Applet class and implements to the Runnable interface. There are two threads used in this program. There are three methods have been used in this program to display the current time

Java version of Clock Apple is given bellow :
import java.applet.Applet; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.util.Date; import java.util.Random;

Simple Calculator program in java using applet

Java version of Simple Calculator is given bellow :
package frame; import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField;

Bubble Sorting in Java

Bubble Sorting is an algorithm in which we are comparing first two values and put the larger one at higher index. Then we take next two values compare these values and place larger value at higher index. This process do iteratively until the largest value is not reached at last index. Then start again from zero index up to n-1 index. The algorithm follows the same steps iteratively unlit elements are not sorted

First Applet in java

First Applet Applet viewer is a command line program to run Java applets. It is included in the SDK. It helps you to test an applet before you run it in a browser. Before going any further, lets see what an applet is? An applet is a special type of application that's included as a part of an HTML page and can be stored in a web page and run within a web browser. The applet's code gets transferred to the system and then the Java Virtual Machine (JVM) of the browser executes that code and displays the output.. So for running the applet,  the browser should be Java enabled. To create an applet, we need to define a class that inherits the Applet.

Create Radio Button with Text Field in Java

In this program, you will learn how to set the radio buttons in a group so that only one can be selected at a time. This program shows five radio buttons with labeled by plain,bold,italic,boldItalic .This program also show a label which contains the text "Font style changes" but when you click on any radio button from a Button Group the text of the selected radio button is shown on the label and a message box will be shown with message holds the selected radio button label. This is done through the generating event for the different-different radio buttons.

Create Check Box in Java

This section illustrates you how to create a Check Box component in Java Swing.In this section, you can learn simply creating the Check Box in Java Swing. Check Boxes are created in swing by creating the instance of the JCheckBox class using it's constructor which contains the string which has to be shown beside the check box on the frame or window

Find out the prime number in java

 Prime number
We will be read how to get prime number between 1 to given number. First of all we have to define a class "primenum ". Java  util package has a input  in which  Scanner input=new Scanner( is used for reading the input stream . As in this program we are going to insert certain instruction by creating  Scanner class.
Now applying in this program we use two 'for' loop. For loop will start from 1 to entered number. And another loop will start and divide it from 2 to less than those number. If number is divided by any number that means it is not prime otherwise prime number.

How to Check Perfect Number in Java

A perfect number is a positive integer where the sum of all its positive divisors, except itself, is equal to the number itself.  For example 6 is a perfect number as 1,2 and 3 are its divisors and the sum of divisors=1+2+3=6. Here we have created a program that will take the number from the user and reports whether it is perfect or not.

Factorial of a non negative integer in Java

Description of this program : This Java programming will teach you the methods for writing program to calculate factorial of any given number. First of all define a class "Factorial" under the Java util package. Java util package has a Scanner is used for reading the input . Take an integer variable as fact=1 and insert the message in the System method. Now applying for loop with conditions as integer i=1(intializer), i<=x and i++ as increment operator. So output result will be like fact=fact*i.

Exponential value for given base in Java

Java version of this program is given bellow :
/** * To change this template, choose Tools | Templates * and open the template in the editor. */ package power; import java.util.Scanner; /** * * @author ACHCHUTHAN */ public class Exponential {