Computer Peripherals

List of Input Devices, Output Devices and Both Input Output devices related to computer.

Here I am going to share you about list of  basic Input Devices, Output devices and  Both inputoutput devices  related to computer.

💻 Input Devices

Input devices are hardware components that help users send data or instructions to the computer for processing.

  1. Common examples of Input Devices:
  2. Graphics Tablet
  3. Camera
  4. Video Capture Hardware
  5. Trackball
  6. Barcode Reader
  7. Digital Camera
  8. Gamepad
  9. Joystick
  10. Keyboard
  11. Microphone
  12. MIDI Keyboard
  13. Mouse (Pointing Device)
  14. Scanner
  15. Webcam
  16. Touchpad
  17. Pen Input
  18. Electronic Whiteboard
  19. OMR (Optical Mark Reader)
  20. OCR (Optical Character Reader)
  21. Punch Card Reader
  22. MICR (Magnetic Ink Character Reader)
  23. Magnetic Tape Drive

🖥️ Output Devices

Output devices are used to display, project, or reproduce processed information from the computer so users can view or hear it.

Common examples of Output Devices:

  1. Monitor (LED, LCD, CRT, etc.)
  2. Printers (Inkjet, Laser, Dot Matrix, etc.)
  3. Plotters
  4. Projector
  5. LCD Projection Panels
  6. Computer Output Microfilm (COM)
  7. Speakers
  8. Headphones
  9. Visual Display Unit (VDU)
  10. Film Recorder
  11. Microfiche

🔁 Both Input and Output Devices

Some devices perform both input and output functions — they can send data to the computer as well as receive information from it.

Examples include:

  1. Modems
  2. Network Cards
  3. Touch Screen
  4. Headsets (Speakers act as output devices and microphones act as input devices)
  5. Facsimile (FAX) (Scans documents for input and prints them for output)
  6. Audio / Sound Cards (Send and receive audio signals)
Java Basic Problems

Java: How to Take input of Float type variables and then add it??

In my last post I have shared about  How to add Integer numbers in Java.

Here I have shown how to add and work with float type variables in java.

In the given example I have taken two float type variable as input and then add it.

 float variable java

Code Example

import java.io.*;

class FloatDemo

{

public static void main(String args[])

{

float floatNumber=0.0f;

float floatNumber1=0.0f;

float sumOf=0.0f;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

try{

System.out.println(“\n”);

System.out.println(“************************************”);

System.out.println(“\n”);

System.out.println(“Enter 1st Floating point input:”);

floatNumber=Float.valueOf(br.readLine()).floatValue();

System.out.println(“\n”);

System.out.println(“Enter 2nd Floating point input:”);

floatNumber1=Float.valueOf(br.readLine()).floatValue();

System.out.println(“\n”);

sumOf=floatNumber+floatNumber1;

System.out.println(“After Addition of the 2 float  number =”+sumOf);

System.out.println(“\n”);

System.out.println(“************************************”);

}

catch(Exception e)

{

Exception newEx=new Exception(“Error at:”+new java.util.Date()+””,e);

newEx.printStackTrace();

}

}

}

Java Basic Problems

Java:Check Empty String and Avoid Null Pointer Exception

In my last post I have shared about the features of  Final Class,Variables and Methods.

Today I am going to share about how to check a string is Empty or not and also how to avoid Null Pointer Exception in java which occurs due to null value of  string.

Here I have used JOptionPane showInputDialog to take String Input from the user and then I checked the String entered by the user is empty or not.

If we check the string using the method given below we will be able to avoid Null Pointer Exception.

 

null pointer exception java

Here is the given example:

import javax.swing.*;

public class StringDemo

{

 StringDemo()

{

String reasonMsg;

reasonMsg=JOptionPane.showInputDialog(“Pleas Enter Your Name”,””);

System.out.println(“\n”);

System.out.println(“ReasonMsg:”+reasonMsg);

try

                                                {

                                                System.out.println(“\n”);

                             if(reasonMsg.trim().toString().length()==0)

                                      {

          JOptionPane.showMessageDialog(null,”You Entered Nothing”);

                                      }

                                                 if (reasonMsg.trim().toString().length()!=0)

                                                 {   

                                                                   JOptionPane.showMessageDialog(null,”You Name is:”+reasonMsg);

          System.out.println(“Your name is :”+reasonMsg);

                                                 }  

                                                }

          catch (Exception ex) {

Exception newEx = new Exception(“Error at:”+new java.util.Date()+””,ex);

 newEx.printStackTrace();

                                                }

}

public static void main(String args[])

{

StringDemo x=new StringDemo();

}

}

Java Basic Problems

Java: Final Variables, Methods and Final Classes

In my last post I have shared about  JButton and JMenuItem ActionListener.

Here I have shared about Final Variables, Methods and Final Class.

By default all methods and variables can be overridden in subclasses.

It is possible to prevent the subclasses from overriding the members of super class; we can declare them as final using the keyword final as a modifier.

The value of a final variable  can never be changed.

Ex : final int age=45;

Making a method final ensures that the functionality defined in this method will never be altered in any way.

Ex: final void age()

{

——

}

Final Classes

It may happen that  we want to prevent a class being subclassed for security reasons or for any other reason related to our software . We can do it easily using final class.  So,  the class that cannot be subclassed is called a final class.

Ex: final class age

{

}

If we try to inherit the above class will cause an error and the compiler will not allow it. It prevents any unwanted extension to the class.

Java Basic Problems

Java : How to know JButton is Clicked or JMenuItem is Clicked??

In my last post I have shared about How to show Bangla(Bengali) in JLabel.

Here I am going to share you about the detection of click event on Java swing .components.

In out java programming we usually use addActionListener  to detect any type of action performed on  java components. For example we can add addActionListener on JMenuItem, JButton etc.

Here I have given how to add actionListener in an easiest way and also about how to detect which component is being clicked.

There are various ways by which you can do the same work. But I found the below procedure is the easiest one.

 OUTPUT:

java actionlistener

Code Example:

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

public class MenuDemo extends JFrame implements ActionListener

{

JMenuBar menuBar = new JMenuBar();

JMenu menu = new JMenu(“File”);

JMenu menu1 = new JMenu(“Edit”);

JMenuItem item1 = new JMenuItem(“New”);

JMenuItem item2 = new JMenuItem(“Open”);

JButton myButton=new JButton(“Click”);

public MenuDemo()

{

setJMenuBar(menuBar);

setVisible(true);

setSize(400,200);

menuBar.add(menu);

menuBar.add(menu1);

item1.addActionListener(this);

myButton.addActionListener(this);

menu.add(item1);menu.add(item2);

JPanel panel=new JPanel();

setTitle(“JLabel Font Change”);

setDefaultCloseOperation(EXIT_ON_CLOSE);

getContentPane().add(panel);

panel.setLayout(null);

myButton.setBounds(95,55,90,50);

panel.add(myButton);

    }

 public void actionPerformed(ActionEvent e){

                   // TODO Auto-generated method stub

                   try {

                             if(e.getSource()==item1){

                             System.out.println(“\n”);

                             System.out.println(“You have Clicked on JMenu item”);

                             System.out.println(“Put Your Menu Item Action Condition here”);

                                                    }

                             else if(e.getSource()==myButton){

                             System.out.println(“\n”);

                             System.out.println(“You have Clicked on Button item”);

                             System.out.println(“Put Your Button Action Condition here”);

                                                    }

                             }

          catch(Exception exc){

    Exception newEx = new Exception(“Error at:”+new java.util.Date()+””,exc);

    newEx.printStackTrace();

   }

 }

 public static void main(String[]args)

 {

 MenuDemo ex=new MenuDemo();

 ex.setVisible(true);

 }

   }

Java Basic Problems

Java: I want to show Bangla(Bengali) in JLabel

In my last post I have discussed about How to Read a text file and search any specific word from that.

Today I will share with you another important fact in java porgramming about how to show Bangla (Bengali) font in JLabel using java.

The Font I have used here is not an Unicode font. To show Bangla I have used SuttonyMJ font.

I have a wish to share with you in another post about Unicode font in Java.

To show Bangla in JLabel is little bit tricy. Just write the Bengali word in a MSWord file and then pest it in the JLabel.

For example: JLabel label2=new JLabel(” †`Lv,  weeiY,  Rvbv”,JLabel.CENTER);

In the code you may not see the Bengali font accurately but after running the code, Java will show you the code accurately.

Check the OUTPUT:

 JLabel Bangla font java

Code Example:

import javax.swing.*;

import java.awt.*;

class labelFont extends JFrame

{

JLabel label1=new JLabel(“see,  description,  know”,JLabel.CENTER);

JLabel label2=new JLabel(” †`Lv,  weeiY,  Rvbv”,JLabel.CENTER);

JLabel label3=new JLabel(“I like Programming and I am a beginner”);

labelFont()

{

          label1.setBounds(95,00,140,40);

          label2.setBounds(95,35,140,40);

          label3.setBounds(15,200,270,40);

          Font displayFont=new Font(“Times New Roman”,Font.PLAIN,12);

    label1.setFont(displayFont);

          Font displayFont1=new Font(“SutonnyMJ”,Font.PLAIN,16);

    label2.setFont(displayFont1);

                  setSize(300,300);

                             setTitle(“JLabel Font Change”);

                             setDefaultCloseOperation(EXIT_ON_CLOSE);

                  JPanel panel=new JPanel();

            getContentPane().add(panel);

                             panel.setLayout(null);

                             panel.add(label1);

            panel.add(label2);

            panel.add(label3);

}

public static void main(String args[])

{

labelFont myFont=new labelFont();

myFont.setVisible(true);

}

}

Java Basic Problems

Java: How to Read a text file and search any specific word from that

In my last post I have given an idea about  How to change font of JLabel.

Here, I have shared   Reading a text file and search any specific word from that.

Sometimes we may need to search any specific word from a text file. For this, we need to know how to read a text file using java.

Here I have given a simple way, just read a text file and find out the search keyword, after finding out the search key word it will be shown on which line the searched keyword was found.

 ** It will give you just a basic idea.

Click Here to download the Code+Reader1.txt  to test yourself.

Code Example:

import java.io.*;

import java.util.*;

class filereader

{

public static void main(String args[]) throws Exception

   {

   int tokencount;

   FileReader fr=new FileReader(“reader1.txt”);

   BufferedReader br=new BufferedReader(fr);

   String s;

   int linecount=0;

   String line;

   String words[]=new String[500];

                                while ((s=br.readLine())!=null)

                                        {

                                        linecount++;

                                        int indexfound=s.indexOf(“see”);

                                                                     if (indexfound>-1)

                                                                     {

 System.out.println(“\n”);

 System.out.println(“Word was found at position::” +indexfound+ “::on line”+linecount);

System.out.println(“\n”);

 line=s;

System.out.println(line);

int idx=0;

StringTokenizer st= new StringTokenizer(line);

tokencount= st.countTokens();

System.out.println(“\n”);

System.out.println(“Number of tokens found” +tokencount); System.out.println(“\n”);                                             

 for (idx=0;idx<tokencount;idx++)                                                                                                    {

 words[idx]=st.nextToken();

System.out.println(words[idx]);

                                                           }

                                                            }

                                        }

   fr.close();

   }

}

OUTPUT:

file reader java

Java Basic Problems

Java: How to change font of JLabel?

In my last post I have discussed about JTextField Validation process.

Today I want to share my idea about how to change the font of JLabel in java.

Sometime in java programming we may need to change the font of   JLabel. Actually, it depends on the developer and may be for  the outlookings of the software.

So, whatever the reason is, there is a way to change the font  of JLabel in java.

In the given example, I have just tried to give an idea about  how to declare JLabel in java and also how to change the font and  font appearance of the following JLabel.

*** Important Note: Whatever the font you want to apply in your JLabel, it must be installed on  that computer.

Code Example:

import javax.swing.*;

import java.awt.*;

class labelFont extends JFrame

{

JLabel  label1=new JLabel(“Hi,My name is Prakash”,JLabel.CENTER);

JLabel  label2=new JLabel(“I am a Student”,JLabel.CENTER);

JLabel  label3=new JLabel(“I like Programming and I am a beginner”);

labelFont()

{

          label1.setBounds(95,00,140,40);

          label2.setBounds(95,15,140,40);

          label3.setBounds(15,200,270,40);

          Font displayFont=new Font(“Times New Roman”,Font.PLAIN,12);

    label1.setFont(displayFont);

          Font displayFont1=new Font(“Calibri (Body)”,Font.PLAIN,12);

    label2.setFont(displayFont1);

                  setSize(300,300);

                             setTitle(“JLabel Font Change”);

                             setDefaultCloseOperation(EXIT_ON_CLOSE);

           JPanel panel=new JPanel();

            getContentPane().add(panel);

                             panel.setLayout(null);

                             panel.add(label1);

            panel.add(label2);

            panel.add(label3);

}

public static void main(String args[])

{

labelFont myFont=new labelFont();

myFont.setVisible(true);

}

}

OUTPUT:

JLabel font change java

Java Basic Problems

Java: I don’t want to allow Plus (+) or Minus (-) sign as a first entry of my JTextField.

In my previous example I have shown about How to add TextField (JTextField)in java.

Here I will try to show how to add validation in JTextField.

Suppose,I am trying to prepare a Calculator and I don’t want my user to give invalid input at the  first keypress entry,  for example, Plus (+) or Minus (-).

But, they can give any numeric entry at the first keyPress.So, I  need to put validation in my JTextField so that Plus (+) or Minus () sign will not be allowed at the first keypress /key entry, but  they are allowed after any numeric or digit entry.

In the given example, if users press (+) or () sign at first, our program will show error message but it will allow users to take numeric entry at first. After first entry, (+) or minus (-) will be allowed.

 

Code Example:

import java.awt.*;

import java.awt.event.*;

import java.awt.event.KeyEvent;

import javax.swing.*;

import java.util.*;

public class Calc extends JFrame

{

   JTextField ques, answer;

   private Toolkit toolkit;

   char ch;

   int plusOccurs=0;

        public Calc()

                   {                

       JPanel panel =new JPanel();

       getContentPane().add(panel);

       panel.setLayout(null);

          setSize(300,200);

          setTitle(“Easy Calculator”);

              setDefaultCloseOperation(EXIT_ON_CLOSE);

               toolkit=getToolkit();

                    Dimension size=toolkit.getScreenSize();

                    setLocation(size.width/2-getWidth()/2, size.height/2-getHeight()/2);

                    ques=new JTextField();

                    answer=new JTextField();

        JButton calculate=new JButton(“Calculate”);

        calculate.setBounds(75,50,90,30);

                   ques.setBounds(10,10,220,30);     // Positioning of TextField(JTextField)

          answer.setBounds(10,100,220,30); //Positioning  of TextField(JTextField)

          panel.add(calculate);

          panel.add(ques );    // Adding TextField(JTextField) in JPanel

          panel.add(answer );  // Adding TextField(JTextField) in JPanel

                    ques.addKeyListener(new KeyAdapter()

                    {

                    public void keyTyped(KeyEvent e)

                    {

                      ch=e.getKeyChar();

               if (ch==’+’ && ques.getText().length()==0)

                 {

   System.out.println(“\n”);

   System.out.println(“Sorry, You have entered :”+ch+”:at first,Please Enter Numeric value, then try”);

                      ques.setEditable(false);

                      ques.setBackground(Color.WHITE);

                      }

                    else if (ch==’-‘&& ques.getText().length()==0)

                 {

                      System.out.println(“\n”);

                                         System.out.println(“Sorry, You have entered :”+ch+”:at first,Please Enter Numeric value at first”);

                      ques.setEditable(false);

                      ques.setBackground(Color.WHITE);

                      }

                      else

                      {

                      ques.setEditable(true);

                      ques.setBackground(Color.WHITE);

                      }

                    }

                    });

                    }

Java Basic Problems

Java: How to use Message Dialog Box and Message Input Box

Sometimes we may need in java programming to use input box to take input from the users in the same way we may also need to show some result or data in the pop up message dialog box.

Here I have given a little example of how to show or use Message Dialog Box and Message Input Box in java.

Here in the example Message Input Box will take input from the user and show the result in Message Dialog box.

Here is the code example:

import javax.swing.*;

class jPaneTest 

{

public void jOptionPaneTest()

                   {

          String reason=JOptionPane.showInputDialog(“Please Enter Number:”);

          JOptionPane.showMessageDialog(null,”Your Marks:”+reason);

                   }

public static void main(String args[])

{

jPaneTest newTest=new jPaneTest();

newTest.jOptionPaneTest();

}

}