Monday, March 22, 2021

project2021

 

project2021

Submit the following details in the comment column

1.Register Number

2. Name of the student  
3. Class 

Thursday, March 11, 2021

iibscitjavainternalmarks

                

Reg.No         Name           First Internal 

B9S17901 S.Hajira Banu                 27
B9S17902 J.Keerthana                 28
B9S17903 R.Murugeswari         28
B9S17904 K.Muthu Lakhsmi         27
B9S17905 R.Nandhini                 28
B9S17906 K.Nandhini Sivani         28
B9S17907 S.Nithya Bharathi         28
B9S17908 M.Poongothai                 27
B9S17909 M.Reena                         28
B9S17910 K.Sarmila                  29
B9S17911
B9S17912 N.Abu Thahir                 28
B9S17913 R.Arimani                 28
B9S17914 K.Arun Kumar         28
B9S17915 S.Dinesh pandiyan         26
B9S17916 A.P.Gokul anath         27
B9S17917 G.Gokul nath                 27
B9S17918 C.Gowtham                 28
B9S17919 S.Harshavarthan         27
B9S17920 S.Hema Vigesh         22
B9S17921 M.Jeyaraj                 28
B9S17922 M.Kamala Kannan         27
B9S17923 S.Karthik                         28
B9S17924 M.Kaviyarasan         28
B9S17925 M.Lukeshnathan 22
B9S17926 M.Manilandaprabhu 28
B9S17927 R.Manivannan         27
B9S17928 R.Manoj Kumar         27
B9S17929 R.Meenakshi Sundaram 28
B9S17930 M.Mohamed Kani         26
B9S17931 J.Mohan                         26
B9S17932 B.Periyasamy                 26
B9S17933 M.Prakash                 27
B9S17934 A.Raja Pandi                 26
B9S17935 S.Raja Rajan                 27
B9S17936 S.Sakthi                         27
B9S17937 P.Seenivasan                 27
B9S17938
B9S17939 M.Sonai                         22
B9S17940 A.Surya                         28
B9S17941 N.Syed Ibrahim         25
B9S17942 D.Thanga pandi        22
B9S17943 C.Udhaya pandi 22
B9S17944 S.Veeranan                 26
B9S17945 K.vel Muthu Pandian      27
B9S17946 S.Velmani                 26
B9S17947 S.Velusamy                 27
B9S17948 T.Venkateshwaran         27
B9S17949 P.vinoth Pandi                 27


B9S18601 B.Jothika                          28
B9S18602 M.Lalithambugai          26
B9S18603 V.Sneha                          27
B9S18604 R.Aathi Sankara Pando    23
B9S18605
B9S18606 E.Ajay                           26
B9S18607 S.Akash                          26
B9S18608 T.Arun Kumar                28
B9S18609 M.Bala Murugan          27
B9S18610 M.Dhanu Prakash        26
B9S18611 M.Dinesh Kumar          27
B9S18612 A.Gowtham                  23
B9S18613 N.Guru Muneeswaran   24
B9S18614 R.Kannan                  25
B9S18615 N.Karhick                  28
B9S18616 M.Karthick Kumar        25
B9S18617
B9S18618 A.Karthi Keyan          27
B9S18619 V.Karthi Keyan          18
B9S18620 S.Kathikeyarajan          26
B9S18621 S.Karunakaran        25
B9S18622 A.Mahendhira Boopathi    27
B9S18623 R.Mauiswaran                26
B9S18624 M.Mathayanai                20
B9S18625 S.Naga Mani                  28
B9S18626 B.Pandi Deva                  25
B9S18627 M.Praveen                  26
B9S18628
B9S18629 A.Prem Kumar          27
B9S18630
B9S18631 S.Raj Kumar                  17
B9S18632 M.Sakthi Murugan       26
B9S18633 S.Saravanan                  27
B9S18634 M.Sathish Kumar          25
B9S18635
B9S18636 M.Senthil Raja          25
B9S18637
B9S18638 C.Sudhakar                26
B9S18639 G.Suren                          16
B9S18640 R.Varun                          26
B9S18641 M.Vel Murugan          24
B9S18642 M.Vijay Kumar          22











Monday, March 1, 2021

IIitjavaonlinenotes

                                             Interface

        An interface is basically a kind of class.  Like classes , interfaces contain methods and variables but with major difference. The difference is that interfaces define only abstract methods and final fields. This means that interfaces do not specify any code to implement these methods and data fields only constants.

        Interfaces are used as super classes whose properties are inherited by classes. It is therefore necessary to create a class that inherits the given interface.

Class classname implements interfacename

{ body of class name

}

        Here the class classname  implements the interface interfacename.

A more general form of implementation may look like this

Class classname extends superclass implements interface1, interface2

{body of class name

}

This shows that a class can extend another class while implementing interfaces.

When a class implements more than one interface , they are separated by  a comma.

        To implement the multiple inheritance concept since you can not directly implement the multiple inheritance concept, you use interface to have multiple base classes for a sub classes.

interface area

{ final static float pi =3.147l

float compute (float x, float y);

}

Class Rectangle implements Area

{

Public float compute (float x, float y0

{ return (x * y);

}   }

Class circle implements Area

{ public float compute( float x, float y)

{ return (pi * x * x)

}   }

Class interfacetest

{ public static void main (string args[])

{ Rectangle rect = new Rectangle();

Circle cir =new circle();

Area area;

area = rect;

System.out.println(“Area of rectangle” +area.compute(10,20);

area =cir;

System.out.println(“area of circle”+ area.compute(10,0));

}

}

Interface look like a class but it is not a class. An interface can have methods and variables just like the class but the methods declared an interface are by default abstract ( only

Java programming language does not allow you to extend more than one class , However you can implement more than one interfaces in your class.

interface A

{

 int x=10;

}

interface B

{

   int x=100;

}

class hello implements A,B

{

  public static void main(String args[])

{

System.out.println(A.x);

System.out.println(B.y);

}

}

 

       A method without body to implementation is known as abstract method. A method must always be declared in an abstract class or in other words you can say that if a class has an abstract method

Without bothering about the implementation part, we can active the security of implementation.

Multiple inheritance is not allowed, however you can use interface to make use of  it as you can implement more than one interface
         

                Managing I/O of data using Files 

Storing and managing data using files is known as file processing, which includes tasks such as creating files, updating files and manipulation of data.

Java supports many powerful features for managing input and output of data using files. Reading and writing of data in a file can be done at the level of bytes or characters or fields depending on the requirements of a particular application. 

 Stream classes

        The java.io package contains a large number of stream classes that provide capabilities for processing all bytes of data. These classes may be categorized into two groups based on the data type on which they include

1.  Byte Stream classes: that provides support for handling I/O operation on bytes.

2.  Character Stream classes that provide support for managing I/O operation on character.

Import java.io.*;

Public class copyfile

{ public void main (String args[]) throws IOException

{ FileInputStream in=Null;

FileOutputStream out=Null;

Try

{ in = new FileInputStream(“input.txt”);

Out=new FileOutputStream(“output.txt”);

Int c;

While (( c = in.read() )  != -1)

{ out.write(c ) ;

}

}

Finally

{

 In.close();

Out.close();

}

}

 This is text for copy file

  


 Random access Files

        Files are read or written only sequentially and therefore are known as Sequential files.

        The random access File class supported by the java.io  package allows us to create files that can be used for reading and writing data with random access. That is, we can jump around in the file while using the file such files is known as random access files.

        A file can be created and append for random access by giving a mode string as a parameter to the constructor when we open the file. We can use one of the following two mode strings.

        r    for reading only

        rw  for both reading and writing

        Random access File support a pointer known as file pointer, that can be move the arbitrary positions in the file prior for reading or writing. The file pointer is moved using the method seek() in the random access File. When the file is opened by the statement

file = new RandomAccessFile (“rand.dat”,”rw”)

The file pointer is automatically positioned at the beginning of the file.

Import java.io.*;

Class randomio

{

 Public static void main(String args[])

{

RandomAccessFile file=null;

try

{ file = new RandomAccessFile(“random.dat”,”rw”);

file.writechar(“x”);

file.WriteInt(555);

file.WriteDouble(3.1412);

file.seek(0);

System.out.println(file.readchar());

System.out.println(file.readInt());

System.out.println(file.readDouble());

file.seek(2);

System.out.println(file.readInt());

file.seek(file.length());

file.writeBoolean(file.readBoolean());

file.close();

}

Catch(IOEXception e )

{ System.out.println(e);

}

}

}

                           Applet

       An applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. An applet is embedded in an html page using the Applet tag and hosted on a web server.

        Applets are used to make the web site more dynamic and entertaining.

1.All applets are sub classes of java.applet. Applet class.

2.Applets are not stand-alone programs. Instead, they run within either a web browser or an applet viewer.

3.In general, execution of an applet does not begin at main() method.

4.output of an applet window is not performed by system.out.println(). Rather it is handled with various awt methods such as drawstring.

Life cycle of an applet

1.init()

2.start()

3.paint()

        When an applet is terminated the following sequence of method calls takes place.

1.stop()

2.destroy()

 

Init:   the init method is the first method to be called. This is where you should initialize variables. This method is called only once during the run time of your applet.

Start(): The start() method is called after init(). It is also called to restart an applet after it has been stoped. Note that init() is called once, when the first time an applet is handled whereas start() is called each time an applet’s html document is displayed on screen. So if a user leaves a web page and comes back, the applet resumes execution at start().

Paint(): The paint() method is called each time an awt based applet’s output must be redrawn.

Stop(): The stop()  method is called when an web browser leaves the html document.

Destroy(): The destroy() method is called when the environment determines that your applet needs to be removed completely from memory.

 To execute the applet by html file, create an applet and compile it, after that create an html file and place the applet code in html file.

First.java

Import java.applet.Applet;

Import java.awt.Graphics;

Public class First extends Applet

{

Public void Paint(Graphics g)

{g.drawString(“Welcome”,150,150);

}

}

D:\> javac First.java

No errors or warnings

First.class

D:\>notepad myapplet.html

<html>

<body>

<applet code =”First.class” width =”300” height=”200”>

</applet>

</body>

</html>

D:\> appletviewer myapplet.html

        It works at the client side therefore the reaction time is extremely less.

It is secured.

        Applet provides all necessary support for applet execution. Such as starting and stopping. It also provides methods that load and display images, and methods that load and play audio clips.

        Every java applet needs to go through a series of places from initialization to destruction in order to complete the execution.

  Initialization state

                Applet enters the initialization state when it is first method. This is achieved by calling the init () method of Applet class. The Applet is born, At this state, we may do the following, if required

   -create objects needed by the applet

   - Setup initial value

    - load images or font

    - Setup colors

Running state: Applets enters the running state when the system calls the start() method of applet class. This occurs automatically after the applet is initialized. The start () method may be called more than once.

Idle or stopped state

        An applet becomes idle when it is stopped from running. Stopping occurs automatically when we leave the page containing the currently running applet. We can also do so by adding the stop() method explicitly.

 

Dead state

An Applet is said to be dead when it is removed from memory. This occurs automatically by invoking the destroy () method, When we quit the browser.

Display state

        Applet moves to the display state whenever it has to perform some output operations on the screen. This happens immediately after the applet enters into the running state. The paint () method is called to accomplish this task almost every applet will have a paint() method

Methods that do the following −

  • Get applet parameters
  • Get the network location of the HTML file that contains the applet
  • Get the network location of the applet class directory
  • Print a status message in the browser
  • Fetch an image
  • Fetch an audio clip
  • Play an audio clip
  • Resize the applet

 

                                Inheritance

        Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an important part of oops( Object oriented programming system)

        The idea behind inheritance in java is that you can create new classes that are built upon existing classes when you inherit from an existing class, you can reuse methods and fields of the parent class moreover, you can add new methods and fields in your current class also.

Types of inheritance

Single inheritance: When a class inherits another class, it is known as a single inheritance.

Multilevel inheritance refers to a mechanism in OO technology where one can inherit from a derived class, thereby making this derived class the base class for the new class.

when a class has more than one child classes (sub classes) or in other words more than one child classes have the same parent class then this type of inheritance is known as hierarchical inheritance.

Class employee

{

 float sal = 60000;

}

Class employee1 extends employee

{ float b=1500;

Float temp=sal + b;

public static void main(String args[])
{employee1 ob=new employee1();

System.out.println(“salary amount is “obj.sal);

System.out.println(Ëxtra bonus is “+ obj.temp);

}

}

Salary amount is 6000

Extra bonus   6500

Defining sub class

        A sub class is defined as follows

Class subclassname extends superclassname

{

  Variable declaration;

methods declaration;

}

        The keyword extends signifies that the properties of the super class name are extended to the sub class name. The sub class now contain its own variables and methods as well these of the super class. This kind of situation occurs when we want to add some more properties to an existing class without actually modifying it.

Multilevel inheritance

        A common requirement in object oriented programming is the use  of a derived class as a super class, java supports this concept and uses it extensively in building its class library

Import java.io.*;

Class A

{ int a =2;}

Class B extends A

{int b =3;

}

Class C extends B

{ int c =4;

void show()

{ System.out.println(a +b +c);

}

}

Public class multilevel

{

   C ob = new C();

Ob.show();

} }

 Hierarchical inheritance

        In hierarchical inheritance, one class servers as a super class (base class) for more than one sub class, the class A serves as a base class for the derived class B,C,D more than one sub class is inherited from a single base class more than one derived class is created from a single base class.

        Hierarchical inheritance in java is one of the types of inheritance in Java. Inheritance is one of the implementation of an object oriented programming system. An inheritance is a mechanism in which one class inherits or acquires all the attributes and behavior of the other class. The class from which inherits the attributes and behaviors are called parent or super or base class and the class which inherits the attributes and behaviors are called child or derived class. The use of inheritance in java is for the reusability of code.

Class employee

{ float salary =40000;

}

Class permanentemp extends employee

{ double hike = 0.5;

}

Class temporaryemp extends employee

{ double hike =0.3;

}
public class herinheritance

{

Public static void main(String args[])

{

Permanentemp p =new permanentemp;

Temporaryemp t = new temporaryemp;

System.out.println(“permanent employee salary is “+p.salary);

System.out.println(“hike for permanent employee salary is “+p.hike);

System.out.println(“temporary employee salary is “+t.salary);

System.out.println(“hile for temporary employee salary is “+t.hike);

}

}

Thread

         A thread is similar to a program that has a single flow of control. It has a beginning, a body and an end, and executes command sequentially.

Creating Thread

        Creating thread in java is simple. Threads are implemented in the form of objects that contain a method called run(). The run() method is the heart and soul of any thread. It makes up the entire body of a thread and is the only method in which the thread’s behavior can be implemented.

        We can make our class run-able as a thread by extending the class java.lang.Thread. This gives us access to all the thread methods directly.

1.   Declare the class as extending the thread class.

2.   Implement the run method that is responsible for executing the sequence of code that the thread will execute.

3.   Create a thread object and call the start() method to initiate the thread execution.

 

Stopping a Thread

    Whenever we want to stop a thread from running further, we may do so by calling the stop() method, like

aThread.Stop()

    This statement causes the thread to move to the dead state automatically when it  reaches the end of its method.

Blocking a Thread

    A thread can also be temporarily suspended or blocked from entering into the run-able and subsequently running state by using either of the following thread methods.

Sleep()        blocked for specified time

Suspend()  blocked until further orders

Wait()         blocked until certain condition occurs

Life cycle of a Thread

    During the life time of a thread, there are many states it can occur. They include

1. New born state

2. Runnable state

3. Running state

4. Blocked state

5. Dead state



Declaring the class

        The thread class can be extended as follows

Class mythread extends Thread

{

……………

}

Implementing the run() method

        The run() method has been inherited by the class mythread. The basic implementation of run() will look like this

Public void run()

{

……………

}

        When we start the new thread java calls the thread run() method , so it is the run() where all the action takes place

 

Starting a new thread

        To actually create and run an instance of our thread class we must write the following

mythread athread  = new mythread;

mythread.start();

        The first line instantiates a new object of the class mythread. Note that this statement just creates the object. The thread that will run this object is not yet running. The thread is in a new born state.

        The second line calls the start () method causing the thread to move into the run-able state.  Then, the java runtime will schedule the thread to run by invoking the run() method. Now, the thread is said to be in the running state.

New born state

        When we create thread object, the thread is born and is said to be in new born state. The thread is not yet scheduled for running. At this state, we can do only one of the following things with it.

-        Schedule it for running using start() method

-        Kill it using stop() method

 

Run-able state

        The run-able state means that the thread is ready for execution and is waiting for the availability of the processor.

Running state

`       Running means that the processor has given its time to the thread for its execution.

Blocked state

        A thread is said to be blocked when it is prevented from entering into the run-able state and subsequently the running state. This happens when the thread is suspended, sleeping, or waiting in order to satisfy certain requirements. A blocked thread is considered “not run-able” but not dead and therefore fully qualified to run again.

Dead state

        Every thread has a life cycle. A   running thread end its life when it has completed executing its run() method. It is a natural death. However, we can kill it by sending the stop message to it as any state thus causing a premature death to it. A thread can be killed as soon as it is born, or while it is running, or even when it is in “not run-able” (blocked condition).

 

Import java.lang.*;

class multi extends Thread

{

Public void run()

{ System.out.println(“thread is running”);

}

Public static void main (String args[])

{

   multi t1=new multi();

t1.start();

}

}

Thread exceptions

        Whenever we call a thread method that is likely to throw an exception, we have to supply an appropriate exception handler to catch it, The catch statement may take one of the following forms

Catch(ThreadDeath e)

{

// killed thread

}

Catch (InterruptedException e)

{

// cannot handle it in the current state

}

Catch(IllegalArgumentException e)

{

// Illegal method argument

}

Catch(Exception e)

{

Any other

Managing errors and Exceptions

        Errors may broadly be classified into two categories

-        Compile –time errors

-        Run time errors

All syntax errors will be detected and displayed by the java compiler and therefore those errors are known as compile time errors.

    Most of the compile-time errors are due to typing mistakes. The most common problems are

-        Missing semicolon

-        Misspelling of identifiers and keywords

-        Missing double quotes in strings

-        Use of undeclared variables

-        In compatible types in assignments / initialization

-        Bad references to objects

-        Use of = in  place of == operators

Run time errors

        Sometimes, a program may compile successfully creating the .class file but may not run properly. Such programs may produce wrong results due to wrong logic or may terminate due to errors, such as stack overflow.

Most common run time errors are

-        Dividing an integer by zero

-        Accessing an element that is out of the bounds of an error

-        Trying to illegally change the state of a thread

-        Attempting to use a negative size for an array

-        Converting invalid string to number

Java uses a keyword try to preface a block of code that is likely to cause an error condition and “throw” an exception.

 

Try

{  

   Statement   // generate an exception

}

Catch (Exception type e)

{

   Processes the exception

}

       The try block can have one or more statements that could generate an exception. If anyone statement generates an exception, the remaining statements in the block are skipped and execution jumps to the catch block that is placed next to the try block

 Common Java Exception

Exception type                   cause of exception

ArithmeticException  math errors such as division by zero

ArrayIndexOutofBoundsException   bad array indexes

ArrayStoreException       when a program tries to store

                                          the wrong type of data in an array

FileNotFoundException  an attempt to access a non

                                            Existent file.

IOException                       general I/O failures such as

                             Inability to read from file

NullpointerException     referencing null object

NumberForamatException   conversion between strings

                                                and number fails

OutofmemoryException    When there’s not enough

                                          Memory to allocate a new object

SecurityException       When an applet tries to perform an

                                    Action not allowed by the browser’s

                                     Security setting.

StackoverflowException     when the system runs out of

                                                Stack space

Finally block

        The finally block follows a try block or a catch block. A finally block of code always executes, irrespective of occurrence of an exception

        Using a finally block  allows you to run any clean up type statements that you want to execute

public class error5

{ public static void main(String args[])

{ int a[] = new int[2];

try

{

  System.out.println(“access elements three “+a[3]);

}

Catch(ArrayIndexOutofBoundsException e)

{ System.out.println(“Exception thrown”+e);

}

Finally

{

 a[0] = 6;

System.out.println(“first element  value “+a[0]);

System.out.println(“The finally statement is executed”);

}

}

}

 


Exceptions can be categorized into two types

Unchecked Exceptions: They are not checked at compile time but at run time. For example Arithmetic Exception, NullpointerException etc.

Checked Exceptions : They are checked at compile time for example IOException, Interrupted Exceptions etc.

Throws keyword

 We use the throw’s keyword in the method declaration to declare the type of exceptions that might occur within it.

Import java.io.*;

Class file1

{

Public static void findfile() throws IOException

{

 File newfile = new file (“test.txt”);

FileInputStream stream=new FileInputStream(newfile);

Public static void main(String args[])

{

{

   Try

{   findfile();

}

Catch(IOException e)

{

   System.out.println(e);

}

}

}

    When we run this program , if the file test.txt does not exist, FileInputStream throws a file not found  Exception which extends the IOException class.

        The findfile() method specifies that an IOException can be thrown. The main() method calls this method and handles the exception if it is thrown

 

Java throw keyword

        The java throw keyword is used to explicitly throw a single exception

        When an exception is thrown, the flow of program execution transfers from the try block to the catch block we use the throw keyword within the method.