Monday, April 17, 2023

Experiment No: 4 Write a Java program that creates a user interface to perform integer divisions. The user enters two numbers in the text fields, Num1 and Num2. The division of Num1 and Num 2 is displayed in the Result field when the Divide button is clicked. If Num1 or Num2 were not an integer, the program would throw a Number Format Exception. If Num2 were Zero, the program would throw an Arithmetic Exception. Display the exception in a message dialog box.

 Program:

import java.awt.*;

import java.awt.event.*;


import javax.swing.*;

/*

<applet code="DivApplet" width=350 height=300>

</applet>

*/

public class DivApplet extends JApplet implements ActionListener{

JTextField number1,number2,result;

JButton divide;

public void init(){

try

{

SwingUtilities.invokeAndWait(

new Runnable() {

public void run() {

makeGUI();

}

});

}

catch (Exception exc)

{

System.out.println("Can't create because of " + exc);

}

}

private void makeGUI()

{

setLayout(new FlowLayout());

Label number1p = new Label("Number1: ",Label.RIGHT);

Label number2p = new Label("Number2: ",Label.RIGHT);

number1= new JTextField(20);

number2 = new JTextField(20);

result = new JTextField(20);

divide = new JButton("Divide");

add(number1p);

add(number1);

add(number2p);


add(number2);

add(result);

add(divide);

divide.addActionListener(this);

}

public void actionPerformed(ActionEvent e){

String snumber1,snumber2;

snumber1 = number1.getText();

snumber2 = number2.getText();

try{

int number1 = Integer.parseInt(snumber1);

int number2 = Integer.parseInt(snumber2);

if(number2==0)

JOptionPane.showMessageDialog(null, "Division by zero not defined.");

else{

double r = (double)number1/number2;

result.setText(((Double)r).toString());

}

}

catch(NumberFormatException ne)

{

JOptionPane.showMessageDialog(null,"Enter a number");

}

}

}

Execution:

C:\Users\vits\Desktop\java>javac DivApplet.java

C:\Users\vits\Desktop\java>appletviewer DivApplet.java

Output:



Monday, April 10, 2023

Experiment No: 5 Aim: Write a Java program that implements a multi-thread application that has three threads. First thread generates random integer every 1 second and if the value is even, second thread computes the square of the number and prints. If the value is odd, the third thread will print the value of cube of the number.

 

Program:

 

import java.util.Random;

class Square extends Thread

{

 int x;

 Square(int n)

 {

 x = n;

 }

 public void run()

 {

 int sqr = x * x;

 System.out.println("Square of " + x + " = " + sqr );

 }

}

class Cube extends Thread

{

 int x;

 Cube(int n)

 {x = n;

 }

 public void run()

 {

 int cub = x * x * x;

 System.out.println("Cube of " + x + " = " + cub );

 }

}

class Number extends Thread

{

 public void run()

 {

 Random random = new Random();

 for(int i =0; i<5; i++)

 {

 int randomInteger = random.nextInt(100);

 

 System.out.println("Random Integer generated : " + randomInteger);

 Square s = new Square(randomInteger);

 s.start();

 Cube c = new Cube(randomInteger);

 c.start();

 try

{

 Thread.sleep(1000);

}

catch (InterruptedException ex)

{

 System.out.println(ex);

}

 }

 }

}

public class Thr

{

 public static void main(String args[])

 {

 Number n = new Number();

 n.start();

 }

}

Output:

 

C:\Users\vits\Desktop\java>javac Thr.java

 

C:\Users\vits\Desktop\java>java Thr

Random Integer generated : 61

Square of 61 = 3721

Cube of 61 = 226981

Random Integer generated : 19

Square of 19 = 361

Cube of 19 = 6859

Random Integer generated : 13

Square of 13 = 169

Cube of 13 = 2197

Random Integer generated : 5

Square of 5 = 25

Cube of 5 = 125

Random Integer generated : 94

Square of 94 = 8836

Cube of 94 = 830584

Monday, March 27, 2023

Write a Java program for the following: i) Create a doubly linked list of elements. ii) Display the contents of the list after deletion.

 import java.lang.*;


public class DoublyLinkedList

 {  

        class Node

        {  

        int data;  

        Node previous;  

        Node next;  

          public Node(int data) 

        {  

                this.data = data;  

        }  

    }  

     Node head, tail = null;  

      public void addNode(int data) 

   {  

        Node newNode = new Node(data);  

          if(head == null) 

            {  

                 head = tail = newNode;  

                   head.previous = null;  

                tail.next = null;  

        }  

        else

        {  

              tail.next = newNode;  

              newNode.previous = tail;  

              tail = newNode;  

              tail.next = null;  

        }  

    }  

  

    public void display() 

    {  

        Node current = head;  

        if(head == null) 

        {  

            System.out.println("List is empty");  

            return;  

        }  

        System.out.println("Nodes of doubly linked list: ");  

        while(current != null) 

        {  

             System.out.print(current.data + " ");  

            current = current.next;  

        }  

    }  

  

    public static void main(String[] args) 

    {  

  

        DoublyLinkedList dList = new DoublyLinkedList();  

        dList.addNode(1);  

        dList.addNode(2);  

        dList.addNode(3);  

        dList.addNode(4);  

        dList.addNode(5);  

  

        dList.display();  

    }  

}  


Output:

Nodes of doubly linked list: 

1 2 3 4 5 



Saturday, December 17, 2022

Data Mining R18

R18 Data Mining Lecture Notes for University Examinations for quick reference.

Unit-1 : Notes Click Here

Unit-1 : Data Preprocessing Click Here

Data Mining Unit-1 Important Question and AnswerClick Here

Introduction to Data Mining ppt Click Here

Data Discretization and Concept Hierarchy Click Here

Unit-2: Notes Click Here

Association Rule Mining ppt Click Here

Apriory Algorithm Click Here

Unit-3 : Notes Click Here

Lazy Learner and Rule Based Learning Click Here

Unit-4 : Notes Click Here

Hierarchal Clustering ppt Click Here

Partitioning Clustering ppt Click Here

Grid Based Clustering ppt Click Here

Density Based Clustering ppt Click Here

Unit-5

ppt on Data Streaming, Mining Time Series Data, Mining Sequential Click Here

ppt on Text Mining Click Here

ppt on Mining Spatial Data, Multimedia Data Click Here




Wednesday, June 1, 2022

VR23 Object Oriented Programming Though Java Unit- 1& 2 Notes

Object Oriented Programming Though Java Syllabus(VR23): Click Here

Unit-1 : 1st Part Notes Click Here

Unit-1 : 2nd Part Notes Click Here

Unit- 2 : Packages & Interfaces Notes Available

Unit-2 : Java.io Package  See Here


Monday, May 23, 2022

Write a Java program to create an abstract class named Shape that contains two integers and an  empty method named print Area (). Provide three classes named Rectangle, Triangle, and Circle  such that each one of the classes extends the class Shape. Each one of the classes contains only  the method print Area () that prints the area of the given shape.

import java.util.*;

abstract class Shape {
	int length, breadth, radius;

	Scanner input = new Scanner(System.in);

	abstract void printArea();

}

class Rectangle extends Shape {
	void printArea() 
{
		
System.out.println("*** Finding the Area of Rectangle ***");
System.out.print("Enter length and breadth: ");
length = input.nextInt();
breadth = input.nextInt();
System.out.println("The area of Rectangle is: " + length * breadth);
	}
}

class Triangle extends Shape 
{
	void printArea()
 {
       System.out.println("\n*** Finding the Area of Triangle ***");
    System.out.print("Enter Base And Height: ");
    length = input.nextInt();
    breadth = input.nextInt();
 
System.out.println("The area of Rectangle is: " + (length * breadth) / 2);
  }
}

class Cricle extends Shape
 {
    void printArea() 
    {
	System.out.println("\n*** Finding the Area of Cricle ***");
	System.out.print("Enter Radius: ");
	radius = input.nextInt();

System.out.println("The area of Rectangle is: " + 3.14f * radius * radius);
    }
}

public class AbstractClassExample
 {
public static void main(String[] args)
 {
   Rectangle rec = new Rectangle();
   rec.printArea();

   Triangle tri = new Triangle();
   tri.printArea();
 		
   Cricle cri = new Cricle();
    cri.printArea();
}
}

Thursday, April 21, 2022

Java Programming

 Students blog for Happy Learning

Java Programming Syllabus(R18-CSE-JNTUH): Click Here

Object Oriented Programming Through Java Syllabus(R18-EIE-JNTUH): Click Here

Unit-1 : 1st Part Notes Click Here

Unit-1 : 2nd Part Notes Click Here

Unit Wise Important Questions: Download

Objective Questions :Download 

Tuesday, February 8, 2022

Chomsky Hierarchy

Chomsky Hierarchy

Chomsky Hierarchy represents the class of languages that are accepted by the different machine. The category of language in Chomsky's Hierarchy is as given below:

  1. Type 0 known as Unrestricted Grammar.
  2. Type 1 known as Context Sensitive Grammar.
  3. Type 2 known as Context Free Grammar.
  4. Type 3 Regular Grammar.



This is a hierarchy. Therefore every language of type 3 is also of type 2, 1 and 0. Similarly, every language of type 2 is also of type 1 and type 0, etc.

Type 0 Grammar:

Type 0 grammar is known as Unrestricted grammar. There is no restriction on the grammar rules of these types of languages. These languages can be efficiently modeled by Turing machines.

For example:

1.     bAa → aa  

2.     S → s  

Type 1 Grammar:

Type 1 grammar is known as Context Sensitive Grammar. The context sensitive grammar is used to represent context sensitive language. The context sensitive grammar follows the following rules:

  • The context sensitive grammar may have more than one symbol on the left hand side of their production rules.
  • The number of symbols on the left-hand side must not exceed the number of symbols on the right-hand side.
  • The rule of the form A → ε is not allowed unless A is a start symbol. It does not occur on the right-hand side of any rule.
  • The Type 1 grammar should be Type 0. In type 1, Production is in the form of V → T

Where the count of symbol in V is less than or equal to T.

For example:

1.     S → AT  

2.     T → xy  

3.     A → a  

Type 2 Grammar:

Type 2 Grammar is known as Context Free Grammar. Context free languages are the languages which can be represented by the context free grammar (CFG). Type 2 should be type 1. The production rule is of the form

1.     A → α  

Where A is any single non-terminal and is any combination of terminals and non-terminals.

For example:

1.     A → aBb  

2.     A → b  

3.     B → a  

Type 3 Grammar:

Type 3 Grammar is known as Regular Grammar. Regular languages are those languages which can be described using regular expressions. These languages can be modeled by NFA or DFA.

Type 3 is most restricted form of grammar. The Type 3 grammar should be Type 2 and Type 1. Type 3 should be in the form of

1.     V → T*V / T*  

For example:

1.     A → xy  

 

 


Pumping Lemma for L = {a | k is a prime number}

  L = {a | k is a prime number}

Let us assume L is regular.  

-> Clearly L is infinite (there are infinitely many prime numbers). From the pumping lemma, there exists a number n such that any string w of length greater than n has a “repeatable” substring generating more strings in the language L.

Let us consider the first prime number p >= n.

For example, 

if n was 50 we could use p = 53. 

From the pumping lemma the string of length p has a “repeatable” substring. We will assume that this substring is of length k >= 1.

Hence:

It should be relatively clear that p + k, p + 2k, etc., cannot all be prime but let us add k p times, then we must have:

so this would imply that (k + 1)p is prime, which it is not since it is divisible by both p and k + 1. Hence L is not regular. 




Pumping Lemma for Regular Languges


Pumping lemma used to show that language is not regular. 

What is pumping?

for regular expression

r = (a u b) (abb)* (bba u bbb), the string w= babbbbb pumps because we may decompose w into three sub strings.

w= b.  abb.  bbb

such that  b(abb)i bbb is represented by r, for every i>= 0.

in this DFA.,


the string aaabab= aa. aba.b pumps because of the cycle that the aba follows.


Suppose L is a regular Language., the there exists an integer k such that for all strings z belongs to L. , satisfying |z|>=k., we can write z= uvw where

|v| >= 1

|uv| <=k

u vw  belongs to L, for all i>=0.


Tuesday, January 18, 2022

FLAT(Formal Languages and Automata Theory)

FLAT Syllabus( R22-CSE- JNTUH ): Click Here

Unit-1 : Hand Written Notes Click Here

old Notes Click Here

Unit-2 : Hand Written Notes Click Here

old Notes Click Here

Unit-3 : Hand Written Notes Click Here

old Notes Click Here

Unit-4 : Hand Written Notes Click Here

old Notes Click Here

Unit-5 : Notes Click Here

Unit Wise Important Questions: Download

JNTUH FLAT Previous Questions: Download

A simple Java program to find the inverse of a given matrix

  import java.util.Scanner; public class MatrixInverse { public static void main (String[] args) { Scanner scanner =...