Sunday, 16 March 2014

RDBMS Introduction

RDBMS  stands for Relational Database Management System. It is the basis of SQL  and is used in all the modern database systems. A RDBMS is basically a DBMS(Database Management System )that maintains records between the tables and is based on the Relational Model by E.F. Codd.
Table:
The data in database is stored in the form of database objects known as tables. Table consist of rows and columns . It is a collection of related data items.
Emp_Id
Name
Age
Dept
01
Gpsingh
20
Programming
02
Mpsingh
19
Web desiging
Field: Field is nothing just the columns of the table. In the above table Emp_Id, Name,Age,Dept are the fields of the table.
Row: A row is also called as a record or the row of data.  A row can consist of data of different datatypes. The data in the row can have values of different fields of different datatypes . Following is a simple row from the above table.
01
Gpsingh
20
Programming

Column:

A column is a vertical entity in a table that contain all the information of the data of a specific data type. Each column has its own data type and it can store data of that particular datatype only.
Following is the example of a column from the above table        
Name
Gpsingh
Mpsingh

 

Null Value:

A null value means a value that appears blank in the database. The null value is different from the zero value or blank spaces. The zero value or blank spaces are themselves value but a null value measn that there is no value and that field in database is blank.

SQL Constraints:

Constrains means the rules that are enforced on the columns of the table. When inserting values in the database these constraints are checked to validate the entries to be stored in the database. The main benefit of constraints is that they enforce the accuracy and reliability of the database.

Types of constraints:

1.       Column Level Constraints
2.       Table Level Constraints

 Commonly used constraints in SQL:

Constraint
Purpose
NOT NULL Constraint
Ensures that a column cannot have NULL value.
DEFAULT Constraint
Provides a default value for a column when none is specified.
UNIQUE Constraint
Ensures that all values in a column are different
PRIMARY Key
Uniquely identified each rows/records in a database table.
FOREIGN Key
: Uniquely identified a rows/records in any another database table.
CHECK Constraint
The CHECK constraint ensures that all values in a column satisfy certain conditions.
INDEX
Use to create and retrieve data from the database very quickly
:

Categories of Data Integrity:

1.     Entity Integrity : It means that there cannot be any duplicate row in the table having values of all the fields same as that of some other row in the same table.
2.     Domain Integrity : Its main focus is to check for that valid data. The data to be entered in some field may be required in some range. Eg: for applying for a vacancy of a job the date of birth may be required between required within in the two yeas rangle.
3.     Referential Integrity : The rows that are being used by some other records cannot be deleted. The value of the records may be dependent on that record. So, Until the dependency exist the records cannot be deleted.
4.     User-Defined Integrity : Enforces some specific business rules that do not fall into entity, domain, or referential integrity

Wednesday, 29 January 2014

SQL Introduction

What is SQL?
SQL is Structured Query Language, which is used for storing, manipulating and retrieving data stored in relational database.
SQL is the standard language for Relation Database System.Examples: MySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server all use SQL .

Why to use SQL?

SQL allows users to access data in relational DBMS it allows users to describe the data.along with that users can define the data in database and manipulate the data according to their requirement and can perform various operations according to their need..More over users can embed SQL within other languages using SQL modules, libraries & pre-compilers and the most basic thing users can create and drop databases and tables as per required using simple queries. It is also possible to create views, stored procedures and functions in the database for better efficiency and proper utilization of the database. The queries like simple to learn and you will easily learn them as go proceed in this tutorial
SQL command Execution Process:
SQL Execution Process
SQL Execution Process

While executing an SQL command the SQL Engine decides how to interpret the task.

Components included in the process:

Query Dispatcher, Optimization Engines, Classic Query Engine and SQL Query Engine

Types of SQL Commands:

1.       DDL - Data Definition Language
2.       DML - Data Manipulation Language:
3.       DCL - Data Control Language:
4.       DQL - Data Query Language:
4.

DDL - Data Definition Language


Command
Description
CREATE
Creates a new table, a view of a table, or other object in database
ALTER
Modifies an existing database object, such as a table
DROP
Deletes an entire table, a view of a table or other object in the database

DML - Data Manipulation Language

Command
Description
INSERT
Creates new records in the database
UPDATE
Updates existing records in the database
DELETE
Deletes a record from the database

DCL - Data Control Language:

Command
Description
GRANT
Used to grant privileges to a user
REVOKE
Used to revoke privileges from a user

DQL - Data Query Language:

Command
Description
SELECT
Retrives certain records from one or more tables in the database

Friday, 1 November 2013

Hierarchical Inheritance

In hierarchical  inheritance, one class is extended by many subclasses. It is one-to-many relationship.
 In the following example there are two child classes that inherit the same base class "Hinh" and in the main class, objects of both the child classes are created that call the respective functions. Both the child functions call the functions defined in their body and the function of the base class.

Program for Hierarchical Inheritance

import java.io.*;
class Hinh
{
void fun_hinh()
{
System.out.println("Function of hinh class");
}
}

class Childone extends Hinh
{
void fun_childone()
{
System.out.println("Function of childone class");
}
}

class Childtwo extends Hinh
{
void fun_childtwo()
{
System.out.println("Function of childtwo class");
}
}

public class Main_class
{
public static void main(String arg[])
{
Childone ch1=new Childone();
ch1.fun_hinh();
ch1.fun_childone();
Childtwo ch2=new Childtwo();
ch2.fun_hinh();
ch2.fun_childtwo();
}
}


Output:


Sunday, 18 August 2013

C++ program without main

 Yes, the following program runs perfectly fine even without a main function. But how, whats the logic behind it? How can we have a C program working without main?
Here we are using preprocessor directive #define with arguments to give an impression that the program runs without main. But in reality it runs with a hidden main function.
The ‘##‘ operator is called the token pasting or token merging operator. That is we can merge two or more characters with it.

Look at the 2nd line of program -
#define decode(s,t,u,m,p,e,d) m##s##u##t
What is the preprocessor doing here. The macro decode(s,t,u,m,p,e,d) is being expanded as “msut” (The ## operator merges m,s,u & t into msut). The logic is when you pass (s,t,u,m,p,e,d) as argument it merges the 4th,1st,3rd & the 2nd characters(tokens).

Now look at the third line of the program -
#define begin decode(a,n,i,m,a,t,e)

Here the preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e). According to the macro definition in the previous line the argument must be expanded so that the 4th,1st,3rd & the 2nd characters must be merged. In the argument (a,n,i,m,a,t,e) 4th,1st,3rd & the 2nd characters are ‘m’,'a’,'i’ & ‘n’.
So the third line “int begin” is replaced by “int main” by the preprocessor before the program is passed on for the compiler. That’s it…

The bottom line is there can never exist a C program without a main function. Here we are just playing a gimmick that makes us beleive the program runs without main function, but actually there exists a hidden main function in the program. Here we are using the proprocessor directive to intelligently replace the word begin” by “main”. In simple words int begin=int main.

Following is a program to run a c++ program without main() :





Output:




Saturday, 17 August 2013

Primitive Data types

data type informs the compiler what type of data a variable is permitted to store. Data type should also be declared when a variable s declared.

Declaring a data type:     datatypename  variablename

 Java as Java is a strongly typed language The data type indicates what type of values that variable can store and possible operations that can be performed. The language system allocates memory to the variable on the type of data it can hold like an integer or double etc. 
String in Java is not a data type. String is a class from java.lang package. String is not a keyword; Strings are used very often in coding like data types.
Java supports 8 data types that can be divided into 4 broad categories.
All data types are keywords. As a rule, all keywords should be written in lowercase. Java does not support unsigned data types; every data type is implicitly signed (except char). "unsigned" is not a keyword of Java. Note that nulltrue and false are also not keywords.



  • Whole numbers – byteshortintlong
  • Floating-point numbers – floatdouble
  • Character values – char
  • Boolean values – boolean
























  • Friday, 16 August 2013

    Drawing animated circle



    The program is to draw an animated circle in computer graphics . The header file used for using graphics in C code is     #include<graphics.h>  , This  graphics functions are included in this header file. The functions like circle, rectangle, arc, eclipse etc all are included in the graphics header file. It is required to declare this header file in the beginning of the program to use these inbuilt functions. The graphics need to be initialized after the main function is defined .The graphics are initialized using initgraph function.In initgraph function the path of the BGI directory is given .

    Program to draw an animated circle

    #include<iostream.h>
    #include<conio.h>
    #include<graphics.h>
    void main()
    {
    int gd=DETECT,gm;
    int x,y;
    initgraph(&gd,&gm,"c:/tc/bgi");
    setbkcolor(RED);
    x=getmaxx()/2;
    y=getmaxy()/2;

    while(!kbhit())
    {
    for(int i=1;i<=15;i++)
    {
    for(int p=400;p>=1;p--)

    {
    circle(x,y,p);
    }
    setcolor(i+2);
    for(int r=1;r<400;r++)
    {
    circle(x,y,r);
    }
    }
    }
    getch();
    }

    Monday, 17 June 2013

    Exception Handling

    http://howtodoinjava.com/wp-content/uploads/ExceptionHierarchyJava.png
    Exception Handling

    Exception handling:

    In programming languages,some time our program compile successfullybut failed to execute program, such type of error interrupt program and runtime environment of language automatically throw appropriate exception. In such a case rest of the programdoesnot execute. If we want to execute rest of the program it gives an error message,then they hav to handle exception which is thrown by runtime environmen of the language, and the technique used to handle runtime error is called exception handling.

    There are two types of exception classes:
    1 Built in exception classes.
    2 User defined exception classes.

    There are 5 reserved keyword which help to handle runtime error:
    1 try
    2 catch
    3 throw
    4 throws
    5 finally

    1 try :  It is used where chances of runtime error are there. Runtime environment automatically detect type of error and throw object of appropriate exception class.
            Syntax:        
               try
            {
           The code that may generate an exception is placed in this block.
             }

    2 catch : A exception which is thrown by try block must be brought either in catch block or finally block.

            Syntax:            
             catch(Exception_name objectname)
         {
                  Statements/ error to display to user when exception occour.
    }


    3 throw: When ever a exception occour throw block throws the exception to the catch block. Each exception that occour must be caught, the type of exception generated is catched by the catch block of that particluar exception, catch block is declared below the try block.

               Syntax:    
                       try
                  {
                  The code that may generate an exception is placed in this block.
                    }
                      catch(Exception_name objectname)
                 {
                      Statements/ error to display to user when exception occour.
                    }  

    4 throws: throws keyword gives a method flexibility of throwing an Exception rather than handling it. with throws keyword in method


    5 finally : execute in every situation even the exception occour or not.finally create a block of code that will be executed afetr a try catch block completed and before the code following try catch block. If an exception is thrown finally block will execute eve if no catch satement matches exception.

    full details in json
    Proudly Powered by Blogger.
    back to top