Sunday, August 28, 2016

COMPUTER HARDWARE

COMPUTER HARDWARE


Computer hardware is the collection of physical parts of a computer system. This includes the computer case, monitor, keyboard, and mouse. It also includes all the parts inside the computer case, such as the hard disk drive, motherboard, video card, and many others. Computer hardware is what you can physically touch and see.
A computer system consists of two major elements: hardware and software. Computer hardware is the collection of all the parts you can physically touch. Computer software, on the other hand, is not something you can touch. Software is a set of instructions for a computer to perform specific operations. You need both hardware and software for a computer system to work.
Some hardware components are easy to recognize, such as the computer case, keyboard, and monitor. However, there are many different types of hardware components.
Before looking at the various components, it is useful to distinguish between two different types of computers: desktop computers and laptop computers. A desktop computer consists of a computer case and a separate monitor, keyboard, and mouse. As the name suggests, this type of computer is typically placed on a desk and is not very portable.
laptop computer has the same components but integrated into a single, portable unit.
While these two types of computers look quite different, they have the same general hardware components.
Hardware represents the physical and tangible components of a computer i.e. the components that can be seen and touched.
Examples of Hardware are following:
  • Input devices -- keyboard, mouse etc.
  • Output devices -- printer, monitor etc.
  • Secondary storage devices -- Hard disk, CD, DVD etc.
  • Internal components -- CPU, motherboard, RAM etc.
 Here are the main types of computer hardware that you can buy for your PC.

1. Hard drive - also called hard disk, it is the permanent storage space that stores all information and applications of the computer, retaining the space even when it is turned off.

2. Motherboard - Considered as the most important types of computer hardware. The motherboard houses the microprocessor, providing the necessary sockets and slots that connect to all other types of computer hardware. Thus the motherboard serves as the 'mediator', a channel that allows the components to work together and walk to each other, making it a whole and completely working unit.

3. RAM - short for Random Access Memory. It is the memory used to process applications. RAM is lost when the computer is turned off.

4. ROM - short for Read Only Memory. It serves as memory for storage of programs.

5. Storage Devices - External storage devices like CDs, DVDs, USB flash drives are important as removable storage devices that you can take from one personal computer to another.

6. Power Supply Unit (PSU) - this converts the AC power to low voltage DC power, integral for the internal components of the PC.

7. Sound Card - responsible for the PC's audio input and output, necessary for games, music and other multimedia programs.

8. Keyboard - an input device used to input text & characters by pressing the keys.

9. Mouse - pointing device that detects two-dimensional motion to the surface. Other pointing devices include the track ball, the touch pad and the touch screen.

10. Joystick - a gaming device with a handheld stick that pivots from left to right and up to down, detecting angles in two and three dimensions.

11. Image input devices - includes scanners and web cams, these devices are used to provide input of images, written text, handwriting, etc for digital use.

12. Image output devices - the printer, used to produce a physical and permanent text or graphic document.

13. Audio input devices - the microphone is used to record or provide input through sound conversion to electrical signals.

14. Audio output devices - headphones and speakers that allows you to hear the audio coming from the computer.

15. Monitor - the monitor is an electronic visual display that shows the graphical and textual information of the computer. There are may types of monitors, such as the CRT (Cathode Ray Tube), which is almost obsolete, the LCD (Liquid Crystal Display) which is the most common monitor used nowadays, and the touch screen display.

Labels:

Thursday, August 25, 2016

printf() Function in C

printf() Function


Description

The C library function int printf(const char *format, ...) sends formatted output to stdout.

Declaration

Following is the declaration for printf() function.
int printf(const char *format, ...)

Parameters:

format:  This is the string that contains the text to be written to stdout. It can optionally contain embedded format tags that are replaced by the values specified in subsequent additional arguments and formatted as requested. Format tags prototype is %[flags][width][.precision][length]specifier, which is explained below 
specifier
Output
c
Character
d or i
Signed decimal integer
e
Scientific notation (mantissa/exponent) using e character
E
Scientific notation (mantissa/exponent) using E character
f
Decimal floating point
g
Uses the shorter of %e or %f
G
Uses the shorter of %E or %f
o
Signed octal
s
String of characters
u
Unsigned decimal integer
x
Unsigned hexadecimal integer
X
Unsigned hexadecimal integer (capital letters)
p
Pointer address
n
Nothing printed
%
Character

flags
Description
-
Left-justify within the given field width; Right justification is the default (see width sub-specifier).
+
Forces to precede the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a -ve sign.
(space)
If no sign is going to be written, a blank space is inserted before the value.
#
Used with o, x or X specifiers the value is preceded with 0, 0x or 0X respectively for values different than zero. Used with e, E and f, it forces the written output to contain a decimal point even if no digits would follow. By default, if no digits follow, no decimal point is written. Used with g or G the result is the same as with e or E but trailing zeros are not removed.
0
Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier).

width
Description
(number)
Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
*
The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

.precision
Description
.number
For integer specifiers (d, i, o, u, x, X) − precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0. For e, E and f specifiers − this is the number of digits to be printed after the decimal point. For g and G specifiers − This is the maximum number of significant digits to be printed. For s − this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered. For c type − it has no effect. When no precision is specified, the default is 1. If the period is specified without an explicit value for precision, 0 is assumed.
.*
The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

length
Description
h
The argument is interpreted as a short int or unsigned short int (only applies to integer specifiers: i, d, o, u, x and X).
l
The argument is interpreted as a long int or unsigned long int for integer specifiers (i, d, o, u, x and X), and as a wide character or wide character string for specifiers c and s.
L
The argument is interpreted as a long double (only applies to floating point specifiers: e, E, f, g and G)



additional arguments: Depending on the format string, the function may expect a sequence of additional arguments, each containing one value to be inserted instead of each %-tag specified in the format parameter (if any). There should be the same number of these arguments as the number of %-tags that expect a value.


Return Value

If successful, the total number of characters written is returned. On failure, a negative number is returned.

Labels:

main() function

main() Function

All C language programs must have a main() function. It's the core of every program. It's required. The main() function doesn't really have to do anything other than be present inside your C source code. Eventually, it contains instructions that tell the computer to carry out whatever task your program is designed to do. But it's not officially required to do anything.

A program shall contain a global function named main, which is the designated start of the program.
Also called as Driver Function.
int main () { body }(1)
int main (int argc, char *argv[]) { body }(2)
int main (int argc, char *argv[] , other_parameters ) { body }(3)
argc-Non-negative value representing the number of arguments passed to the program from the environment in which the program is run.
argv-Pointer to the first element of an array of pointers to null-terminated multibyte strings that represent the arguments passed to the program from the execution environment (argv[0]through argv[argc-1]). The value of argv[argc] is guaranteed to be 0.
body-The body of the main function
other_parameters-Implementations may allow additional forms of the main function as long as the return type remains int. A very common extension is passing a third argument of type char*[] pointing at an array of pointers to the execution environment variables.
The names argc and argv are arbitrary, as well as the representation of the types of the parameters: 

            int main(int ac, char** av) is equally valid.

The main function is called at program startup. It is the designated entry point to a program that is executed in hosted environment (that is, with an operating system). The entry points to freestanding programs (boot loaders, OS kernels, etc) are implementation-defined.
The parameters of the two-parameter form of the main function allow arbitrary multi byte character strings to be passed from the execution environment (these are typically known as command line arguments), the pointers argv[1] .. argv[argc-1] point at the first characters in each of these strings. argv[0] is the pointer to the initial character of a null-terminated multibyte strings that represents the name used to invoke the program itself (or an empty string "" if this is not supported by the execution environment). The strings are modifiable, although these modifications do not propagate back to the execution environment: they can be used, for example, with std::strtok. The size of the array pointed to by argv is at least argc+1, and the last element, argv[argc], is guaranteed to be a null pointer.



Labels:

Keywords and Identifiers

Keywords and Identifiers


C TOKENS:

  • C tokens are the basic buildings blocks in C language which are constructed together to write a C program.
  • Each and every smallest individual units in a C program are known as C tokens.
  • C tokens are of six types. They are,
  1. Keywords               (eg: int, while),
  2. Identifiers               (eg: main, total),
  3. Constants              (eg: 10, 20),
  4. Strings                    (eg: “total”, “hello”),
  5. Special symbols  (eg: (), {}),
  6. Operators              (eg: +, /,-,*)
Keywords are the reserved words in programming and are part of the syntax. 

Character set

Character set is a set of alphabets, letters and some special characters that are valid in C language.

Alphabets

Uppercase: A B C ................................... X Y Z
Lowercase: a b c ...................................... x y z

Digits

0 1 2 3 4 5 6 7 8 9

Special Characters


,<>._
();$:
%[]#?
'&{}"
^!*/|
-\~+

White space Characters

blank space, new line, horizontal tab, carriage return and form feed.

Carriage return:
Carriage return means to return to the beginning of the current line without advancing downward. The name comes from a printer's carriage, as monitors were rare when the name was coined. This is commonly escaped as "\r", abbreviated CR, and has ASCII value 13 or 0x0D.

Line feed:
Linefeed means to advance downward to the next line; however, it has been repurposed and renamed. Used as "newline", it terminates lines (commonly confused with separating lines). This is commonly escaped as "\n", abbreviated LF or NL, and has ASCII value 10 or 0x0A. CRLF (but not CRNL) is used for the pair "\r\n".

Form feed:
Form feed means advance downward to the next "page". It was commonly used as page separators, but now is also used as section separators. (It's uncommonly used in source code to divide logically independent functions or groups of functions.) Text editors can use this character when you "insert a page break". This is commonly escaped as "\f", abbreviated FF, and has ASCII value 12 or 0x0C.

Keywords

Keywords are predefined, reserved words used in programming that have special meaning. Keywords are part of the syntax and they cannot be used as an identifier. For example:
int money;
Here, int is a keyword that indicates 'money' is a variable of type integer. 
As C is a case sensitive language, all keywords must be written in lowercase. Here is a list of all keywords allowed in ANSI C.
autodoubleintstruct
breakelselongswitch
caseenumregister typedef
charexternreturnunion
continueforsignedvoid
doifstatic while
defaultgotosizeofvolatile
constfloatshortunsigned


Standard Identifies in c (Predefined)


Identifiers

Identifiers are the names that are given to various program elements such as variables, symbolic constants and functions.Variable or function identifier that is called a symbolic constant name.
Identifier names must be unique. They are created to give unique name to a C entity to identify it during the execution of a program. For example:
                            int money;

                           double accountBalance;
Here, money and accountBalance are identifiers.
Also remember, identifier names must be different from keywords. You cannot use int as an identifier because int is a keyword.

Rules for writing an identifier

  1. A valid identifier can have letters (both uppercase and lowercase letters), digits and underscore only.
  2. The first letter of an identifier should be either a letter or an underscore. However, it is discouraged to start an identifier name with an underscore. It is because identifier that starts with an underscore can conflict with system names.
  3. In such cases, compiler will complain about it. Some system names that start with underscore are _fileno_iob_wfopen etc.
  4. There is no rule on the length of an identifier. However, the first 31 characters of identifiers are discriminated by the compiler. So, the first 31 letters of two identifiers in a program should be different.
  5. There should be no blank space while declaring an identifier
  6. No special characters, such as semicolon,period,blank space, slash or comma are permitted.

Good Programming Practice:
You can choose any name for an identifier. However, if the programmer choose meaningful name for an identifier, it will be easy to understand and work on.


Labels:

Saturday, August 20, 2016

Persistence

Persistence

Persistence is the ability to save a Bean to nonvolatile storage and retrieve it at a later time. The information that is particularly important are the configuration settings. 
Let us first see how the BDK allows you to save a set of Beans that have been configured and connected together to form an application. 
Recall our previous example involving both the Colors and TickTock Beans. The rectangular property of the Colors Bean was changed to true, and the interval property of the TickTock Bean was changed to one second. These changes can be saved. 
To save the application, go to the menu bar of the BeanBox and select File | Save. A dialog box should appear, allowing you to specify the name of a file to which the Beans and their configuration parameters should be saved. Supply a filename and click the OK button on that dialog box. Exit from the BDK. Start the BDK again.
 To restore the application, go to the menu bar of the BeanBox and select File | Load. A dialog box should appear, allowing you to specify the name of the file from which an application should be restored. 
Supply the name of the file in which the application was saved, and click the OK button. Your application should now be functioning. Confirm that the rectangular property of the Colors Bean is true and that the interval property for the TickTock Bean is equal to one second. 
The object serialization capabilities provided by the Java class libraries are used to provide persistence for Beans. If a Bean inherits directly or indirectly from java.awt.Component, it is automatically serializable, because that class implements the java.io.Serializable interface. 
If a Bean does not inherit an implementation of the Serializable interface, you must provide this yourself. Otherwise, containers cannot save the configuration of your component. 
The transient keyword can be used to designate data members of a Bean that should not be serialized. The color variable of the Colors class is an example of such an item.

Labels: