Search This Blog

If you like any posts in this blog then click this icon which is present under the post

Sunday, 31 July 2011

Program to Implement abstract class


import java.io.*;
import java.util.*;
abstract class Employee
{
            private String name;
            private int ssn;
            Employee(String s,int a)
            {
                        setname(s);
                        setssn(a);
                        getname();
                        getssn();

Program to Implement Multilevel Inheritance


import java.io.*;
class Point
{
            protected double x,y;
            Point(double a,double b)
            {
                        setpoint(a,b);
                        getx();
                        gety();

Friday, 29 July 2011

for looping statement

      for statement is used to execute a statement or a group of statements repeatedly for a known number of times. The general form is

for(variable=initial value;test condition;increment or decrement)
{
             Body of the loop;
}
next statement;

Difference between while and do...while statements


                while is an entry control statement. so if the test condition is false the loop will not be executed.
               
                do ….while is an exit control statement. So irrespective of the condition value, the body of the loop will be executed atleast once. 

do ..... while statement


                The general form is

do
{
      Body of the loop;
}
while(test condition);
next statement;

While statement


This is a simple looping statement. The general form is

while(test condition)
{
        Body of the loop;
}
next statement;

Looping statements


                Looping statements are used to execute a group of statements repeatedly until some condition is satisfied. The looping statements are

                                1. while statement
                                2. do ….. while statement
                                3. for statement

Switch case statement


Switch statement is an extension of if else statement. This permits any number of branches. The general form is

switch(expression)
{
                case label1:
                                statement block-1;
                                break;
                case label2:
                                statement block-2;
                                break;
-----------------------------------------
-----------------------------------------
                case labeln:
                                statement block-n;
                                break;
                default       :
                                default statement;
                                break;
}


Wednesday, 27 July 2011

Program for Domain Name System (DNS) using UDP


Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientdns12
{
            public static void main(String args[])
            {
            try
            {
                        DatagramSocket client=new DatagramSocket();
                        InetAddress addr=InetAddress.getByName("127.0.0.1");

Program for Reverse Address Resolutuion Protocol (RARP) using UDP

Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp12
{
            public static void main(String args[])
            {
            try
            {
                        DatagramSocket client=new DatagramSocket();
                        InetAddress addr=InetAddress.getByName("127.0.0.1");

Program for Address Resolutuion Protocol (ARP) using UDP


Client: 
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp12
{
            public static void main(String args[])
            {
            try
            {
                        DatagramSocket client=new DatagramSocket();
                        InetAddress addr=InetAddress.getByName("127.0.0.1");

Program for Domain Name System (DNS) using TCP


Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientdns
{
            public static void main(String args[])
            {
            try
            {         
                        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                        Socket clsct=new Socket("127.0.0.1",139);

Program for Reverse Address Resolutuion Protocol (RARP) using TCP


Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
{
            public static void main(String args[])
            {
            try
            {         
                        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                        Socket clsct=new Socket("127.0.0.1",139);

Program for Address Resolutuion Protocol (ARP) using TCP


Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
{
            public static void main(String args[])
            {
            try
            {         
                        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

Monday, 25 July 2011

Program to Demonstrate switch case in Java

import java .io.*;
class switch
{
public static void main(Strings args[])
{
for (int i=o;i<4;i++)
{
switch(i)
{
case 0: if(i<1)
                        System.out.println(+i+”less than”+1);
            case 1: if(i<2)
                        System.out.println(+i+”less than”+2);

Saturday, 23 July 2011

Nested if .... else Statement


                This statement is formed by joining if ….. else statements either in the block or in the else block or both. The general form is

if(test condition-1)
{
    if(test condition-2)
    {
    Statement block-1;
    }
    else
    {
    Statement block-2;

else ........ if Ladder


                else…..if  ladder statement is used to take multi way decision. This statement is formed by joining if ……..else statements in which each else contains another if ….else. The general form is

if(test condition-1)
{
Statement block-1;
}
else if(test condition-2)
{
Statement block-2;
}
-------------------------
-------------------------
else if (test condition-n)
{
Statement block-n;

Friday, 22 July 2011

if ........ else Statement


     if….. else statement is used to  execute one group of statements if the test condition is true or other group if the test condition is false. The general form is

     if(test condition)
     {
           Statement block-1;
     }
     else
     {
          Statement block-2;
     }
     Next statement;

Simple if Statement


     Simple if statement is used to execute or skip one statement or group of statements for a particular condition. The general form is

     If(test condition)
     {
         Statement block;
     }
     Next statement;

Control Structure


DECISION MAKING STATEMENTS

     Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The decision making statements are,

1.       Simple if statements
2.       if……….else statements
3.       else……….if ladder
4.       nested if
5.       switch statement

LOOPING STATEMENTS

Type Conversion in Expressions


AUTOMATIC TYPE CONVERSION

     An expression is defined as a linear combination of operands and operators. If the operands are of different data types (int, float etc) the lower data type operand is automatically converted to the higher data type before execution. This process of conversion is called automatic type conversion. The result is of the higher type.

Example

Let,
     float b=10.7;
     int c=7;
Then b+c=17.7. here int c is converted to float.

The table given below shows the conversion.

Thursday, 21 July 2011

Operators in Java

     An operator is a symbol which represents some operation that can be performed on data. There are eight operators available in java to carry out the operations. They are
1.       Arithmetic operators
2.       Relational operators
3.       Logical operators 
4.       Short hand assignment operators
5.       Increment and decrement operators
6.       Conditional operators
7.       Bitwise operators
8.       Special operators

Java Environment

     Java environment has large number of development tools and number of classes and methods. The development tools are part of a system called Java Development kit (JDK). The classes and methods are of the Java Standard Library (JSL) also known as Application Programming Interface (API).

Java Development Kit (JDK)
                 
     This contains tools for developing and running java programs. The tools are
applet viewer - This is used to run java applets.
javac                   - Java compiler which converts java source code to java  byte code.
java                     - Java interpreter which converts java byte code to machine code.

Wednesday, 20 July 2011

Program for Client - Server communication to perform Chat operation using UDP in Java


client
import java.io.*;
import java.net.*;
import java.util.*;
class Client13
{
            public static void main(String args[])
            {
            try
            {
                        DatagramSocket client=new DatagramSocket();

Program for Client - Server communication to access Date using UDP in Java


Client
import java.io.*;
import java.net.*;
import java.util.*;
class Client12
{
            public static void main(String args[])
            {
            try
            {
                        DatagramSocket client=new DatagramSocket();

Program for Client - Server communication to perform Echo Opreration using UDP in Java


     The DatagramSocket object is used to establish communication between Client and Server.
client
import java.io.*;
import java.net.*;
import java.util.*;
class Client1
{
            public static void main(String args[])
            {
            try
            {
                        DatagramSocket client=new DatagramSocket();

Tuesday, 19 July 2011

Difference between application and applets

    Java is a pure object oriented general purpose language. Using java we can develop two types of programs. They are
Application programs
* Applet programs
  
 Applications are programs to do jobs on a local computer.

    
Applets are programs that has ability to run on internet through a web browser.

Monday, 18 July 2011

Program to Return the Object to main class in Java

     This program returns the object to the main class from the sub class.

import java.io.*;
class robject
{
int a;
robject(int x)
{

Program to implement final Keyword in Java

 This program is used to implement final variable. Final variable is constant variable which is unchanged. 

import java.io.*;
import java.util.*;
class increment
{
private int i;
private final int J;
increment()
{
J=2;  // final value

Program to Demonstrate Static & this Keyword


     This program is used to demonstrate static variable, static member and this keyword.

import java.io.*;
import java.util.*;
class Employee
{
            String fn,ln;
            static int count=0; 
            Employee( String s,String s1)
            {

Program to Implement Method Overloading in Java


     This is a program to implement method overloading which passes the integer,float,double variable as a argument.

import java.io.*;
import java.util.*;
class Method1
{
            void add(int a,int b)
            {

Program to Implement Constructor Overloading in Java


     This program is used to implement constructor overloading. Here the integer, float, double variable and object is passed as arguments.
 
import java.io.*;
import java.util.*;
class Box1
{
            int wt,ht,dt,a;
            float wt1,ht1,dt1,a2;
            double wt2,ht2,dt2,a3;
            Box1()

Program to Implement Stack in Java


    This program is used to demonstrate the Stack operations PUSH & POP with the help of Switch an if statements.


import java.io.*;

import java.util.*;

class Stack

{

    int a[]=new int[10];

    int top=0;

    Stack()

Wednesday, 13 July 2011

Program to demonstrate the Switch case and If statement


This a Program to demonstrate the Switch case and If statement by calculating the discount amount of a cloth products

Program:
 
import java.io.*;
import java.util.*;
class Cloth1
{
void purchase()
                {
                Scanner s=new  Scanner(System.in);
                System.out.println("What do  you want to Purchase? \n 1)Mill Cloth \n 2)Handloom Cloth \n 3)Exit");

Program to Chat between Client & Server in Java

     This program enables us to chat between the client and server. This is a bidirectional data transfer.

Client


import java.io.*;
import java.net.*;
import java.util.*;
class Client
{
            public static void main(String arghs[])
            {
                        try
                        {
                                    Socket clientskt=new Socket("127.0.0.1",1024);
                                    while(true)

Program for Client - Server Communication to Display date using Java


     This is a program for displaying the date from server to client. Client is requesting the server to retrieve the current date.

Client:

import java.io.*;
import java.net.*;
import java.util.*;
class Client
{
            public static void main(String args[])
            {
            try
            {
                        Socket clsct=new Socket("127.0.0.1",139);

Wednesday, 6 July 2011

Comments in java program

     Comments are included in a program for better understanding about the program. There are three types of comments in java. They are
               1 .  Single line comment
               2 . Multi line comment
               3 . Documentation comment

Single line comment
   
     Single line comment should end on a single line and should begin with double slash (//).
                          Example:  //Java is flexible

Multi line comments

     If the comment exceeds one line, multiline comment is used. these comments must begin with /* and end with */.
         Example: /*This program is used to calculate
                              the salary of the employees*/

Documentation comments

     This comment is used to generate documentation automatically. these comments must begin with /** and ends with */. Java scans the program finds /** and */ and generate documentation automatically with the help of the documentation utility javadoc .

Program for Client - Server Communication using Java


Client Program

       Socket object must be created to communicate with server. The Socket object is clsct in the following program . 

import java.io.*;
import java.net.*;
import java.util.*;
class Client

Tuesday, 5 July 2011

Program to know the Sockets of a System using Java

     This is the program to find out the inused ports in the system. The range between 0-1024 ports are reserved for internal system usage. In that some of the ports are unused. Socket object is used to find out the required ports. Socket is created with the combination of IP address and port number.

import java.io.*;
import java.net.*;
class Sock
{
public static void main(String args[])
{
                        for(int port=0;port<1024;port++)

Program to know the HTML content of a Website in Java

   This is the program to display or retrive the HTML content of a URL or Website. In the URL object 'a' is used to pass the URL name or address as argument to URL class. By using the BufferedReader and InputStreamReader the HTML content is retrived . openStream() is used open the given URL.

import java.io.*;
import java.net.*;
public class Main {
   
        public Main() {
    }
   
    public static void main(String[] args) {
        try{
            String obj;

Program to Identify Protocol, Host, File, Path of a URL in Java

     The getProtocol() function is used to return a protocol which is accessing a given URL.
     The getHost() function is used to display the Host name of a given URL.
     The getPort() function is used to display a  Port number.
     The getFile() function is used to display the File name which is present given URL. 
     The getQuery() function is used to display the content which is present after question mark (?) of a given URL.

import java.net.*;
public class Main {
   
    public Main() {
    }
   
    public static void main(String[] args) {
    try
    {      
        URL a=new URL("http://www.google.com?hello%2osachin%20");

Monday, 4 July 2011

Program to Implement Number Pattern in Java

class Pattern
{
                public static void main(String args[])
                {
                                int twod[][]=new int[4][];
                                twod[0]=new int[1];
                                twod[1]=new int[2];
                                twod[2]=new int[3];
                                twod[3]=new int[4];

Program to Implement Library Funtions in Java


import java.io.*;
import java.math.*;
class three
{
                public static void main(String args[])
                {
                                System.out.println("Square Root of 44 is "+Math.sqrt(44));
                                System.out.println("Sin of 90 is "+Math.sin(90));
                                System.out.println("Cos of 0 is "+Math.cos(0));
                                System.out.println("Tan of 45 is "+Math.tan(45));

Friday, 1 July 2011

Program for Type Conversion in Java

import java.io.*;
class Typeconversion
{
    public static void main(String args[])
    {
        double i;
        float sum1=0.0f,sum=0.0f;
        for(i=1;i<=20;i++)
        {
            sum1=(float)i;
            sum+=(1/sum1);

Program for Escape Sequence in Java

import java.io.*;
class Escape
{
    public static void main(String args[])
    {
        System.out.println("P    Q    P&Q    P|Q      P^Q");
        int i,x,y,z;
        int p[]={0,0,1,1};
        int q[]={0,1,0,1};
        for(i=0;i<4;i++)

Program for Gallons to Liter Conversion in java

import java.io.*;
class Conversion
{
    public static void main(String args[])
    {
        double ans;
        for(int i=1;i<=20;i++)
        {
            ans=i*3.84;

Program for Display Alphabets & Sorted Numbers in Java

import java.io.*;
class Alpha
{
    public static void main(String args[])
    {
        String s[]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
        int n=s.length;
        for(int i=0;i<n;i++)
        {
            System.out.print(s[i]);
        }
        int s1[]={1,54,26,8,32,65};
        int n1=s1.length;

Followers