Computer Notes, Programming codes, Hardware and Networking Tip, Entertainment, Biography, Internet Tip, Tech News, Latest Technology, YouTube,

Latest Post
About RAM Advantages of multiprocessing system Associative memory Binary Number System CA CA Notes Change drive icon change pendrive icon Computer Abbreviation Computer Architecture Computer fundamental MCQ Computer Generation Computer generation computer notes Computer MCQ Computer Network MCQ Computer Operator MCQ Critical Section Critical section in OS Database connectivity in java Deadlock avoidance Deadlock detection algorithm Deadlock Detection and Recovery Deadlock detection method Deadlock Handling Deadlock in OS Deadlock Prevention Deadlock Recovery define object and class Define system cell Descrete Structure Device Driver Device driver in computer device driver in os DFA DFA contains with DFA ends with dfa examples dijkstra's algorithm Discrete Structure Discrete Structure graph theory Download JDBC Driver Download MySql Download PUBG DS DS Notes FCFS Job Scheduling Algorithm Finding shortest path Finite Sate Automata Flynn's Classifications fragmentation in computer fragmentation in harddisk fragmentation in os fragmented memory Full form related to computer Generations of operations Generations of OS Graph theory ICT 1st semester notes Instruction Address Modes Java java array declaration java class and object example Java Database connectivity example java event handling example program Java JDBC Java JMenuBar Java JSP program example java notes java program methods example Java program to create class and object java program to create methods java program to print even number between any two numbers Java programming java programming notes Java programs Java question answer java swing example java swing program to calculate simple interest Java Tutorials JSP program learn qbasic Lekh MCQ MCQ Computer MCQ Operating System memory fragmentation MICT 1st semester notes mict 1st semester operating system notes MICT first semester notes Multiprocessing mutex in os Necessary conditions for deadlock Number System Operating System Operating system notes OS OS Notes OS Numeric pattern printing program in qbasic patterns in qbasic Pipeline Hazards Pipelining Pipelining concept prime or composite in qbasic print patterns qbasic print series in qbasic Printing Series in qbasic PUBG PUBG Mobile PUBG PC PUBG Story qbasic qbasic code qbasic for class 10 qbasic for class 8 qbasic for class 9 qbasic for school QBASIC Pattern printing qbasic pattern printing program qbasic pattern printing programs qbasic pattern types qbasic patterns qbasic programming tutorials qbasic programs qbasic sequence printing programs qbasic tutorials Race Condition in Operating system reverse order in qbasic RISC and CISC RISC Pipeline Scheduling algorithm segmentation in operating system segmentation in os semaphore and mutex Semaphore concept in os Semaphore in os semaphore in os notes semaphore meaning sequential programs in qbasic series in qbasic series printing programs in qbasic shell in operating system shell in os shortest path shortest path algorithm simple interest program in java swing System Bus System Cell Teach Blog Tech Blog Tech School technical school The Shell in Operating system types of fragmentation Types of Multiprocessor types of operating system Types of pipeline hazards View Connected Wifi password Virtual Memory Virtual memory in OS Von Neumann's architecture What is associative memory? what is class? What is computer system? What is Fragmentation? What is jsp? what is object? What is process? What is segmentation What is System Cell What is Thread? what is virtual memory in computer What is virtual memory? पब्जी गेम

What is computer system? Discuss its components. Explain John Von Neumann's architecture of computer system. 


A computer system is a set of integrated devices that input, output, process, and store data and information. Computer systems are currently built around at least one digital processing device. There are five main hardware components in a computer system: Input, Processing, Storage, Output and Communication devices.

Input
Input means data and instruction given to the computer which is most essential for producing meaningful and useful output. The unit which is used to give input to the computer system is called input unit and it is formed by various input devices attached to the computer such as keyboard, mouse, joystick, trackball touch screen, MICR (Magnetic Ink Character REader) etc into computer understandable form. The input unit establishes the communication link between the user and the computer system. 

Processing
Processing unit is also called 'Central Processing Unit' and it is the control center for a computer. It guides, directs and governs all operations and components inside the computer. It is considered as brain of computer. It is linked with various peripheral devices including I/O devices, secondary storage and memory unit. it performs arithmetic operations, logical comparison, transfer information between all parts of computer and executes instructions. CPU consists of ALU, CU and Registers. 

Output
Output is the processed data which is very useful and meaningful to us and we can get it from the computer in the form that we want. The unit which is used to provide output is called output unit. It is always in the form of human readable or understandable. There are various types of output devices such as Monitor, Printer, Plotter, Speakers etc. 

Memory/Storage Unit
A storage device is any computing hardware that is used for storing, porting and extracting data files and objects. It can hold and store information both temporarily and permanently, and can be internal or external to a computer, server or any similar computing device.  Data and instruction are stored in memory in the binary form. 



Von Neumann Architecture
Von Neumann architecture is based on the stored-program computer concept, where instruction data and program data are stored in the same memory.  This design is still used in most computers produced today. This architecture was first published by John von Neumann in 1945.

Von Neumann Architecture
His computer architecture design consists of a Control Unit, Arithmetic and Logic Unit (ALU), Memory Unit, Registers and Inputs/Outputs.



CPU (Central Processing Unit)
The CPU is an electronic circuit which is responsible for executing the instructions of a computer program. Sometimes it is also referred to as the microprocessor or processor. It contains ALU, CU and Registers. 

Registers 
Registers are high speed storage areas in the CPU.  All data must be stored in a register before it can be processed. Some registers are 
  • MAR (Memory Address Register) 
  • MDR (Memory Data Register) 
  • AC (Accumulator) 
  • PC (Program Counter) 
  • CIR (Current Instruction Register) 
ALU (Arithmetic and Logic Unit) 
The ALU allows arithmetic (add, subtract etc) and logic (AND, OR, NOT etc) operations to be carried out.

CU(Control Unit) 
The control unit controls the operation of the computer’s ALU, memory and input/output devices, telling them how to respond to the program instructions it has just read and interpreted from the memory unit.

MU (Memory Unit)
The memory unit consists of RAM, sometimes referred to as primary or main memory.  Unlike a hard drive (secondary memory), this memory is fast and also directly accessible by the CPU.

Buses 
Buses are the means by which data is transmitted from one part of a computer to another, connecting all major internal components to the CPU and memory. There are three types of buses 
  • Address Bus (Carries the addresses of data) 
  • Data Bus (Carries data between different units) 
  • Control Bus (Carries control signals from CPU to control the activities) 

  • A JInternalFrame is a container that looks much like a JFrame. The key difference is that internal frames can only exist within some other Java container.
  • Thus, we must add an internal frame to a container (usually a JDesktopPane). The following list summarizes the rules for using internal frames.
  • –Set size of internal frames
    –Set location
    –Add internal frames into DesktopPane
    –Call setVisible method
  • We can create internal frames by using any one of following constructors.
  • –JInternalFrame()
    –JInternalFrame(String title, boolean resizable, boolean closeable, boolean maximizable,  boolean iconifiable)
    Example: 
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class IFDemo extends JFrame
{
	JDesktopPane dp;
	JInternalFrame iframe;
	JTextField tb;
	JLabel lb;
	IFDemo()
	{
		setSize(400,300);		
		setDefaultLookAndFeelDecorated(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
		dp=new JDesktopPane();
		iframe=new JInternalFrame("Internal Frame",true,true,true,true);
		iframe.setSize(200,200);
		iframe.setLocation(50,50);
		dp.add(iframe);
		add(dp);
		lb=new JLabel("Email");
		tb=new JTextField(10);
		iframe.setLayout(new FlowLayout(FlowLayout.CENTER));
		iframe.add(lb);
		iframe.add(tb);
		iframe.setVisible(true);		
	}	
	public static void main(String args[]) 
	{
		IFDemo frame=new IFDemo();		
	}
}


To create menus, we need to follow the following steps:
- First, A JMenubar is created
- Then, we attach all of the menus to this JMenubar.
- Then we add JMenuItem to the JMenu.
- The JMenubar is then added to the frame by using setJMenuBar() method.


JMenuBar
We can create menu bar by using following constructor:
       JMenuBar()

JMenu
It can be created by using following constructors:
      JMenu()
      JMenu(String)

 
import javax.swing.*; 

class Menu extends JFrame{ 
 JMenuBar mb; 
 JMenu file, edit, data, name; 
 JMenuItem open, save, sas, cut, copy, paste; 
 JCheckBoxMenuItem  raju, indra;
 
 Menu(){ 
  setTitle("Menu Demo"); 
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

  mb=new JMenuBar(); 
  file=new JMenu("File"); 
  edit=new JMenu("Edit"); 
  data=new JMenu("Data"); 
  name=new JMenu("Name"); 

  open=new JMenuItem("Open"); 
  save=new JMenuItem("Save"); 
  sas=new JMenuItem("Save As"); 
  cut=new JMenuItem("Cut"); 
  copy=new JMenuItem("Copy"); 
  paste=new JMenuItem("Paste");

  raju=new JCheckBoxMenuItem("Raju"); 
  indra=new JCheckBoxMenuItem("Indra"); 

  file.add(open);  
  file.add(save); 
  file.add(sas); 

  edit.add(cut); 
  edit.add(copy); 
  edit.add(paste); 

  data.add(name); 

  name.add(raju); 
  name.add(indra); 

  mb.add(file); 
  mb.add(edit); 
  mb.add(data); 

  setJMenuBar(mb); 
  setSize(500, 500); 
  setVisible(true); 
 }

 public static void main(String args[]){
  new Menu(); 
 }
}


1. Define constructor? Explain constructor overloading with suitable example. 


Solution: 
Constructor in java is special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object therefore it is known as constructor. 

More than one constructor with different signature in a class is called constructor overloading. 


 
public class Student{
 int roll, marks; 
 String name;

 Student(int r, String n, int m){
  roll = r; 
  name = n; 
  marks = m; 
 }

 Student(int r, int m, String n){
  roll = r; 
  name = n; 
  marks = m;  
 }

 void displaInfo(){
  System.out.println(roll+"\t"+name+"\t"+marks);
 }
 public static void main(String args[]){
  Student s1 = new Student(1, "Ram", 56); 
  Student s2 = new Student(2, 89, "Shyam"); 

  System.out.println("Roll \t Name \t Marks");
  s1.displaInfo();
  s2.displaInfo(); 
 }
}


2. How class is different then object ? Write a program to create Employee class with data  members employee id, employee name, and salary. Also put necessary member function for reading and display objects. Create two objects of employee class and then read and display their details. 



Solution: 
Classes and objects are the fundamental components of OOP's. A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object.

Object is an instance of a class. It determines the behavior of the class.  Memory is allocated for data members of class when object is created.

 
import java.util.Scanner; 
class Employee{
 int id, salary;
 String name; 

 public void getData(){
  Scanner in = new Scanner(System.in); 
  System.out.println("\nEnter the Following Info of Employee"); 
  System.out.print("Employee ID : "); 
  id = in.nextInt(); 
  System.out.print("Employee Name : "); 
  name = in.next(); 
  System.out.print("Employee Salary : "); 
  salary = in.nextInt(); 
 }

 public void displayData(){
  System.out.println("\n***Employee Details***"); 
  System.out.println("ID = "+id); 
  System.out.println("Name = "+name); 
  System.out.println("Salary = "+salary); 
 }
 
 public static void main(String args[]){
  Employee em1 = new Employee(); 
  Employee em2 = new Employee(); 

  em1.getData();
  em1.displayData(); 

  em2.getData();
  em2.displayData(); 
 }
}



3. Write a program to create a form first number second number, and result, and two buttons and add subtract. Handle the events such that clicking on and button computes addition and clicking on subtract performs subtraction.

Solution: 

 
import java.awt.*;
import javax.swing.*; 
import java.awt.event.*; 

class Calc extends JFrame implements ActionListener{
 
 JLabel l1, l2, l3; 
 JTextField t1, t2, t3; 
 JButton b1, b2; 

 Calc(){
  
  super("Handling Action Event"); 
  l1 = new JLabel("Enter First Number"); 
  l2 = new JLabel("Enter Second Number"); 
  l3 = new JLabel("Result"); 

  t1 = new JTextField(10); 
  t2 = new JTextField(10); 
  t3 = new JTextField(10); 

  b1 = new JButton("Add"); 
  b2 = new JButton("Subtract"); 

  setLayout(new FlowLayout(FlowLayout.LEFT,90,10));
  add(l1); 
  add(t1); 
  add(l2); 
  add(t2); 
  add(l3); 
  add(t3); 
  add(b1); 
  add(b2); 

  b1.addActionListener(this); 
  b2.addActionListener(this); 

  setSize(300, 300); 
  setVisible(true);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
 }

 public void actionPerformed(ActionEvent ae){
  int x, y, z; 
  x=Integer.parseInt(t1.getText()); 
  y=Integer.parseInt(t2.getText()); 
  if(ae.getSource() == b1){
   z = x + y; 
  }else{
   z = x - y; 
  }

  t3.setText(String.valueOf(z)); 
 }

 public static void main(String args[]){
  new Calc(); 
 }
}




4. What are different types of exceptions? Explain use of try.....catch and finaly with example.

Solution: 
Exceptions are the unwanted errors or bugs or events that restrict the normal execution of a program. In such cases we get a system generated error message. An error message is displayed on the screen. There are mainly two types of exceptions: They are :
  • Built-In Exception
  • User-Defined Exception
Built-in exceptions are the exceptions which are available in Java libraries. These exceptions are suitable to explain certain error situations. Some Built-in exceptions are :
  • Arithmetic Exception
  • ArrayIndexOutOfBoundsException
  • ClassNotFoundException
  • FileNotFoundException
  • IOException etc.
Sometimes, the built-in exceptions in Java are not able to describe a certain situation. In such cases, user can also create exceptions which are called ‘user-defined Exceptions’.

Use of Try ... Catch and Finally
  • A try block is used to enclose the code that might throw an exception. It must be used within the method. Java try block must be followed by either catch or finally block.
  • Java catch block is used to handle the Exception. It must be used after the try block only.
  • Java finally block is a block that is used to execute important code such as closing connection, stream etc. Java finally block is always executed whether exception is handled or not. Java finally block follows try or catch block.
Example

 

public class TestFinally{
    public static void main(String args[]){
        try{
            int x = 20/0; 
            System.out.println("Quoitent = "+x); 
        }
        catch(ArithmeticException e){
            System.out.println("e.getMessage"); 
        }
        finally{
            System.out.println("Finally block is always executed"); 
        }
        System.out.println("Rest of the Codes .... "); 
    }
}



5. Write down the the steps for writing client and server program by using UDP?

Solution
UDP is a Datagram, It is a connection less ,independent , self contained protocol. Bulk Data are send and receive as packets from using UDP. Steps to write client and server program by using UDP are as follows:
Steps for Writing Client Program 
Step1: Get Datagram Socket
           DatagramSocket ds=new DatagramSocket(port)
Step2: Send Request
           DatagramPacket p=new DatagramPacket(byte[],length, inetaddress,port)
           ds.send(p)
Step3: Get Response
           p=new DatagramPacket(buf,buf.length)
           ds.receive(p)
Step4: Display Response
           String s=new String(p.getData());
           System.out.println(“Server:”+s);
Step 5: Close the Socket
           ds.close();

Steps for Writing Server Program 
Step1: Get Datagram Socket
           DatagramSocket ds=new DatagramSocket(port)
Step2: Receive Request
           byte[] buf=new byte[256]
           DatagramPacket p=new DatagramPacket(buf,buf.length)
           ds.receive(p)
Step3: Send Response
           String s=new String(“Hello Client”);
           buf=s.getBytes()
           ds.send(p)
Step 4: Close the Socket
           ds.close();

5. Write a Java Swing Program to design the following menu bar. 


Solution:

import javax.swing.*;  

class MenuDemo extends JFrame{
 
 JMenuBar mb; 
 JMenu file, edit, format; 
 JMenuItem open, save, save_as, exit, undo, redo; 

 MenuDemo(){
  setTitle("Menu Bar"); 
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

  mb=new JMenuBar(); 

  file=new JMenu("File"); 
  edit=new JMenu("Edit"); 
  format=new JMenu("Format"); 

  open=new JMenuItem("Open"); 
  save=new JMenuItem("Save"); 
  save_as=new JMenuItem("Save As"); 
  exit=new JMenuItem("Exit"); 
  undo=new JMenuItem("Undo"); 
  redo=new JMenuItem("Redo"); 

  file.add(open); 
  file.add(save); 
  file.add(save_as); 
  file.add(exit); 

  edit.add(undo); 
  edit.add(redo); 

  mb.add(file); 
  mb.add(edit); 
  mb.add(format); 

  setJMenuBar(mb); 
 
  setSize(300, 200); 
  setVisible(true); 
 }

 public static void main(String args[]){
  new MenuDemo(); 
 }
}


1. Construct finite state automata (DFA) that contains with abb

Solution :
Σ: inputs = {a, b}
          q0 = initial state
          q1 = string with a
          q2 = string with ab
          q3 = string with abb

Q: set of all states (q0, q1, q2, q3)
F: Final State 

 Transition Matrix
  f
    a b
ε q0 q1 q0
a q1 q1 q2
ab q2 q1 q3
abb q3 q3 q3
Transition Graph


2. Construct finite state automata (DFA) that contains with aab

Solution :
Σ: inputs = {a, b}
          q0 = initial state
          q1 = string with a
          q2 = string with aa
          q3 = string with aab

Q: set of all states (q0, q1, q2, q3)
F: Final State 

  Transition Matrix
  f
    a b
ε q0 q1 q0
a q1 q2 q0
ab q2 q2 q3
abb q3 q3 q3
Transition Graph


3. Construct finite state automata (DFA) that contains with aba

Solution :
Σ: inputs = {a, b}
          q0 = initial state
          q1 = string with a
          q2 = string with ab
          q3 = string with aba

Q: set of all states (q0, q1, q2, q3)
F: Final State 

  Transition Matrix
  f
    a b
ε q0 q1 q0
a q1 q1 q2
ab q2 q3 q0
abb q3 q3 q3
Transition Graph


4. Construct finite state automata (DFA) that contains with aabb

Solution :
Σ: inputs = {a, b}
          q0 = initial state
          q1 = string with a
          q2 = string with aa
          q3 = string with aabb

Q: set of all states (q0, q1, q2, q3)
F: Final State 

  Transition Matrix
  f
    a b
ε q0 q1 q0
a q1 q2 q0
aa q2 q2 q3
aab q3 q1 q4
aabb q4 q4 q4
Transition Graph

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget