Search This Blog

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

Monday, 24 October 2011

CRC Using TCP

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

Wednesday, 12 October 2011

Creating Objects


                 Creating objects means to allocate memory space for all the instance variables of the objects. Step to create an object are,

1. Declare an object.
2. Define the object using new operator. The new operator dynamically allocates memory for an object and returns a reference to it.
The general form is
1. Declare an object.
2. Define the object using new operator. The new operator dynamically allocates memory for an object and returns a reference to it.

Adding Variables and Methods


Adding variables
                 To a variable in a class it must be defined inside the class. At once a variable is added to a class it becomes instance variable.
Example
                class Student
                {
                                int reg_no;
                                 int mark_1;
                                int mark_2;

Defining a Class


                A class is a user defined data type. It contains data and its related methods. The general form is

class classname
{
     Datatype field-1;
      ……………………….
     Datatype field-n;
     Datatype methodname-1(parameter list)
     {
           Body of the method
      }
     ………………………..
     Datatype methodname-n(parameter list)
     {
          Body of the method
     }
}

Classes and Objects


  1.          Java is a pure object oriented language. 
  2.          So java program contains only classes. 
  3.          Each class has its own data items and functions. 
  4.          The data items are called fields and the functions are called methods.
  5.          A class is a user defined data type and it represents the template of the fields and its related methods. 
  6.          Object is a variable of type class and is used to access the class.

Monday, 10 October 2011

Program for Hormonic series

Program
import java.io.*;
class HormonicSeries
{
    public static void main(String args[])
    {
        float s=0f;int n=0;
        try
        {

Wednesday, 28 September 2011

Finding class of the IP address


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

Tuesday, 27 September 2011

RPC and RMI operation in java


Client
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrpc
{
            public static void main(String args[])
            {
            try
            {
                        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                        Socket clsct=new Socket("127.0.0.1",139);
                        DataInputStream din=new DataInputStream(clsct.getInputStream());
                        DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());

Stop and Wait in Java


Client
import java.io.*;
import java.net.*;
import java.util.*;
class Clientstop
{              public static void main(String args[])
                {try{while(true)
                                {String str1=null;
                                BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                                Socket clsct=new Socket("127.0.0.1",139);
                                DataInputStream din=new DataInputStream(clsct.getInputStream());
                                DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());

Bitstuffing in java


Client
import java.io.*;
import java.net.*;
import java.util.*;
class Clientbs
{              public static void main(String args[])
                {try{       BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                                Socket clsct=new Socket("127.0.0.1",139);
                                DataInputStream din=new DataInputStream(clsct.getInputStream());
                                DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());

File operation between client and server


File
Client
import java.io.*;
import java.net.*;
import java.util.*;
class Clientfile
{              public static void main(String args[])
                {try{
                                BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                                Socket clsct=new Socket("127.0.0.1",139);
                                DataInputStream din=new DataInputStream(clsct.getInputStream());
                                DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
                                System.out.println("Enter the file name:");

Tuesday, 13 September 2011

Program for Hamming code & CRC in Java


HAMMING CODE :
CLIENT
import java.io.*;
import java.net.*;
import java.util.*;
import java.math.*;
class Clienthamming
{          public static void main(String args[])
            {
            try      
            {         
                        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                        Socket clsct=new Socket("127.0.0.1",139);
                        DataInputStream din=new DataInputStream(clsct.getInputStream());
                        DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
                        int x,y,z;
                        System.out.println("Enter the no.of bits in data word:");
                        String strr=in.readLine();
                        x=Integer.parseInt(strr);
                        System.out.println("Enter the no.of redundant bits:");

Thursday, 11 August 2011

Labelled Loops


                Java has a facility to give labels to a block of statements.
The general form is

label : Looping statement

Where,
                label                            -  valid java variable name
                looping statement – for,do,while

Continue statement - skipping a part of a loop


               Continue statement is used to skip a part in the body of the loop. When this statement is used inside a loop it skips the execution of the remaining statements in the body of the loop after the keyword continue and continue with the next iteration.

The general form is

continue;

                When this statement is used inside a for loop the control is transferred to the beginning of the loop. If it is used inside while or do loops the control is transferred to the test condition.

Break Statement - Jumping out of a loop


                Break statement is used to exit from a loop while the test condition is true. This statement can be used within a for, while, do-while or switch statement.

The general form is
                                               
break;

                When the break statement is executed inside a loop, the execution of the loop is terminated and the program continues with the statement following the loop. If break statement is used in nested loops, it will exit from the loop containing it.

Program for Parity bit Generator and Checker using TCP/IP


Client
import java.io.*;
import java.net.*;
import java.util.*;
class Clientparity
{          public static void main(String args[])
            {
            try       
            {         
                        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
                        Socket clsct=new Socket("127.0.0.1",139);
                        DataInputStream din=new DataInputStream(clsct.getInputStream());
                        DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());

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. 

Followers