Basics of computer hardware

BASICS OF COMPUTER HARDWARE
Basics of computer hardware includes the basic components of computer and its terms and terminologies.


CPU CABINET

CPU cabinets are the only containers of the hardware components of the computer, their are mainly two classifications of cabinets AT and ATX (came from AT and ATX class motherboards).

AT   - Created by IBM.
ATX- Created by Intel.

AT is an old method where the size is bigger and most ports are located at the back of the cabinet and power is directly connected to the board rather than to the switch, with this system will turn off but power supply will last until the user manually switches off.

ATX cabinets are cute and provides customization of ports and the power supplied through switches so power will be dropped automatically when the system is turned off.

AT 



ATX


SMPS(Switch Mode Power Supply)

Distributes the total power into required amount of power to each component of the computer.


Motherboard

An area where all the components are connected especially the processor.



RAM(Random Access Memory)

A primary memory where files are loaded when an application is executed its dependent files are loaded into the primary memory.

DDR(Double Data Rate)

According to the class of motherboard,capacity and speed RAM vary and new innovations are made..

DDR1


DDR2


DDR3

PCI(Peripheral Component Interconnect)

Enables the user to add extra cards which provides better facility and performance examples sound card,graphics card, TV turner card these enables extra memory allocated to them with the help of special driver software.

The main advantage of PCI is that if the on board functioning is stopped then the user can provide that functionality by adding the corresponding PCI card in the PCI slot of motherboard.

Example:- if a motherboard doesn't provides sound functionality then the user can add a sound card into the PCI slot with corresponding driver software and can enjoy the sound.


BIOS(Basic Input/Output System)

Consist of a set of programs which enables the user/Administrator to choose between the functionality of the computer. set of instructions that are maintained as the configuration of the system.

CMOS(Complementary Metal Oxide Semiconductor)

Which is used to save the changes made to the BIOS settings.

POST(Power On Self  Test)

Checking the hardware components status that they are ready for the processing and if everything is correct then loads the OS. Will return a beep sound from the system when it is switched on(if the on board speaker is connected).




C program downloads


1. Matrix multiplication : Reads two arrays from the user and assigns the result in another array and prints the array.   Download

2. Sub-string : Returns the sub string from a string.   Download

3. Student details using file : Reads student information from the user and writes to a file and reads data from the file and prints the data.   Download

4. String length using pointer : Finds the length of the string using pointer.   Download

5. String length : Finds the string length.   Download

6. String Concatenation :  Concatenates one string with another.   Download

7. Sine series : Prints the sine equivalent of the given number.   Download

8. Cosine series : Prints the cosine equivalent of the given number.   Download

9. Exponential series : Prints the exponent value of the given number.   Download

10. String Reverse : Prints the given string in reverse.   Download

11. String replace : Replaces a string with existing string.   Download

12. File operations : Performs file operations like read and writing to file.   Download

13. Prime numbers : Prime numbers.   Download

14. Pattern search : Searches for a string in a given string.   Download

15. Pascal Triangle : Prints pascal triangle.   Download

16. Hash search : Searching for an element using hashing algorithm.   Download

17. Towers of Hanoi : Program to present towers of Hanoi.   Download

18. Floyd s triangle :  Prints Floyd s triangle.   Download

19. Fibonacci series : Prints Fibonacci numbers up to a given limit.   Download

20. Factorial : Prints the factorial of numbers.   Download

21. Converting decimal number to octal : Converts a given decimal number to its octal number format.   Download

22. Multiplication table : Prints the multiplication table of the given number up to a given limit.   Download

23. ASCII : Returns the ASCII value of the given value.   Download

24. Palindrome number : Returns whether the given number is palindrome number or not.   Download

25. Armstrong numbers : Returns whether the given number is Armstrong number or not.   Download 


NOTE : To run the downloaded C file, install C in the system and paste the downloaded C file in the root directory (for convenience) and open that file from the C application first Compile the program  and then Run.

 

Java reference VOL-4


File I/O and Streams
You can write data to a file instead of the computer screen. You can write certain data to a file while still putting other data on the screen. Or you may need access to multiple files simultaneously. Or you may want to query the user for input rather than accepting it all on the command line. Or maybe you want to read data out of a file that's in a particular format. In Java all these methods take place as streams. < > Using File I/O streams. The System.out.println() statement we've been using all along is an implementation of Streams.

A program that writes a string to a file



In order to use the Java file classes, we must import the Java input/output package (java.io) in the following manner


import java.io.*;


Inside the main method of our program, we must declare a FileOutputStream object. In this case, we wish to write a string to the file, and so we create a new PrintStream object that takes as its constructor the existing FileOutputStream. Any data we send from PrintStream will now be passed to the FileOutputStream, and ultimately to disk. We then make a call to the println method, passing it a string, and then close the connection.

Source Code

/*
* FileOutput
* Demonstration of FileOutputStream and PrintStream classes
*/


import java.io.*;


class FileOutput
{


public static void main(String args[])
{
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object


try
{
// Create a new file output stream connected to "myfile.txt"
out = new FileOutputStream("myfile.txt");


// Connect print stream to the output stream
p = new PrintStream( out );


p.println ("This is written to a file myFile.txt");


p.close();
}
catch (Exception e)
{
System.err.println ("Error writing to the file myFile.txt");
}
}
}



Program asking  the user for their name and then prints a personalized greeting.



Source Code



import java.io.*;





class PersonalHello {

  public static void main (String args[])
    {
    
      byte name[] = new byte[100];
      int nr_read = 0;

      System.out.println("Your name Please?");
      try {
        nr_read = System.in.read(name);
        System.out.print("Hello ");
        System.out.write(name,0,nr_read);
      }
      catch (IOException e) {
        System.out.print("I did not get your name.");
      }
      
    }
    
}

In code that does any significant input or output you'll want to begin by importing all the various java.io classes. import.java.io.*; Most of the reading and writing you do in Java will be done with bytes. Here we've started with an array of bytes that will hold the user's name.

First we print a query requesting the user's name. Then we read the user's name using the

System.in.read()
method. This method takes a byte array as an argument, and places whatever the user types in that byte array. Then, like before, we print "Hello." Finally we print the user's name.

The program doesn't actually see what the user types until he or she types a carriage return. This gives the user the chance to backspace over and delete any mistakes. Once the return key is pressed, everything in the line is placed in the array.

Often strings aren't enough. A lot of times you'll want to ask the user for a number as input. All user input comes in as strings so we need to convert the string into a number.

The

getNextInteger()
method that will accept an integer from the user. Here it is:

  static int getNextInteger() {



  
    String line;
  
    DataInputStream in = new DataInputStream(System.in);
    try {
      line = in.readLine();
      int i = Integer.valueOf(line).intValue();
      return i;
    }
    catch (Exception e) {
      return -1;
    }
       
  } // getNextInteger ends here

It's often the case that you want to read not just one number but multiple numbers. Sometimes you may need to read text and numbers on the same line. For this purpose Java provides the StreamTokenizer class.

Sometimes you want to save your output in a  file. To do this we'll need to learn how to write data to a file. 

Source Code



// Write the Fahrenheit to Celsius table in a file





import java.io.*;

class FahrToCelsius  {

  public static void main (String args[]) {

    double fahr, celsius;
    double lower, upper, step;

    lower = 0.0;    // lower limit of temperature table
    upper = 300.0;  // upper limit of temperature table
    step  = 20.0;   // step size

    fahr = lower;
  
    try {

      FileOutputStream fout =  new FileOutputStream("test.out");

      // now to the FileOutputStream into a PrintStream
      PrintStream myOutput = new PrintStream(fout);
  
      while (fahr <= upper) {  // while loop begins here
        celsius = 5.0 * (fahr-32.0) / 9.0;
        myOutput.println(fahr + " " + celsius);
        fahr = fahr + step;
      } // while loop ends here
  
    }  // try ends here
    catch (IOException e) {
      System.out.println("Error: " + e);
      System.exit(1);
    }
  
  } // main ends here

}

There are only three things necessary to write formatted output to a file rather than to the standard output:
  1. Open a FileOutputStream using a line like

FileOutputStream fout =  new FileOutputStream("test.out");



This line initializes the FileOutputStream with the name of the file you want to write into.
  1. Convert the FileOutputStream into a PrintStream using a statement like

PrintStream myOutput = new PrintStream(fout);



The PrintStream is passed the FileOutputStream from step 1.
  1. Instead of using System.out.println()use myOutput.println(). System.outand myOutputare just different instances of the PrintStreamclass. To print to a different PrintStreamwe keep the syntax the same but change the name of the PrintStream.

Now that we know how to write a text file, let's try reading one. The following code accepts a series of file names on the command line and then prints those filenames to the standard output in the order they were listed.

// Imitate the Unix cat utility





import java.io.*;

class cat  {

  public static void main (String args[]) {
  
  String thisLine;

  //Loop across the arguments
  for (int i=0; i < args.length; i++) {

  //Open the file for reading
  try {
    FileInputStream fin =  new FileInputStream(args[i]);

    // now turn the FileInputStream into a DataInputStream
    try {
      DataInputStream myInput = new DataInputStream(fin);
  
      try {
        while ((thisLine = myInput.readLine()) != null) {  // while loop begins here
          System.out.println(thisLine);
        } // while loop ends here
      }
      catch (Exception e) {
       System.out.println("Error: " + e);
      }
    } // end try
    catch (Exception e) {
      System.out.println("Error: " + e);
    }
  
   } // end try
   catch (Exception e) {
    System.out.println("failed to open file " + args[i]);
    System.out.println("Error: " + e);
  }
  } // for end here
  
  } // main ends here

} 

Java Command Line Arguments
This class demonstrates how command line arguments are passed in Java. Arguments are passed as a String array to the main method of a class. The first element (element 0) is the first argument passed not the name of the class.

Source Code
An example that prints in the command line arguments passed into the class when executed.
public class ReadArgs
{
       public static final void main(String args[])
       {
                for (int i=0;i<args.length;++i)
                {
                         System.out.println( args[i] );
                }
        }


Sample Run

With the following command line, the output shown is produced.

java ReadArgs zero one two three


Output:

The following command line arguments were passed:
arg[0]: zero
arg[1]: one
arg[2]: two
arg[3]: three

Java Loops (while, do-while and  for loops)
A loop is a section of code that is executed repeatedly until a stopping condition is met. A typical loop may look like:
 
while there's more data {
  Read a Line of Data
  Do Something with the Data
}
There are many different kinds of loops in Java including while, for, and do while loops. They differ primarily in the stopping conditions used.

For

loops typically iterate a fixed number of times and then exit.
Whileloops iterate continuously until a particular condition is met. You usually do not know in advance how many times a whileloop will loop.

In this case we want to write a loop that will print each of the command line arguments in succession, starting with the first one. We don't know in advance how many arguments there will be, but we can easily find this out before the loop starts using the

args.length
. Therefore we will write this with a forloop. Here's the code:

Source Code



// This is the Hello program in Java

class Hello {


    public static void main (String args[]) {

   

      int i;

   

      /* Now let's say hello */

      System.out.print("Hello ");

      for (i=0; i < args.length; i = i++) {

        System.out.print(args[i]);

        System.out.print(" ");

      }

      System.out.println();

  }


}



We begin the code by declaring our variables. In this case we have exactly one variable, the integer i.

i

Then we begin the program by saying "Hello" just like before.

Next comes the

for
loop. The loop begins by initializing the counter variable ito be zero. This happens exactly once at the beginning of the loop. Programming tradition that dates back to Fortran insists that loop indices be named i, j, k, l, mand nin that order.

Next is the test condition. In this case we test that

i
is less than the number of arguments. When ibecomes equal to the number of arguments, (args.length) we exit the loop and go to the first statement after the loop's closing brace. You might think that we should test for ibeing less than or equal to the number of arguments; but remember that we began counting at zero, not one.

Finally we have the increment step,

i++ (i=i+1)
. This is executed at the end of each iteration of the loop. Without this we'd continue to loop forever since iwould always be less than args.length.