Tuesday, January 25, 2011

DHTML

What is DHTML?

DHTML is the art of making HTML pages dynamic!

Dynamic HTML or DHTML is a term used for a collection of technologies, used together to create interactive and animated web sites by using a combination of static markup language (such as HTML), a client-side scripting language (such as JavaScript), the presentation definition language (Cascading Style Sheets).

Client-side scripting

Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side (on the web server). This type of computer programming is an important part of the Dynamic HTML (DHTML) concept, enabling web pages to be scripted; that is, to have different and changing content depending on user input, environmental conditions (such as the time of day), or other variables.

Server-side scripting

Server-side scripting is a web server technology in which a user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages. It is usually used to provide interactive web sites that interface to databases or other data stores. This is different from client-side scripting where scripts are run by the viewing web browser, usually in JavaScript. The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores.

What Is JavaScript?

JavaScript is the premier client-side scripting language used today on the Web. It’s widely used in tasks ranging from the validation of form data to the creation of complex user interfaces. JavaScript lets you build interactions between page content, the state of the browser, and the actions of the user.

Designed for Simple, Small Programs
JavaScript is well suited to implementing simple, small programs such as unit conversion calculator between miles and kilometers or pounds and kilograms. These tasks can be easily written and performed at acceptable speeds with JavaScript and would be easily integrated into a Web page.

Designed for Programming User Events
Because of the way in which JavaScript is integrated into the browser and can interact directly with HTML pages, JavaScript makes it possible to program responses to user events such as mouse clicks and data entry in forms.
For instance, a JavaScript script could be used to implement a simple help system. Whenever the user points at a button or a link on the page, a helpful and informative message can be displayed in the status bar at the bottom of the browser window.
This adds interactivity to Web pages, makes forms dynamic, and can decrease the bandwidth requirements and server load incurred.
Easy Debugging and Testing
Like other scripting languages, JavaScript eases development and trouble-shooting because it is not compiled. It is easy to test program code, look at the results, make changes, and test it again without the overhead and delay of compiling.

Versions of JavaScript
Version Description
JavaScript 1.0 The original version of the language. It was buggy and is now essentially obsolete. Implemented by Netscape 2.
JavaScript 1.1 Introduced a true Array object; most serious bugs resolved. Implemented by Netscape 3.
JavaScript 1.2 Introduced the switch statement, regular expressions, and a number of other features. Almost compliant with ECMA v1, but has some incompatibilities. Implemented by Netscape 4.
JavaScript 1.3 Fixed incompatibilities of JavaScript 1.2. Compliant with ECMA v1. Implemented by Netscape 4.5.
JavaScript 1.4 Implemented only in Netscape server products.
JavaScript 1.5 Introduced exception handling. Compliant with ECMA v3. Implemented by Mozilla and Netscape 6.
JScript 1.0 Roughly equivalent to JavaScript 1.0. Implemented by early releases of IE 3.
JScript 2.0 Roughly equivalent to JavaScript 1.1. Implemented by later releases of IE 3.
JScript 3.0 Roughly equivalent to JavaScript 1.3. Compliant with ECMA v1. Implemented by IE 4.
JScript 4.0 Not implemented by any web browser.
JScript 5.0 Supported exception handling. Partially compliant with ECMA v3. Implemented by IE 5.
JScript 5.5 Roughly equivalent to JavaScript 1.5. Fully compliant with ECMA v3. Implemented by IE 5.5 and IE 6. (IE 6 actually implements JScript 5.6, but 5.6 is not different from 5.5 in any way that is relevant to client-side JavaScript programmers.)
ECMA v1 The first standard version of the language. Standardized the basic features of JavaScript 1.1 and added a few new features. Did not standardize the switch statement or regular expression support. Conformant implementations are JavaScript 1.3 and JScript 3.0.
ECMA v2 A maintenance release of the standard that included clarifications but defined no new features.
ECMA v3 Standardized the switch statement, regular expressions, and exception handling. Conformant implementations are JavaScript 1.5 and Jscript 5.5.

Characteristics of JavaScript
1. Written using the Unicode character set.
2. Case-sensitive language.
3. JavaScript ignores spaces, tabs, and new lines that appear between tokens in programs, except those that are part of string or regular expression literals.
4. Simple statements in JavaScript are generally followed by semicolons (;), just as they are in C, C++, and Java.
5. JavaScript, like Java, supports both C++ and C-style comments
Ex. //  for single line comment
/* (text here) */  for multiple line comment

Data Structure of Programming Language

Introduction

In computer science, a data structure is a way of storing data in a computer so that it can be used efficiently. Often a carefully chosen data structure will allow the most efficient algorithm to be used. A well-designed data structure allows a variety of critical operations to be performed, using as few resources, both execution time and memory space, as possible. Data structures are implemented using the data types, references and operations on them provided by a programming language.

Chapter 1: Memory, Abstract Data Types, and Addresses

Computer memory is divided into three sections: main memory, cache memory in the central processing unit (CPU), and persistent storage. Main memory, also called random access memory (RAM), is where instructions (programs) and data are stored.

Main memory
- are also called random access memory (is where instructions and data are stored)
- is volatile; that is, instructions and data contained in main memory are lost once the computer is powered down.

Cache memory
-used to store frequently used instructions and data that either is, will be, or has been used by the CPU.
-A segment of the CPU’s cache memory is called a register. A register is a small amount of memory within the CPU that is used to temporarily store instructions and data.

Persistent storage
- An external storage device such as a hard disk that stores instructions and data.
- Persistent storage is nonvolatile; that is, instructions and data remain stored even when the computer is powered down.

Data and Memory
Data used by your program is stored in memory and manipulated by various data structure techniques, depending on the nature of your program.
Reserving memory
Before any data can be stored in memory, you must tell the computer how much space to reserve for data by using an abstract data type.
Abstract data type
- is a keyword of a programming language that specifies the amount of memory needed to store data and the kind of data that will be stored in that memory location.

Memory Address
Imagine main memory as a series of seemingly endless boxes organized into groups of eight. Each box holds a zero or one. Each group of eight boxes (1 byte) is assigned a unique number called a memory address,
Chapter 2: The Point about Variables and Pointers

A pointer is a variable that is used to point to a memory address whose content you want to use in your program.
Declaring Variables and Objects
Memory is reserved by using a data type in a declaration statement. The form of a declaration statement varies depending on the programming language you use. Here is a declaration statement for C, C++, and Java:
int myVariable;
There are three parts to this declaration statement:
• Data type - Tells how much memory to reserve  and the kind of data that will be stored in that memory location
• Variable name - A name used within the  program to refer to the contents of that memory location
• Semicolon - Tells the computer this is an  instruction (statement)

Primitive Data Types and User-Defined Data Types

Primitive Data Type
- Primitive data type is defined by the programming language.
- Some programmers call these built-in data types.
User-defined data type
- group of primitive data types defined by the programmer
- User-defined data type varies depending on the programming language used to write the program.
Defining a User-Defined Data Type
A structure definition consists of four elements:
• struct - Tells the computer that you are defining a structure
• Structure name - The name used to uniquely identify the structure and used to declare instances of a structure
• Structure body - open and close braces within which are primitive data types that are declared when an instance of the structure is declared
• Semicolon - Tells the computer this is an instruction (statement).
The body of a structure can contain any combination of primitive data types and previously defined user-defined data types depending on the nature of the data required by your program. Here is a structure that defines a student record consisting of a student number and grade. The name of this user-defined data type is StudentRecord:
struct StudentRecord
{
int studentNumber;
char grade;
};

Declaring a User-Defined Data Type
You declare an instance of a user-defined data type using basically the same technique that you used to declare a variable. However, you use the name of the structure in place of the name of the primitive data type in the declaration station.
#include
using namespace std; ////use to look in the std library to find the object
struct StudentRecord
{
int studentNumber;
char grade;
} ;
void main()
{
StudentRecord myStudent;
myStudent.studentNumber = 10;
myStudent.grade = 'A';
cout << "grades: " << myStudent.studentNumber << " "
<< myStudent.grade << endl;
}
The declaration statement tells the computer to reserve memory the size required to store the StudentRecord user-defined data type and to associate myStudent with that memory location. The size of a user-defined data type is equal to the sum of the sizes of the primitive data types declared in the body of the structure.
Pointers
- A pointer is a variable and can be used as an element of a structure and as an attribute of a class in some programming languages such as C++, but not Java.
- However, the contents of a pointer is a memory address of another location of memory, which is usually the memory address of another variable, element of a structure, or attribute of a class.
Declaring a Pointer
A pointer is declared similar to how you declare a variable. The following example declares a pointer called ptGrade. There are four parts of this declaration:
• Data type The data type of the memory address stored in the pointer
• Asterisk (*) Tells the computer that you are declaring a pointer
• Variable name The name that uniquely identifies the pointer and is used to reference the pointer within your program
• Semicolon Tells the computer this is an instruction (statement)
char *ptGrade;

Monday, November 22, 2010

Cool Interesting tutorial

Visit this site and here

Getting Started with C

A Brief History of the C Language

C was created by Dennis Ritchie at the Bell Telephone Laboratories in 1972. The language wasn't created for the fun of it, but for a specific purpose: to design the UNIX operating system (which is used on many computers). C is considered as middle-level programming language, because it combined the power of low-level language and the elegance of high-level language. This means that C language can directly manipulate the bits, bytes and even the systems programming.

Because C is such a powerful and flexible language, its use quickly spread beyond Bell Labs. Programmers everywhere began using it to write all sorts of programs. Soon, however, different organizations began utilizing their own versions of C, and subtle differences between implementations started to cause programmers headaches. In response to this problem, the American National Standards Institute (ANSI) formed a committee in 1983 to establish a standard definition of C, which became known as ANSI Standard C. With few exceptions, every modern C compiler has the ability to adhere to this standard.
Now, what about the name? The C language is so named because its predecessor was called B. The B language was developed by Ken Thompson of Bell Labs.
Why Use C?
In today's world of computer programming, there are many languages to choose from, such as C, Pascal, BASIC, and Java. These are all excellent languages suited for most programming tasks. Even so, there are several reasons why many computer professionals feel that C is at the top of the list:
  • C is a popular language preferred by professional programmers. As a result, a wide variety of C compilers and helpful accessories are available.
  • C is a portable language. Portable means that a C program written for one computer system (an IBM PC, for example) can be compiled and run on another system (MAC system, perhaps) with little or no modification. Portability is enhanced by the ANSI standard for C, the set of rules for C compilers.
  • C is a language of few words, containing only a handful of terms, called keywords, which serve as the base on which the language's functionality is built. You might think that a language with more keywords (sometimes called reserved words) would be more powerful. This isn't true. As you program with C, you will find that it can be programmed to do any task.
  • C is modular. C code can be written in routines called functions. These functions can be reused in other applications or programs. By passing pieces of information to the functions, you can create useful, reusable code.
As these features show, C is an excellent choice for your first programming language. What about C++? You might have heard about C++ and the programming technique called object-oriented programming. Perhaps you're wondering what the differences are between C and C++ and whether you should be teaching yourself C++ instead of C.
Not to worry! C++ is a superset of C, which means that C++ contains everything C does, plus new additions for object-oriented programming. If you do go on to learn C++, almost everything you learn about C will still apply to the C++ superset. In learning C, you are not only learning one of today's most powerful and popular programming languages, but you are also preparing yourself for object-oriented programming.
Another language that has gotten lots of attention is Java. Java, like C++, is based on C. If later you decide to learn Java, you will find that almost everything you learned about C can be applied.
Preparing to Program
You should take certain steps when you're solving a problem. First, you must define the problem. If you don't know what the problem is, you can't find a solution! Once you know what the problem is, you can devise a plan to fix it. Once you have a plan, you can usually implement it. Once the plan is implemented, you must test the results to see whether the problem is solved. This same logic can be applied to many other areas, including programming.
When creating a program in C (or for that matter, a computer program in any language), you should follow a similar sequence of steps:
1. Determine the objective(s) of the program.
2. Determine the methods you want to use in writing the program.
3. Create the program to solve the problem.
4. Run the program to see the results.
As an example, assume that someone asks you to write a program to determine the area inside a circle. Step 1 is complete, because you know your objective: determine the area inside a circle. Step 2 is to determine what you need to know to ascertain the area. In this example, assume that the user of the program will provide the radius of the circle. Knowing this, you can apply the formula pr2 to obtain the answer. Now you have the pieces you need, so you can continue to steps 3 and 4, which are called the Program Development Cycle.

The Program Development Cycle

The Program Development Cycle has its own steps.
1.  In the first step, you use an editor to create your source code.
2.  In the second step, you compile the source code to create an object file.
3.  In the third step, you link the compiled code to create an executable file.
4.  The fourth step is to run the program to see whether it works as originally planned.
When you save a source file, you must give it a name. The name should describe what the program does. In addition, when you save C program source files, give the file a “.C extension”. Although you could give your source file any name and extension, .C is recognized as the appropriate extension to use.

Compiling the Source Code

Although you might be able to understand C source code, your computer can't. A computer requires digital, or binary, instructions in what is called machine language. Before your C program can run on a computer, it must be translated from source code to machine language. This translation, the second step in program development, is performed by a program called a compiler. The compiler takes your source code file as input and produces a disk file containing the machine language instructions that correspond to your source code statements.

Linking to Create an Executable File

One more step is required before you can run your program. Part of the C language is a function library that contains object code (code that has already been compiled) for predefined functions. A predefined function contains C code that has already been written and is supplied in a ready-to-use form with your compiler package.
The printf() function used in the previous example is a library function. These library functions perform frequently needed tasks, such as displaying information on-screen and reading data from disk files.

Completing the Development Cycle

Once your program is compiled and linked to create an executable file, you can run it by entering its name at the system prompt or just like you would run any other program. If you run the program and receive results different from what you thought you would, you need to go back to the first step. You must identify what caused the problem and correct it in the source code. When you make a change to the source code, you need to recompile and relink the program to create a corrected version of the executable file. You keep following this cycle until you get the program to execute exactly as you intended.
The Components of a C Program

Your First C Program

This program displays the words Hello, World! on-screen.
#include <stdio.h>
main()
  {
     printf("Hello, World!\n");
  }

The Program's Components

#include

The #include directive instructs the C compiler to add the contents of an include file into your program during compilation. An include file is a separate disk file that contains information needed by your program or the compiler. Several of these files (sometimes called header files) are supplied with your compiler. You never need to modify the information in these files; that's why they're kept separate from your source code. Include files should all have an .H extension (for example, STDIO.H).

 

main()

The only component that is required in every C program is the main() function. In its simplest form, the main() function consists of the name main followed by a pair of empty parentheses (()) and a pair of braces ({}). Within the braces are statements that make up the main body of the program. Under normal circumstances, program execution starts at the first statement in main() and terminates at the last statement in main().

 

printf()

The printf() statement is a library function that displays information on-screen. The printf() statement can display a simple text message or a message and the value of one or more program variables.

 

Braces

You use braces ({}) to enclose the program lines that make up every C function--including the main() function. A group of one or more statements enclosed within braces is called a block. C has many uses for blocks.

 

A Short C Program

 

This is a very simple program. All it does is input two numbers from the keyboard and calculate their product.
1:  /* Program to calculate the product of two numbers. */
2:  #include <stdio.h>
3:
4:  int a,b,c;
5:
6:  main()            
7:  {              
8:     /* Input the first number */              
9:     printf("Enter a number between 1 and 100: ");              
10:     scanf("%i", &a);                 
11:
12:     /* Input the second number */                 
13:     printf("Enter another number between 1 and 100: ");              
14:     scanf("%i", &b);          
15:
16:     /* Calculate and display the product */                
17:     c = a*b;             
18:     printf ("%i times %i = %i\n", a, b, c);               
19:
20:     
21: }

Program Comments (Lines 1, 8, 12, and 16)

Any part of your program that starts with /* and ends with */ is called a comment. The compiler ignores all comments, so they have absolutely no effect on how a program works. You can put anything you want into a comment, and it won't modify the way your program operates. A comment can span part of a line, an entire line, or multiple lines. Here is an example:
/* A single-line comment */
int a,b,c; /* A partial-line comment */

The Variable Definition (Line 4)

A variable is a name assigned to a data storage location. Your program uses variables to store various kinds of data during program execution. In C, a variable must be defined before it can be used. A variable definition informs the compiler of the variable's name and the type of data it is to hold. In the sample program, the definition on line 4, int a,b,c;, defines three variables--named a, b, and c--that will each hold an integer value.

scanf()

The scanf() statement (lines 10 and 14) is another library function. It reads data from the keyboard and assigns that data to one or more program variables.