Translate

Saturday, 16 December 2017

We count 35 heads and 94 legs among the chickens and rabbits in a farm. How many rabbits and how many chickens do we have?


public class ChickenAndRabbits
{
public static void main(String arga[])
{
int a=35;
int b=94;
int c=a*2;
int d=(b-c)/2;
System.out.println("RABBITS :"+d);
int e=a-d;
System.out.println("CHICKENS :+e);
}
}


OUTPUT

RABBITS 12
CHICKENS 23


Sunday, 10 December 2017

java program area

import java.util.Scanner;

public class Parallelogram

{

    public static void main(String[] args) 

    {

        int a, b,area;

        Scanner s = new Scanner(System.in);

        System.out.print("Enter the base of parallelogram:");

        a = s.nextInt();

        System.out.print("Enter the height of the parallelogram:");

        b = s.nextInt();

        area = a * b;

        System.out.println("Area of parallelogram:"+area);

    }

}


Output:


Enter the base of parallelogram:5

Enter the height of the parallelogram:6

Area of parallelogram:30

Pattern in Java

      Pattern in Java

class NumberPattern

{

 public static void main(String[] args) 

 {

 for (int i = 1; i <= 5; i++) 

 {

 for (int j = 1; j <= i; j++)

 {

 System.out.print(j+" ");

 }

 System.out.println();

 }

 }

}

 

                 User code 


import java.util.Scanner;

 

public class MainClass

{

    public static void main(String[] args) 

    {

        Scanner sc = new Scanner(System.in);

         

        //Taking rows value from the user

         

        System.out.println("How many rows you want in this pattern?");

         

        int rows = sc.nextInt();

         

        System.out.println("Here is your pattern....!!!");

         

        for (int i = 1; i <= rows; i++) 

        {

            for (int j = 1; j <= i; j++)

            {

                System.out.print(j+" ");

            }

             

            System.out.println();

        }

         

        //Close the resources

         

        sc.close();

    }

}


                 Output 



1 2 

1 2 3 

1 2 3 4 

1 2 3 4 5

Wednesday, 22 November 2017

font in css

<!DOCTYPE html>

<html>


<head>

  <title>List Style</title>

  <style>

  .ul1 {

    list-style-type: circle;

  }

  

  .ul2 {

    list-style-type: square;

  }

  

  .ol1 {

    list-style-type: upper-roman;

  }

  

  .ol2 {

    list-style-type: lower-alpha;

  }

  </style>

</head>


<body>


  <p>Example of unordered lists:</p>

  <ul class="ul1">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ul>


  <ul class="ul2">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ul>


  <p>Example of ordered lists:</p>

  <ol class="ol1">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ol>


  <ol class="ol2">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ol>  <ol class="ol2">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ol>


</body>


</html>




List Style css

<!DOCTYPE html>

<html>


<head>

  <title>List Style</title>

  <style>

  .ul1 {

    list-style-type: circle;

  }

  

  .ul2 {

    list-style-type: square;

  }

  

  .ol1 {

    list-style-type: upper-roman;

  }

  

  .ol2 {

    list-style-type: lower-alpha;

  }

  </style>

</head>


<body>


  <p>Example of unordered lists:</p>

  <ul class="ul1">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ul>


  <ul class="ul2">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ul>


  <p>Example of ordered lists:</p>

  <ol class="ol1">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ol>


  <ol class="ol2">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ol>  <ol class="ol2">

    <li>Coffee</li>

    <li>Tea</li>

    <li>Coca Cola</li>

  </ol>


</body>


</html>




Saturday, 18 November 2017

text and background color css

<!DOCTYPE html>

<html>


<head>

  <title>Background and text color</title>

  <style>

  .clr_cls {

    background-color: red;

    color: yellow;

  }

  </style>

</head>


<body>

  <div class="clr_cls">

    Mafasict

  </div>


</body>


</html>

Friday, 17 November 2017

Java while loop example



While Loop Example


import java.util.Scanner;


class WhileLoop {

public static void main(String[] args) {

int n;


Scanner input = new Scanner(System.in);

System.out.println("Input an integer"); 


while ((n = input.nextInt()) != 0) {

System.out.println("You entered " + n);

System.out.println("Input an integer");

}


System.out.println("Out of loop");

}

}


Input an integer

7

You entered 7

Input an integer

-2

You entered -2

Input an integer

9546

You entered 9546

Input an inte

ger 0

Out of loop


Wednesday, 15 November 2017

Java 1st program

First Program


class Simple {

public static void main (string args []) {

System.out.println ("Hello Java");

}

}


save this file as Simple.java

To compile: javac Simple.java

To execute: java Simple

It will give output as Hello Java


Let's see what this is:

class keyword is used to declare a class in java.


Public keyword is an access modifier which represents visibility, it means it is visible to all.


static is a keyword, if we declare any method as static, it is known as static method. The main method is executed by the JVM, it does not require the object to invoke the main method. So it saves memory.


The void is the return type of method, it means it does not return any value.


main is a entry point of the program. Execution of programs starts from main. It is called by Runtime System


String [] args is used for command line argument. We will learn it later.


System.out.println () is used print statement.

Monday, 13 November 2017

Java switch statement




5.2 Switch statement

A switch statement is used instead of nested if...else statements. It is multiple branch decision statement.
A switch statement tests a variable with list of values for equivalence. Each value is called a case. The case value must be a constant i.

SYNTAX
switch(expression){
case constant:
//sequence of optional statements
break; //optional
case constant:
//sequence of optional statements
break; //optional
.
.
.
default : //optional
//sequence of optional statements
}


Individual case keyword and a semi-colon (:) is used for each constant.
Switch tool is used for skipping to particular case, after jumping to that case it will execute all statements from cases beneath that case this is called as ''Fall Through''.

In the example below, for example, if the value 2 is entered, then the program will print two one something else!

switch(i)
{
case 4: System.out.println(''four'');
break;
case 3: System.out.println(''three'');
break;
case 2: System.out.println(''two'');
case 1: System.out.println(''one'');
default: System.out.println(''something else!'');
}

To avoid fall through, the break statements are necessary to exit the switch.
If value 4 is entered, then in case 4 it will just print four and ends the switch.

The default label is non-compulsory, It is used for cases that are not present.


Sunday, 12 November 2017

java if statement



5.1 If statement


if statement

An if statement contains a Boolean expression and block of statements enclosed within braces.


if(conditional expression)

//statement or compound statement;

else 

//optional

//statement or compound statement; 

//optional


If the Boolean expression is true then statement block is executed otherwise (if false) program directly goes to next statement without executing Statement block.


if....else

If statement block with else statement is known as as if...else statement. Else portion is non-compulsory.


if ( condition_one ) 

{

//statements

}

else if ( condition_two )

{

//statements

}

else

{

//statements

}


If the condition is true, then compiler will execute the if block of statements, if false then else block of statements will be executed.


nested if...else

when a series of decisions are involved, we may have to use more than one if...else statement in nested form as follows:


if(test condition1)

{

if(test condition2)

{

//statement1;

}

else

{

//statement2;


}

}

else

{

//statement3;

}

//statement x;


Java program operator



4.1 Operators


Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

- Arithmetic Operators

- Relational Operators

- Bitwise Operators

- Logical Operators

- Assignment Operators

- Misc Operators


Arithmetic Operators:

Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra.

arithmetic operators:

+ Additive operator (also used for String concatenation)

- Subtraction operator

* Multiplication operator

/ Division operator

% Remainder operator


Relational Operators:

There are following relational operators supported by Java language

> Greater than

< Less than

== Equal to

!= Not equal to

>= Greater than or equal to

<= Less than or equal to


Bitwise Operators:

Java defines several bitwise operators, which can be applied to the integer types, long, int, short, char, and byte.

Bitwise operator works on bits and performs bit-by-bit operation. 


~ Unary bitwise complement

<< Signed left shift

>> Signed right shift

>>> Unsigned right shift & Bitwise AND

^ Bitwise exclusive OR

| Bitwise inclusive OR


Logical Operators:

The following table lists the logical operators:

&& Conditional-AND

|| Conditional-OR

?: Ternary (shorthand for if-then-else statement)


Assignment Operators:

There are following assignment operators supported by Java language:

= Simple assignment operator

+= Add AND assignment operator

-= Subtract AND assignment operator

*= Multiply AND assignment operator

/= Divide AND assignment operator

%= Modulus AND assignment operator

<<= Left shift AND assignment operator.

>>= Right shift AND assignment operator

&= Bitwise AND assignment operator.

^= bitwise exclusive OR and assignment operator.

|= bitwise inclusive OR and assignment operator.


Increment and Decrement Operators

Increment and decrement operators are used to add or subtract 1 from the current value of oprand.

++ increment

-- decrement


Increment and Decrement operators can be prefix or postfix. 

In the prefix style the value of oprand is changed before the result of expression and in the postfix style the variable is modified after result.


For eg.

a = 9;

b = a++ + 5;

/* a=10 b=14 */


a = 9;

b = ++a + 5;

/* a=10 b=15 */


Miscellaneous Operators

There are few other operators supported by Java Language.

Conditional Operator ( ? : )

Conditional operator is also known as the ternary operator.

The operator is written as:

variable x = (expression) ? value if true : value if false


Instance of Operator:

This operator is used only for object reference variables.

instanceof oper

ator is wriiten as:

( Object reference variable ) instanceof (class/interface type)


Java data types



3.2 Data type


Every variable in Java has a data type. Data types specify the size and type of values that can be stored.

Data types in Java divided primarily in two tyeps: 

Primitive(intrinsic) and Non-primitive.


Primitive types contains Integer, Floating points, Characters, Booleans And Non-primitive types contains Classes, Interface and Arrays.


Integer:This group includes byte, short, int and long, which are whole signed numbers.

Floating-point Numbers: This group includes float and double, which represent number with fraction precision.

Characters: This group includes char, which represents character set like letters and number

Boolean: This group includes Boolean, which is special type of representation of true or false value.


Some data types with their range and size:

byte: -128 to 127 (1 byte)


short: -32,768 to +32,767 (2 bytes)


int: -2,147,483,648 to +2,147,483,647 (4 bytes)


float: 3.4e-038 to 1.7e+0.38 (4 bytes)


double: 3.4e-038 to 1.7e+308 (8 bytes)


char : holds only a single character(2 bytes)


boolean : can take only

 true or false (1 bytes)


Java program variables



3.1 Variables


A variable provides us with named storage that our programs can manipulate. 

Each variable in Java has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.


You must declare all variables before they can be used. 

The basic form of a variable declaration is shown here:

data_type variable = value;


Here data type is one of Java's datatypes and variable is the name of the variable. To declare more than one variable of the specified type, you can use a comma-separated list.


Following are valid examples of variable declaration and initialization in Java:

int a, b, c;

// Declares three ints, a, b, and c.


int a = 10, b = 10;

// Example of initialization


double pi = 3.14159;

// declares and assigns a value of PI.


char a = 'a';

// the char variable a iis initialized with value 'a'


Constant: During the execution of program, value of variable may change. A constant represents permanent data that never changes. 


If you want use some value likes p=3.14159; no need to type every time instead you can simply define constant for p, following is the syntax for declaring constant.

Static final datatype ConstantName = value;


Example: stat

ic final float PI=3.14159; 


Java program features



1.2 Features


1. Simple

Java is easy to learn and its syntax is quite simple and easy to understand.


2. Object-Oriented

In java everything is Object which has some data and behaviour. Java can be easily extended as it is based on Object Model.


3. Platform independent

Unlike other programming languages such as C, C++ etc which are compiled into platform specific machines. Java is guaranteed to be write-once, run-anywhere language.


On compilation Java program is compiled into bytecode. This bytecode is platform independent and can be run on any machine, plus this bytecode format also provide security. Any machine with Java Runtime Environment can run Java Programs.


4. Secured

When it comes to security, Java is always the first choice. With java secure features it enable us to develop virus free, temper free system. Java program always runs in Java runtime environment with almost null interaction with system OS, hence it is more secure.


5. Robust

Java makes an effort to eliminate error prone codes by emphasizing mainly on compile time error checking and runtime checking. But the main areas which Java improved were Memory Management and mishandled Exceptions by introducing automatic Garbage Collector and Exception Handling.


6. Architecture neutral

Compiler generates bytecodes, which have nothing to do with a particular computer architecture, hence a Java program is easy to intrepret on any machine.


7. Portable

Java Bytecode can be carried to any platform. No implementation dependent features. Everything related to storage is predefined, example: size of primitive data types 


8. High Performance

Java is an interpreted language, so it will never be as fast as a compiled language like C or C++. But, Java enables high performance with the use of just-in-time compiler.


9. Multithreaded

Java multithreading feature makes it possible to write program that can do many tasks simultaneously. Benefit of multithreading is that it utilizes same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along.


10. Distributed

We can create distributed applications in java. RMI and EJB are used for creating distributed applications. We may access files by calling the methods from any machine on the internet.


11. Interpreted

An interpreter is needed in order to run Java programs. The programs are compiled into Java Virtual Machine code called bytecode. The bytecode is machine independent and is able to run on any machine that has a Java interpreter. With Java, the program need only be compiled once, and the bytecode generated by the Java c

ompiler can run on any platform. 


introduction Java




1.1 Introduction

Java is a simple and yet powerful object oriented programming language and it is in many respects similar to C++.

Java is created by James Gosling from Sun Microsystems (Sun) in 1991. The first publicly available version of Java (Java 1.0) was released in 1995.

Java is defined by a specification and consists of a programming language, a compiler, core libraries and a runtime machine(Java virtual machine).
The Java runtime allows software developers to write program code in other languages than the Java programming language which still runs on the Java virtual machine.
The Java platform is usually associated with the Java virtual machine and the Java core libraries.

Java virtual machine
The Java virtual machine (JVM) is a software implementation of a computer that executes programs like a real machine.

Java Runtime Environment vs. Java Development Kit
A Java distribution typically comes in two flavors, the Java Runtime Environment (JRE) and the Java Development Kit (JDK).
The JRE consists of the JVM and the Java class libraries. Those contain the necessary functionality to start Java programs.
The JDK additionally contains the development tools necessary to create Java programs. The JDK therefore consists of a Java compiler, the Java virtual machine and the Java class libraries.

Uses of JAVA
Java is also used as the programming language for many different software programs, games, and add-ons.

Some examples of the more widely used programs written in Java or that use Java include the Android apps, Big Data Technologies, Adobe Creative suite, Eclipse, Lotus Notes, Minecraft, OpenOffice, Runescape, and Vuze.


Friday, 10 November 2017

java basic


             JAVA PROGRAM

Object oriented and cant write procedural programs
Functions are called methods
Unit of a program is the class from which objects are created
Automatic garbage collection
Singleinheritance only
Each class contains data and methods which are used to manipulate the data
Programs are small and portable
Multithreaded which allows several operations to be executed concurrently
A rich set of classes and methods are available in java class libraries
Platform Independent
Case sensitive

java program development

* Edit –use any editor
* Compile –use command ‘javac’ if your program compiles correctly, will create a file with extension .class
* Execute –use the command ‘java’

java language keyword

Keywords are special reserved words in java that you cannot use as identifiers for classes, methods or variables. They have meaning to the compiler, it uses them to understand what your source code is trying to do.

first Java program

class FirstPro {
public static void main(String args[])
{
System.out.println("Hello World!“);
}
}

java source files

 All java source files must end with the extension ‘.java’
Generally contain at most one top level public class definition
If a public class is present, the class name should match the file name

top level elevents appears in a file

If these are present then they must appear in the following order.
Package declarations
Import statements
Class definitions

identifiers

An identifier is a word used by a programmer to name a variable, method class or label.
Keywords may not be used as an identifier
Must begin with a letter, a dollar sign($) or an underscore( _ ).
Subsequent character may be letters, digits, _ or $.
Cannot include white spaces.

declering


Sunday, 5 November 2017

ms access short question answer

MS ACCESS 

1) What is  Database  Management System  (DBMS)?
 *computer  Software  to  manage, maintain  database  as  well  as  view  update and  retrieve  data  is  called  database management  system.

 2)What do you mean by  data processing? 
*The  term  data  processing  embraces  the technique  of  sorting,  relating,  interpreting and  computing  items  of  data  in  order  to provide  meaningful  and  useful  information. 

3) List  some database applications.
* Some  of  the  popular  database  management systems  are:  Oracle,  Sybase,  MS  Access,  MS SQL  Server,  Paradox,  DB/2,  Dbase,  FoxPro, MySql 

4) What is  MS-Access?
* MS-Access  is  a  RDBMS  (Relational  Database Management  System)  application  developed by  Microsoft  Inc.  that  runs  on  Windows operating  System.   

5) What is  Database?
* A  database  is  an  organization  of  data  related to  a  particular  subject  or  purpose  so  that  the data  can  be  retrieved or  processed. 

6) What is  the extension of  Access database file? 
*The  extension  of  MS-Access  data  file  is  MDB. 

7) What is relational database? 
*A database with tables related to each other on a common field to facilitate the data retrieval from multiple tables is known as relational database. 

8) What is a key field?
* A common field on which two tables are linked is known as key field. 

9) What is primary key?
* A primary key is a rule which ensures that unique data is entered for the field and the field is not left blank. This is the field that would indentify a record uniquely in table

10)  What do you mean by foreign key? 
*The common field in child table that maintains relation with master table is foreign key. 

11) What are the elements of a database?  
*The major six elements of a database are   Tables, Queries, Form, Reports, Macros, Modules

12) What is a table? 
*A table is a collection of data about a specific topic such as products, students or suppliers. A table organizes data into columns (fields) and rows (records or tuples)

13) What is  a field? 
*A  field  in  a  database  is  a  piece  of  information  about  a  subject. Each  field  is  arranged  as  a  column in  table.

14) What is  a record?
* A  record  is  complete  information  about  a  subject.  A  record  is  a  collection  of  fields  and presented  as  a  row  in  a  table  of  database. 

15) What is  a query?
* A  query  is  a  question  about  data  in  database.  It  results  a  set  of  data  from  database  that  can  be used  as  a  source  of  records  for  reports  and  forms. 

16) What is  a form? 
*Entering  and  viewing  data  directly  on  the database  table  is  not  always  convenient.  So,  a form  is  created  to  facilitate  easy  entering  data and  created  that  retrieve  records  from  a  single table  or  from  multiple  tables.

17) What is  a  report? A  report  is  an  object  in  MS-Access  that  is  used to  view  and  print  data.  Though  a  Report  is similar  to  a  form;  its  specialty  lies  in  special features  like  help  to  summarize  data. 

18) What are  the differences between a form and a  report? *Forms  are  primarily  used  to  edit  overview  data whereas  reports  are  used  primarily  to  print  or view  data. In  a  form  your  usually navigate  from  one  record to  another,  whereas  in  reports  summarized data  are  possible  to  present. 

19) What is  a macro? 
*A  macro  is  an  object  in  MS-Access  that  is  used to  execute  one  or  more  database  commands automatically.  Macros  are  useful  in  tasks  such as  printing  month-end  reports,  adding  new record  to  a  table,  printing  letters  to  customers periodically. 

20) What is  a module?
* A  module  object  in  Access  is  a  program  written using  VBA  (Visual  Basic  for  Application)  to automate  and  customize  database  function. 

Tuesday, 31 October 2017

link tag


<!DOCTYPE html>
<html>

<head>
  <title>Link in HTML</title>
</head>

<body>

  <a href="http://www.mafasict.blogspot.com">mafasict</a>


</body>

</html>

check box


<!DOCTYPE html>
<html>

<head>
  <title>Check Box</title>
</head>

<body>


  <input type="checkbox" name="subject">Maths

  <input type="checkbox" name="subject">Ict

</body>

</html>

radio button


<!DOCTYPE html>
<html>

<head>
  <title>Radio Button </title>
</head>

<body>


    <input type="radio" name="gndr">Male

   
 
    <input type="radio" name="gndr">FeMale
 

</body>

</html>

Monday, 30 October 2017

input button tag


<!DOCTYPE html>
<html>

<head>
  <title>Input Button</title>
</head>

<body>

  <input type="button" value="Click Me">

</body>

</html>

text area


<!DOCTYPE html>
<html>

<head>
  <title>Text Area</title>
</head>

<body>

  <textarea cols="5" rows="5">Colombo,srilanka</textarea>

</body>

</html>

password tag


<!DOCTYPE html>
<html>

<head>
  <title>password</title>
</head>

<body>

  Username:
  <input type="text">
  <br> Password :
  <input type="password">

</body>

</html>

text box


<!DOCTYPE html>
<html>

<head>
  <title>TextBox</title>
</head>

<body>

  <input type="text" value="12345" size="5" maxlength="3">

</body>

</html>

center tag


<!DOCTYPE html>
<html>

<head>
  <title>Center tag</title>
</head>

<body>

  <center>This is the text display in center</center>

</body>

</html>

pre tag


<!DOCTYPE html>
<html>

<head>
  <title>Pre Tag</title>
</head>

<body>

  <pre>
H
 A
  V
   E
    A
     N
      I
      C
     E
    D
   A
 Y
  </pre>
  <br>
  <!--No Pre Tag-->
H
 A
  V
   E
    A
     N
      I
      C
     E
    D
   A
 Y

</body>

</html>

var tag


<!DOCTYPE html>
<html>

<head>
  <title>var Tag</title>
</head>

<body>

  var tag is defined mathamatical variable.
  <br>
  <var>(a+b)<sup>2</sup></var>=<var>a</var><sup>2</sup>+<var>b</var><sup>2</sup>+<var>2ab</var>

</body>

</html>

address tag


<!DOCTYPE html>
<html>

<head>
  <title>Address</title>
</head>

<body>

  My Address is.
  <Address>
    Mafas,<br>
Brinthuraichenai,<br>
Valaichenai,<br>
Pin-629167,<br>
B.T.Dist.
  </Address>

</body>

</html>

Quotation tag HTML


<!DOCTYPE html>
<html>

<head>
  <title>Quotation</title>
</head>

<body>

  He said <q>This is too much.</q>

</body>

</html>

br tag


<!DOCTYPE html>
<html>

<head>
  <title>BR Tag</title>
</head>

<body>

  <!--Without BR Tag-->
  Line 1
  Line 2
  Line 3
  Line 4
  Line 5

  <!--With using BR Tag-->
  <br> Line 1
  <br> Line 2
  <br> Line 3
  <br> Line 4
  <br> Line 5

</body>

</html>

strong tag


<!DOCTYPE html>
<html>

<head>
  <title>Strong tag</title>
</head>

<body>

  This is the <strong>Strong Text</strong>

</body>

</html>

superscript tag


<!DOCTYPE html>
<html>

<head>
  <title>superscripted Text</title>
</head>

<body>

  This is the <sup>superscripted</sup> Text

</body>

</html>

subscriped tag


<!DOCTYPE html>
<html>

<head>
  <title>subscripted Text</title>
</head>

<body>

  This is the <sub>subscripted</sub> Text

</body>

</html>

delete tag HTML


<!DOCTYPE html>
<html>

<head>
  <title>Delete</title>
</head>

<body>

  This is the <del>Deleted Text</del>

</body>

</html>

mark tag


<!DOCTYPE html>
<html>

<head>
  <title>mark tag</title>
</head>

<body>

  Normal Text
  <br>
  mark <mark>This</mark> Text
 
</body>

</html>

small tag HTML


<!DOCTYPE html>
<html>

<head>
  <title>small tag</title>
</head>

<body>

  Normal Text<br>
  <small>small Text</small>
  <br>
  This is <small>small</small> Sample

</body>

</html>

div tag


<!DOCTYPE html>
<html>

<head>
  <title>div tag</title>
</head>

<body>

  <!--Div can be used to group elements-->
  <div>
    This is the First Div
    <input type="text">
    <input type="text">
    <input type="text">
  </div>

  <div>
    This is the Second Div
    <input type="text">
    <button>Sample Button</button>
  </div>

</body>

</html>

text formatting


<!DOCTYPE html>
<html>

<head>
  <title>Text Formatting</title>
</head>

<body>

  <b>Bold Text</b>
  <br>
  <i>Italic Text</i>
  <br>
  <u>UnderLine Text</u>
  <br>
  <b><u><i>This is the Mixed Line</i></u></b>

</body>

</html>



Horizontal Line size


<!DOCTYPE html>
<html>

<head>
  <title>Horizontal Line size</title>
</head>

<body>

  First Line
  <hr size="10px" color="red">
  Second Line
  <hr size="30px" color="green">
  Third Line
  <hr color="blue">

</body>

</html>



Horizontal Line color


<!DOCTYPE html>
<html>

<head>
  <title>Horizontal Line color</title>
</head>

<body>

  First Line
  <hr color="red">
  Second Line
  <hr color="green">
  Third Line
  <hr color="blue">

</body>

</html>



Horizontal Line html tag


<!DOCTYPE html>
<html>

<head>
  <title>Horizontal Line</title>
</head>

<body>

  First Line
  <hr>
  Second Line
  <hr>
  Third Line
  <hr>

</body>

</html>



paragraph tag


<!DOCTYPE html>
<html>

<head>
  <title>Paragraph Tag</title>
</head>

<body>

  <p>This is the First Paragraph starting</p>
  <p>This is the Second Paragraph starting</p>
  <p>This is the Fourth Paragraph starting</p>
  <p>This is the Fifth Paragraph starting</p>

</body>

</html>



1st HTML program


<!DOCTYPE html>
<html>

<head>
  <title>First HTML</title>
</head>

<body>

 Mafastech

</body>

</html>




Friday, 27 October 2017

DBMS - Normalization


DBMS - Normalization

Functional Dependency

Functional dependency (FD) is a set of constraints between two attributes in a relation. Functional dependency says that if two tuples have same values for attributes A1, A2,..., An, then those two tuples must have to have same values for attributes B1, B2, ..., Bn.

Functional dependency is represented by an arrow sign (→) that is, X→Y, where X functionally determines Y. The left-hand side attributes determine the values of attributes on the right-hand side.

Armstrong's Axioms

If F is a set of functional dependencies then the closure of F, denoted as F+, is the set of all functional dependencies logically implied by F. Armstrong's Axioms are a set of rules, that when applied repeatedly, generates a closure of functional dependencies.

Reflexive rule − If alpha is a set of attributes and beta is_subset_of alpha, then alpha holds beta.

Augmentation rule − If a → b holds and y is attribute set, then ay → by also holds. That is adding attributes in dependencies, does not change the basic dependencies.

Transitivity rule − Same as transitive rule in algebra, if a → b holds and b → c holds, then a → c also holds. a → b is called as a functionally that determines b.

Trivial Functional Dependency

Trivial − If a functional dependency (FD) X → Y holds, where Y is a subset of X, then it is called a trivial FD. Trivial FDs always hold.

Non-trivial − If an FD X → Y holds, where Y is not a subset of X, then it is called a non-trivial FD.

Completely non-trivial − If an FD X → Y holds, where x intersect Y = Φ, it is said to be a completely non-trivial FD.

Normalization

If a database design is not perfect, it may contain anomalies, which are like a bad dream for any database administrator. Managing a database with anomalies is next to impossible.

Update anomalies − If data items are scattered and are not linked to each other properly, then it could lead to strange situations. For example, when we try to update one data item having its copies scattered over several places, a few instances get updated properly while a few others are left with old values. Such instances leave the database in an inconsistent state.

Deletion anomalies − We tried to delete a record, but parts of it was left undeleted because of unawareness, the data is also saved somewhere else.

Insert anomalies − We tried to insert data in a record that does not exist at all.

Normalization is a method to remove all these anomalies and bring the database to a consistent state.

First Normal Form

First Normal Form is defined in the definition of relations (tables) itself. This rule defines that all the attributes in a relation must have atomic domains. The values in an atomic domain are indivisible units.

unorganized relation

We re-arrange the relation (table) as below, to convert it to First Normal Form.

Relation in 1NF

Each attribute must contain only a single value from its pre-defined domain.

Second Normal Form

Before we learn about the second normal form, we need to understand the following −

Prime attribute − An attribute, which is a part of the prime-key, is known as a prime attribute.

Non-prime attribute − An attribute, which is not a part of the prime-key, is said to be a non-prime attribute.

If we follow second normal form, then every non-prime attribute should be fully functionally dependent on prime key attribute. That is, if X → A holds, then there should not be any proper subset Y of X, for which Y → A also holds true.

Relation not in 2NF

We see here in Student_Project relation that the prime key attributes are Stu_ID and Proj_ID. According to the rule, non-key attributes, i.e. Stu_Name and Proj_Name must be dependent upon both and not on any of the prime key attribute individually. But we find that Stu_Name can be identified by Stu_ID and Proj_Name can be identified by Proj_ID independently. This is called partial dependency, which is not allowed in Second Normal Form.

Relation  in 2NF

We broke th

database users


Users of Database management system:-

1. Database administrators: responsible for authorizing access to the database, for coordinating and monitoring its use, acquiring software, and hardware resources, controlling its use and monitoring efficiency of operations.


2. Database Designers: Responsible to define the content, the structure, the constraints, and functions or transactions against the database. They must communicate with the end-users and understand their needs.


3. End users : End users are the people whose jobs require access to the database for querying, updating, and generating reports; the database primarily exists for their use. There are several categories of end users:

Casual  End User: access database occasionally when needed. But they may need different information each time.

Naïve or Parametric End user : they make up a large section of the end-user population. They use previously well-defined functions in the form of canned transactions” against the database. Examples are bank-tellers or reservation clerks who do this activity for an entire shift of operations.
                                                           
Sophisticated End User : These include business analysts, scientists, engineers, others thoroughly familiar with the system capabilities. Many use tools in the form of software packages that work closely with the stored database.

Stand-alone End User : Mostly maintain personal databases using ready-to-use packaged applications. An example is a tax program user that creates his or her own internal database.

function of dbms


The functions performed by a typical DBMS are the following:

1. Data Definition

The DBMS provides functions to define the structure of the data in the application. These include defining and modifying the record structure, the type and size of fields and the various constraints/conditions to be satisfied by the data in each field.

2. Data Manipulation

Once the data structure is defined, data needs to be inserted, modified or deleted. The functions which perform these operations are also part of the DBMS. These function can handle planned and unplanned data manipulation needs. Planned queries are those which form part of the application. Unplanned queries are ad-hoc queries which are performed on a need basis.

3. Data Security & Integrity

The DBMS contains functions which handle the security and integrity of data in the application. These can be easily invoked by the application and hence the application programmer need not code these functions in his/her programs.

4. Data Recovery & Concurrency

Recovery of data after a system failure and concurrent access of records by multiple users are also handled by the DBMS.

5. Data Dictionary Maintenance

Maintaining the Data Dictionary which contains the data definition of the application is also one of the functions of a DBMS.

6. Performance

Optimizing the performance of the queries is one of the important functions of a DBMS. Hence the DBMS has a set of programs forming the Query Optimizer which evaluates the different implementations of a query and chooses the best among them.

Thus the DBMS provides an environment that is both convenient and efficient to use when there is a large volume of data and many transactions to be processed.

ADVANTAGE DATABASE SYSTEM



As shown in the figure, the DBMS is a central system which provides a common interface between the data and the various front-end programs in the application. It also provides a central location for the whole data in the application to reside.

Due to its centralized nature, the database system can overcome the disadvantages of the file-based system as discussed below.

Minimal Data Redundancy:- Since the whole data resides in one central database, the various programs in the application can access data in different data files. Hence data present in one file need not be duplicated in another. This reduces data redundancy.

However, this does not mean all redundancy can be eliminated. There could be business or technical reasons for having some amount of redundancy. Any such redundancy should be carefully controlled and the DBMS should be aware of it.

Data Consistency:- Reduced data redundancy leads to better data consistency.

Data Integration:- Since related data is stored in one single database, enforcing data integrity is much easier. Moreover, the functions in the DBMS can be used to enforce the integrity rules with minimum programming in the application programs.

Data Sharing:-  Related data can be shared across programs since the data is stored in a centralized manner. Even new applications can be developed to operate against the same data.


· Enforcement of Standards:- Enforcing standards in the organization and structure of data files is required and also easy in a Database System, since it is one single set of programs which is always interacting with the data files.


· Application Development Ease:- The application programmer need not build the functions for handling issues

like concurrent access, security, data integrity, etc. The programmer only needs to implement the application business rules. This brings in application development ease. Adding additional functional modules is also easier than in file-based systems.


· Better Controls:-Better controls can be achieved due to the centralized nature of the system.


· Data Independence:-The architecture of the DBMS can be viewed as a 3-level system comprising the following:


- The internal or the physical level where the data resides.

- The conceptual level which is the level of the DBMS functions

- The external level which is the level of the application programs or the end user.


Data Independence is isolating an upper level from the changes in the organization or structure of a lower level. For example, if changes in the file organization of a data file do not demand for changes in the functions in the DBMS or in the application programs, data independence is achieved. Thus Data Independence can be defined as immunity of applications to change in physical representation and access technique. The provision of data independence is a major objective for database systems.


· Reduced Maintenance:-Maintenance is less and easy, again, due to the centralized nature of the system.

history of database system


Data processing drives the growth of computers, as it has from the earliest days of commercial computers. In fact, automation of data processing tasks predates computers. Punched cards, invented by Hollerith, were used at the very beginning of the twentieth century to record U.S. census data, and mechanicalsystems were used to process the cards and tabulate results. Punched cards were later widely used as a means of entering data into computers.

Techniques for data storage and processing have evolved over the years:

• 1950s and early 1960s: Magnetic tapes were developed for data storage. Data processing tasks such as payroll were automated, with data stored on tapes. Processing of data consisted of reading data from one or more tapes and writing data to a new tape. Data could also be input from punched card decks, and output to printers. For example, salary raises were processed by entering the raises on punched cards and reading the punched card deck in synchronization with a tape containing the master salary details. The records had to be in the same sorted order. The salary raises would be added to the salary read from the master tape, and written to a new tape; the new tape would become the new master tape.

• Late 1960s and 1970s:Widespread use of hard disks in the late 1960s changed the scenario for data processing greatly, since hard disks allowed direct access to data. The position of data on disk was immaterial, since any location on disk could be accessed in just tens of milliseconds. Data were thus freed from the tyranny of sequentiality.With disks, network and hierarchical databases could be created that allowed data structures such as lists and trees to be stored on disk.  Programmers could construct and manipulate these data structures.



A landmark paper by Codd [1970] defined the relational model, and nonprocedural ways of querying data in the relational model, and relational databases were born.The simplicity of the relational model and the possibility of hiding implementation details completely from the programmer were enticing indeed. Codd later won the prestigious Association of Computing Machinery Turing Award for his work.

1980s: Although academically interesting, the relational model was not used in practice initially, because of its perceived performance disadvantages; relational databases could not match the performance of existing network and hierarchical databases. That changed with System R, a groundbreaking project at IBM Research that developed techniques for the construction of an efficient relational database system. Excellent overviews of System R are provided by Astrahan [1976] and Chamberlin [1981]. The fully functional System R prototype led to IBM’s first relational database product, SQL/DS. Initial commercial relational database systems, such as IBM DB2, Oracle, Ingres, and DEC Rdb, played a major role in advancing techniques for efficient processing of declarative queries. By the early 1980s, relational databases had become competitive with network and hierarchical database systems even in the area of performance. Relational databases were so easy to use that they eventually replaced network/hierarchical databases; programmers using such databases were forced to deal with many low-level implementation details, and had to code their queries in a procedural fashion.
• Early 1990s: The SQL language was designed primarily for decision support applications, which are query intensive, yet the mainstay of databases in the1980s was transaction processing applications, which are update intensive. Decision support and querying re-emerged as a major application area for databases. Tools for analyzing large amounts of data saw large growths in usage.

Many database vendors introduced parallel database products in this period. Database vendors also began to add object-relational support to their databases.

• Late 1990s: The major event was the explosive growth of the World Wide Web. Databases wer

view of data


A database system is a collection of interrelated files and a set of programs that allow users to access and modify these files. A major purpose of a database system is to provide users with an abstract view of the data. That is, the system hides certain details of how the data are stored and maintained.



Data Abstraction

For the system to be usable, it must retrieve data efficiently. The need for efficiency has led designers to use complex data structures to represent data in the database. Since many database-systems users are not computer trained, developers hide the complexity from users through several levels of abstraction, to simplify users’ interactions with the system:

• Physical level. The lowest level of abstraction describes how the data are actually stored. The physical level describes complex low-level data structures in detail.

• Logical level. The next-higher level of abstraction describes what data are stored in the database, and what relationships exist among those data. The logical level thus describes the entire database in terms of a small number of relatively simple structures. Although implementation of the simple structures at the logical level may involve complex physical-level structures, the user of the logical level does not need to be aware of this complexity. Database administrators, who must decide what information to keep in the database, use the logical level of abstraction.

• View level. The highest level of abstraction describes only part of the entire database. Even though the logical level uses simpler structures, complexity remains because of the variety of information stored in a large database. Many users of the database system do not need all this information; instead, they need to access only a part of the database. The view level of abstraction exists to simplify their interaction with the system. The system may provide many views for the same database.

Instances and Schemas


Databases change over time as information is inserted and deleted. The collection of information stored in the database at a particular moment is called an instance of the database. The overall design of the database is called the database schema. Schemas are changed infrequently, if at all.

The concept of database schemas and instances can be understood by analogy to a program written in a programming language. A database schema corresponds to the variable declarations (along with associated type definitions) in a program. Each variable has a particular value at a given instant. The values of the variables in a program at a point in time correspond to an instance of a database schema.
Database systems have several schemas, partitioned according to the levels of abstraction. The physical schema describes the database design at the physical level, while the logical schema describes the database design at the logical level.A database may also have several schemas at the view level, sometimes called subschemas, that describe different views of the database. Application programs are said to exhibit physical data independence if they do not depend on the physical schema, and thus need not be rewritten if the physical schema changes.

SQL Overview


SQL Overview

SQL is a programming language for Relational Databases. It is designed over relational algebra and tuple relational calculus. SQL comes as a package with all major distributions of RDBMS.

SQL comprises both data definition and data manipulation languages. Using the data definition properties of SQL, one can design and modify database schema, whereas data manipulation properties allows SQL to store and retrieve data from database.

Data Definition Language

SQL uses the following set of commands to define database schema −

CREATE

Creates new databases, tables and views from RDBMS.

For example −

Create database tutorialspoint;
Create table article;
Create view for_students;
DROP

Drops commands, views, tables, and databases from RDBMS.

For example−

Drop object_type object_name;
Drop database tutorialspoint;
Drop table article;
Drop view for_students;
ALTER

Modifies database schema.

Alter object_type object_name parameters;
For example−

Alter table article add subject varchar;
This command adds an attribute in the relation article with the namesubject of string type.

Data Manipulation Language

SQL is equipped with data manipulation language (DML). DML modifies the database instance by inserting, updating and deleting its data. DML is responsible for all froms data modification in a database. SQL contains the following set of commands in its DML section −

SELECT/FROM/WHERE
INSERT INTO/VALUES
UPDATE/SET/WHERE
DELETE FROM/WHERE
These basic constructs allow database programmers and users to enter data and information into the database and retrieve efficiently using a number of filter options.

SELECT/FROM/WHERE

SELECT − This is one of the fundamental query command of SQL. It is similar to the projection operation of relational algebra. It selects the attributes based on the condition described by WHERE clause.

FROM − This clause takes a relation name as an argument from which attributes are to be selected/projected. In case more than one relation names are given, this clause corresponds to Cartesian product.

WHERE − This clause defines predicate or conditions, which must match in order to qualify the attributes to be projected.

For example −

Select author_name
From book_author
Where age > 50;
This command will yield the names of authors from the relationbook_author whose age is greater than 50.

INSERT INTO/VALUES

This command is used for inserting values into the rows of a table (relation).

Syntax−

INSERT INTO table (column1 [, column2, column3 ... ]) VALUES (value1 [, value2, value3 ... ])
Or

INSERT INTO table VALUES (value1, [value2, ... ])
For example −

INSERT INTO tutorialspoint (Author, Subject) VALUES ("anonymous", "computers");
UPDATE/SET/WHERE

This command is used for updating or modifying the values of columns in a table (relation).

Syntax −

UPDATE table_name SET column_name = value [, column_name = value ...] [WHERE condition]
For example −

UPDATE tutorialspoint SET Author="webmaster" WHERE Author="anonymous";
DELETE/FROM/WHERE

This command is used for removing one or more rows from a table (relation).

Syntax −

DELETE FROM table_name [WHERE condition];
For example −

DELETE FROM tutorialspoints
   WHERE Author="unknown";

extended ER features


The basic E-R concepts can model most database features, some aspects of a database may be more aptly expressed by certain extensions to the basic E-R model. The extended E-R features are specialization, generalization, higher- and lower-level entity sets, attribute inheritance, and aggregation.

1. Specialization

An entity set may include subgroupings of entities that are distinct in some way from other entities in the set. For instance, a subset of entities within an entity set may have attributes that are not shared by all the entities in the entity set. The E-R model provides a means for representing these distinctive entity groupings.

Consider an entity set person, with attributes name, street, and city. A person may be further classified as one of the following:

• customer

• employee

Each of these person types is described by a set of attributes that includes all the attributes of entity set person plus possibly additional attributes. For example, customer entities may be described further by the attribute customer-id, whereas employee entities may be described further by the attributes employee-id and salary. The process of designating subgroupings within an entity set is called specialization. The specialization of person allows us to distinguish among persons according to whether they are employees or customers.

2.Generalization

The refinement from an initial entity set into successive levels of entity subgroupings represents a top-down design process in which distinctions are made explicit. The design process may also proceed in a bottom-up manner, in which multiple entity sets are synthesized into a higher-level entity set on the basis of common features. The database designer may have first identified a customer entity set with the attributes name, street, city, and customer-id, and an employee entity set with the attributes name, street, city, employee-id, and salary.

There are similarities between the customer entity set and the employee entity set in the sense that they have several attributes in common. This commonality can be expressed by generalization, which is a containment relationship that exists between a higher-level entity set and one or more lower-level entity sets. In our example, person is the higher-level entity set and customer and employee are lower-level entity sets. Higher- and lower-level entity sets also may be designated by the terms superclass and subclass, respectively. The person entity set is the superclass of the customer and employee subclasses.

For all practical purposes, generalization is a simple inversion of specialization.            

3.Attribute Inheritance

A crucial property of the higher- and lower-level entities created by specialization and generalization is attribute inheritance. The attributes of the higher-level entity sets are said to be inherited by the lower-level entity sets. For example, customer and employee inherit the attributes of person. Thus, customer is described by its name, street, and city attributes, and additionally a customer-id attribute; employee is described by its name, street, and city attributes, and additionally employee-id and salary attributes.

A lower-level entity set (or subclass) also inherits participation in the relationship sets in which its higher-level entity (or superclass) participates. The officer, teller, and secretary entity sets can participate in the works-for relationship set, since the superclass employee participates in the works-for relationship. Attribute inheritance applies through all tiers of lower-level entity sets. The above entity sets can participate in any relationships in which the person entity set participates. Whether a given portion of an E-R model was arrived at by specialization or generalization,the outcome is basically the same:

• A higher-level entity set with attributes and relationships that apply to all of its lower-level entity sets

• Lower-level entity sets with distinctive features that

hierarchical data model


In the hierarchical data model, information is organized as a collection of inverted trees of records. The inverted trees may be of arbitrary depth. The record at the root of a tree has zero or more child records; the child records, in turn, serve as parent records for their immediate descendants. This parent-child relationship recursively continues down the tree.

The records consists of fields, where each field may contain simple data values (e.g. integer, real, text), or a pointer to a record. The pointer graph is not allowed to contain cycles. Some combinations of fields may form the key for a record relative to its parent. Only a few hierarchical DBMSs support null values or variable-length fields.



Applications can navigate a hierarchical database by starting at a root and successively navigate downward from parent to children until the desired record is found. Applications can interleave parent-child navigation with traversal of pointers. Searching down a hierarchical tree is very fast since the storage layer for hierarchical databases use contiguous storage for hierarchical structures. All other types of queries require sequential search techniques.

A DDL for hierarchical data model must allow the definition of record types, fields types, pointers, and parent-child relationships. And the DML must support direct navigation using the parent-child relationships and through pointers. Programs therefore navigate very close to the physical data structure level, implying that the hierarchical data model offers only very limited data independence.

The hierarchical data model is impoverished for expressing complex information models. Often a natural hierarchy does not exist and it is awkward to impose a parent-child relationship. Pointers partially compensate for this weakness, but it is still difficult to specify suitable hierarchical schemas for large models.

Database Relations


Database Relations

1.      Relation schema

   Named relation defined by a set of attribute and domain name pairs.


2.      Relational database schema

         Set of relation schemas, each with a distinct name.

Properties of Relations

Relation name is distinct from all other relation names in relational schema.
Each cell of relation contains exactly one atomic (single) value.
Each attribute has a distinct name.
Values of an attribute are all from the same domain.
Each tuple is distinct; there are no duplicate tuples.
Order of attributes has no significance.
Order of tuples has no significance, theoretically.
Relational Keys

Superkey

An attribute, or a set of attributes, that uniquely identifies a tuple within a relation.


Candidate Key

 Superkey (K) such that no proper subset is a superkey within the relation.
In each tuple of R, values of K uniquely identify that tuple (uniqueness).
No proper subset of K has the uniqueness property (irreducibility).

Primary Key

Candidate key selected to identify tuples uniquely within relation.


Alternate Keys

Candidate keys that are not selected to be primary key.


Foreign Key

Attribute, or set of attributes, within one relation that matches candidate key of some (possibly same) relation.


Relational Integrity

Null

Represents value for an attribute that is currently unknown or not applicable for tuple.
Deals with incomplete or exceptional data.
Represents the absence of a value and is not the same as zero or spaces, which are values.

Entity Integrity

In a base relation, no attribute of a primary key can be null.


Referential Integrity

If foreign key exists in a relation, either foreign key value must match a candidate key value of some tuple in its home relation or foreign key value must be wholly null.


Enterprise Constraints

Additional rules specified by users or database administrators.

Featured post

check box

<!DOCTYPE html> <html> <head>   <title>Check Box</title> </head> <body>   <input ty...