DBMS Keys Auto Saved)

23
DBMS Keys: A key is an attribute (also known as column or field) or a combination of attributes that is used to identify records. Sometimes we might have to retrieve data from more than one table, in those cases we require to join tables with the help of keys. The purpose of the key is to bind data together across tables without repeating all of the data in every table. The various types of key with e.g. in SQL are mentioned below, (For examples let suppose we have an Employee Table with attributes ID‘ , Name‘ ,‘Address‘ , Department_ID‘ ,‘Salary‘) (I) Super Key An attribute or a combination of attribute that is used to identify the records uniquely is known as Super Key. A table can have many Super Keys. E.g. of Super Key 1 ID 2 ID, Name 3 ID,Address 4 ID, Department_ID 5 ID, Salary 6 Name, Address 7 Name, Address, Department_ID ………… So on as any combination which can identify the records uniquely will be a Super Key. (II) Candidate Key It can be defined as minimal Super Key or irreducible Super Key. In other words an attribute or a combination of attribute that identifies the record uniquely but none of its proper subsets can identify the records uniquely. E.g. of Candidate Key 1 Code 2 Name, Address For above table we have only two Candidate Keys (i.e. Irreducible Super Key) used to identify the records from the table uniquely. Code Key can identify the record uniquely and similarly combination of Name and Address can identify the record uniquely, but neither Name nor Address can be used to identify the records uniquely as it might be possible that we have two employees with similar name or two employees from the same ho use. (III) Primary Key A Candidate Key that is used by the database designer for unique identification of each row in a table is known as Primary Key. A Primary Key can consist of one or more attributes of a t able. E.g. of Primary Key - Database designer can use one of the Candidate Key as a Primary Key. In this case we have Codeand Name, Addressas Candidate Key, we will consider CodeKey as a Primary Key as the other key is the combination of more than one attribute. (IV) Foreign Key A foreign key is an attribute or combination of attribute in one base table that points to the candidate key (generally it is the primary key) of another table. The purpose of the foreign key is to ensure referential integrity of the data i.e. only values that are supposed to appear in the database are permitted. E.g. of Foreign Key Let consider we have another table i.e. Department Table with Attributes Department_ID, Department_Name, Manager_ID, Location_IDwith Department_ID as an Primary Key. Now the Depar tment_ID attribute of Employee Table

Transcript of DBMS Keys Auto Saved)

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 1/23

DBMS Keys: A key is an attribute (also known as column or field) or a combination of

attributes that is used to identify records. Sometimes we might have to retrieve data from

more than one table, in those cases we require to join tables with the help of keys. The

purpose of the key is to bind data together across tables without repeating all of the data in

every table. The various types of key with e.g. in SQL are mentioned below, (For examples

let suppose we have an Employee Table with attributes ‗ID‘ , ‗Name‘ ,‘Address‘ ,

‗Department_ID‘ ,‘Salary‘) 

(I) Super Key – An attribute or a combination of attribute that is used to identify the

records uniquely is known as Super Key. A table can have many Super Keys.

E.g. of Super Key 1 ID

2 ID, Name

3 ID,Address

4 ID, Department_ID

5 ID, Salary

6 Name, Address7 Name, Address, Department_ID ………… So on as any combination which can identify the

records uniquely will be a Super Key.

(II) Candidate Key – It can be defined as minimal Super Key or irreducible Super Key. In

other words an attribute or a combination of attribute that identifies the record uniquely but

none of its proper subsets can identify the records uniquely.

E.g. of Candidate Key 1 Code

2 Name, Address

For above table we have only two Candidate Keys (i.e. Irreducible Super Key) used to identify

the records from the table uniquely. Code Key can identify the record uniquely and similarly

combination of Name and Address can identify the record uniquely, but neither Name nor

Address can be used to identify the records uniquely as it might be possible that we have two

employees with similar name or two employees from the same house.

(III) Primary Key – A Candidate Key that is used by the database designer for unique

identification of each row in a table is known as Primary Key. A Primary Key can consist of

one or more attributes of a table.

E.g. of Primary Key - Database designer can use one of the Candidate Key as a Primary Key.

In this case we have ―Code‖ and ―Name, Address‖ as Candidate Key, we will consider ―Code‖

Key as a Primary Key as the other key is the combination of more than one attribute.

(IV) Foreign Key – A foreign key is an attribute or combination of attribute in one base tablethat points to the candidate key (generally it is the primary key) of another table. The

purpose of the foreign key is to ensure referential integrity of the data i.e. only values that

are supposed to appear in the database are permitted.

E.g. of Foreign Key – Let consider we have another table i.e. Department Table with

Attributes ―Department_ID‖, ―Department_Name‖, ―Manager_ID‖, ‖Location_ID‖ with

Department_ID as an Primary Key. Now the Department_ID attribute of Employee Table

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 2/23

(dependent or child table) can be defined as the Foreign Key as it can reference to the

Department_ID attribute of the Departments table (the referenced or parent table), a

Foreign Key value must match an existing value in the parent table or be NULL.

(V) Composite Key – If we use multiple attributes to create a Primary Key then that Primary

Key is called Composite Key (also called a Compound Key or Concatenated Key).

E.g. of Composite Key, if we have used ―Name, Address‖ as a Primary Key then it will be our

Composite Key.

(VI) Alternate Key – Alternate Key can be any of the Candidate Keys except for the Primary

Key.

E.g. of Alternate Key is ―Name, Address‖ as it is the only other Candidate Key which is not a

Primary Key.

(VII) Secondary Key – The attributes that are not even the Super Key but can be still used

for identification of records (not unique) are known as Secondary Key.

E.g. of Secondary Key can be Name, Address, Salary, Department_ID etc. as they can

identify the records but they might not be unique.

Primary key :- The attribute or combination of attributes that uniquely identifies a row or

record.

Foreign Key:- an attribute or combination of attributes in a table whose value matches a

primary key in another table.

Composite key:- A primary key that consists of two or more attributes is known as

composite key

candidate key:- is a column in a table which has the ability to become a primary key.

Alternate Key: - Any of the candidate keys that is not part of the primary key is called an

alternate key.Secondary key:- alternate of primary key.

Cloud computing is the delivery of computing as a service rather than a product, whereby

shared resources, software and information are provided to computers and other devices as

a utility(like the electricity grid) over a network(typically the Internet).

Difference B/W Class and Structure: what's the difference between structure and class?‖Or

"In what could be the structure useful as we have already the class that can do perfectly the

 job?"

1. The structures are value types and the classes are reference types. Before stepping to the

next point let explain the difference between the two types. Imagine this is the memory

within the machine.

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 3/23

 The value types are stored in the stack. In fact, what could be really stored in the

stack for the reference types is a pointer that targets an address at the heap level.

Then type of structure objects are stored in the stack exactly like any value type say

an Integer, a double or a float. Meanwhile, memory emplacements could be reserved

for the reference types in the heap. Defining heap and stack and the difference

between them is beyond the scope of this article but nevertheless I propose this

excellent Matthew article to understand the memory mechanism.

http://www.csharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034P

M/csharp_memory.aspx?ArticleID=9adb0e3c-b3f6-40b5-98b5-413b6d348b91 

2.Classes are usually used for large amounts of data, whereas structs are usually used for

smaller amount of data

3.Classes could be inherited whereas structures no

4.A structure couldn't be Null like a class5.A structure couldn't have a destructor such as class

6.A structure can't be abstract, a class can

7.U cannot override any methods within a structure except those belong to type of object

a. Equals()

b. GetHashCode()

c. GetType()

d. ToString()

And the other polymorphism technique used for structures is implementing interfaces

8.Declared events within a class are automatically locked and then they are Thread safe, at

the contrast of the structure type where event couldn't be locked.9.A structure must have always the default parameter less constructor be defined as public

but a class might have one, so you can't define a private parameter less constructor

struct Me

 {

private Me() // compile-time error 

 {

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 4/23

}

 }

class Me

 {

private Me() // runs Ok

 {

 }

10.A static constructor is trigged in case of class but not in case of structure

struct myStructure

 {

static myStructure()

 {

Console.WriteLine("This is me a structure");

 }

 }class myClass

 {

static myClass()

 {

Console.WriteLine("This is me a class");

 }

 }

class Program {

static void Main(string[] args)

 {

myStructure s = new myStructure();//Nothing happen

myClass c = new myClass();//Will out put This is me a class

Console.Read();

 }

 }

11.The structure can't contain a volatile field whereas the class does

12. U can't use sizeof with classes but you can with structures

13.Fields are automatically initialized with classes to 0/false/null whereas in structures no

14.Fields couldn't directly instantiated within structures but classes allow such operations

struct myStructure

 {

public string x = 2;//Not allowed

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 5/23

}

class myClass

 {

public string x = 2; //Allowed

 }

15.Structure and class don't adopt the same approach toward the System.Object.Equals()method. Eg: Suppose those Strucutre and class

struct StructurePerson

 {

public string FirstName;

public string LastName;

 }

class ClassPerson

 {

public string FirstName;

public string LastName;

 }

Now, try this code

class Program

 {

static void Main(string[] args)

 {

StructurePerson strX = new StructurePerson();

strX.LastName = "Bejaoui";

strX.FirstName = "Bechir";

StructurePerson strY = new StructurePerson();strY.LastName = "Bejaoui";

strY.FirstName = "Bechir";

if (strX.Equals(strY))

 {

Console.WriteLine("strX = strY");

 }

else

 {

Console.WriteLine("strX != strY"); }//This code displays strX = strY 

ClassPerson clsX = new ClassPerson();

clsX.LastName = "Bejaoui";

clsX.FirstName = "Bechir";

ClassPerson clsY = new ClassPerson();

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 6/23

clsY.LastName = "Bejaoui";

clsY.FirstName = "Bechir";

if (clsX.Equals(clsY))

 {

Console.WriteLine("clsX = clsY");

 }

else

 {

Console.WriteLine("clsX != clsY");

 }//This code displays clsX != clsY

Console.Read();

 }

 }

In the first strucutre case the two objects are value types, they are compared

according to their values like int I = 5 and int J = 5 so I=J because they have the

same value. At the contrast, in the class case two different and distinct reference are

created so to make clsX = clsY you should use this code.

ClassPerson clsX = new ClassPerson();

clsX.LastName = "Bejaoui";

clsX.FirstName = "Bechir";

ClassPerson clsY = clsX;

if (clsX.Equals(clsY))

 {

Console.WriteLine("clsX = clsY");

 }

else

 {

Console.WriteLine("clsX != clsY");

 }//This code displays clsX = clsY

Question Raised : In 10th point we cant use new keyword with structure.

myStructure s = new myStructure();

& in 15th point U are still declaring with new.

StructurePerson strX = new StructurePerson();

Answer: In the rule n10 I've just made clear that the notion of the static constructor let's

say is not useful in case of structure like in the class case. First, let's explain the notion of

the static constructor, this last one once it holds some business logic, then this business logic

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 7/23

will be processed exactly one time when the first instance of the class is created, Of Corse,

if you want that business logic is invoked each time a new instance is created then you should

locate it in the instance constructor, the static constructor is approximatively similar to the

static block in java static{//Some logic here} if you did some java programming. On the other

hand if you define some business logic within a static constructor within structure then this

last one will not simply be invoked, for the first time that you use the structure.

In the n15 the use of the new keyword is optional in case of structure as it is of value type.

try to use this structure with and without the new keyword, in both cases it works!

struct Structure2

 {

public string MyProperty { get { return "Bechir"; } }

 }

I can still use the new keyword in this case for example, I mean, I want to leverage some

business logic when the structure is invoked.

struct Structure {

private int result;

public Structure(int a , int b)

 {

result = a + b;

 }

public int MyProperty { get { return result; } }

 }

Structure s = new Structure(2,5);

Console.WriteLine(s.MyProperty.ToString());

Wrapper Class in Java: Java is an object-oriented language and as said everything in java isan object. what about the primitives? They are sort of left out in the world of objects, i.e.,

they cannot participate in the object activities, such as being returned from a method as an

object, and being added to a Collection of objects, etc. . As a solution to this problem, Java

allows you to include the primitives in the family of objects by using what are called wrapper

classes. There is a wrapper class for every primitive data type in Java. This class

encapsulates a single value for the primitive data type. For instance the wrapper class for int

is Integer, for float is Float, and so on. Remember that the primitive name is simply the

lowercase name of the wrapper except for char, which maps to Character, and int, which

maps to Integer. The wrapper classes in the Java API serve two primary purposes:

  To provide a mechanism to ―wrap‖ primitive values in an object so that the primitives

can be included in activities reserved for objects, like as being added to Collections, or

returned from a method with an object return value.

  To provide an assortment of utility functions for primitives. Most of these functions

are related to various conversions: converting primitives to and from String objects,

and converting primitives and String objects to and from different bases (or radix),

such as binary, octal, and hexadecimal.

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 8/23

The wrapper object of a wrapper class can be created in one of two ways: by instantiating

the wrapper class with the new operator or by invoking a static method on the wrapper class.

We will explore this further in this article.

Creating Wrapper Objects with the new Operator:

Before we can instantiate a wrapper class, we need to know its name and the arguments its

constructor accepts. The name of the wrapper class corresponding to each primitive datatype, along with the arguments its constructor accepts, is listed below:

Primitive datatype-->Wrapper Class-->Constructor arguments

  boolean--> Boolean--> boolean or String

  byte--> Byte--> byte or String

  char--> Character--> char

  short--> Short--> short or String

  int-->Integer--> int or String

  long--> Long--> long or String

  float-->Float--> float double or String

  double-->Double--> double or String

All the wrapper classes are declared final. That means you cannot derive a subclass from any

of them. All the wrapper classes except Boolean and Character are subclasses of an abstract

class called Number, whereas Boolean and Character are derived directly from the Object

class. All of the wrapper classes except Character provide two constructors: one that takes a

primitive of the type being constructed, and one that takes a String representation of the

type being constructed—for example,

Code:

Boolean wboo = new Boolean("false");

Boolean yboo=new Boolean(false);

Byte wbyte = new Byte("2");Byte ybyte=new Byte(2);

Short wshort = new Short("4");

Short yshort = new Short(4);

Integer wint = new Integer("16");

Integer yint = new Integer(16);

Long wlong = new Long("123");

Long ylong = new Long(123);

Float wfloat = new Float("12.34f");

Float yfloat = new Float(12.34f);

Double wdouble = new Double("12.56d");

Double wdouble = new Double(12.56d);Character c1 = new Character('c');

The value may also be passed as a variable, as shown in the following example:

Code:

boolean boo = false;

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 9/23

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 10/23

The valueOf(…) method in the Character class accepts only char as an argument, while any

other wrapper class will accept either the corresponding primitive type or String as an

argument. The valueOf(…) method in the integer number wrapper classes (Byte, Short,

Integer, and Long) also accepts two arguments together: a String and a radix, where radix is

the base.

Using Wrapper Conversion UtilitiesA storage capability without the corresponding retrieval capability is not of much use. Once

you store a primitive in a wrapper object, often you will want to retrieve the stored primitive

at a later time.

xxxValue() method

When you need to convert the value of a wrapped numeric to a primitive, use one of the many

xxxValue() methods. All of the methods in this family are no-arg methods. Each of the six

numeric wrapper classes has six methods, so that any numeric wrapper can be converted to

any primitive numeric type.

Code:

Integer i2 = new Integer(42); // make a new wrapper object

byte b = i2.byteValue(); // convert i2's value to a byte primitiveshort s = i2.shortValue(); // another of Integer's xxxValue methods

double d = i2.doubleValue(); // yet another of Integer's xxxValue methods

or

Code:

Float f2 = new Float(3.14f); // make a new wrapper object

short s = f2.shortValue(); // convert f2's value to a short primitive

System.out.println(s); // result is 3 (truncated, not rounded)

xxx Parsexxx(String) methodIf you do not need to store a value in a wrapper but just want to perform a quick operation

on it, such as converting the type, you can do it by using an appropriate static method of the

appropriate wrapper class. For example, all the wrapper classes except Character offer a

static method that has the following signature:

static <type> parse<Type>(String s) 

The <type> may be any of the primitive types except char (byte, short, int, long, float,

double, or boolean), and the <Type> is the same as <type> with the first letter uppercased;

for example:

static int parseInt (String s) 

Each of these methods parses the string passed in as a parameter and returns the

corresponding primitive type.For example, consider the following code:

Code:

String s = "123";

int i = Integer.parseInt(s);

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 11/23

The second line will assign an int value of 123 to the int variable i.

Methods to Convert Strings to Primitive Types

Wrapper Class--> Method Signature--> Method Arguments

  Boolean--> static boolean parseBoolean(…)--> String

 Character--> Not Available

  Byte static byte parseByte(…)--> String, or String and radix

  Short--> static short parseShort(…)--> String, or String and radix

  Integer--> static int parseInt(…)--> String, or String and radix

  Long--> static long parseLong(…)--> String, or String and radix

  Float--> static float parseFloat(…)--> String

  Double--> static double parseDouble(…)--> double or String

parseXxx() and valueOf()

The six parseXxx() methods (one for each numeric wrapper type) are closely related to the

valueOf() method that exists in all of the numeric wrapper classes (plus Boolean). Both

parseXxx() and valueOf() take a String as an argument, throw a NumberFormatException ifthe String argument is not properly formed, and can convert String objects from different

bases (radix), when the underlying primitive type is any of the four integer types.

The difference between the two methods is:

  parseXxx() returns the named primitive.

  valueOf() returns a newly created wrapped object of the type that invoked the

method.

Some examples of these methods in action:

Code:

double d4 = Double.parseDouble("3.14"); // convert a String to a primitiveSystem.out.println("d4 = " + d4); // result is "d4 = 3.14"

Double d5 = Double.valueOf("3.14"); // create a Double object

System.out.println(d5 instanceof Double ); // result is "true"

The next examples involve using the radix argument, (in this case binary):

Code:

long L2 = Long.parseLong("101010", 2); // binary String to a primitive

System.out.println("L2 = " + L2); // result is "L2 = 42"

Long L3 = Long.valueOf("101010", 2); // binary String to Long object

System.out.println("L3 value = " + L3); // result is "L2 value = 42"

toString() method

The class Object, the super class of all classes, has a toString() method. Since we know that

all other Java classes inherit from class Object, we also know that all other Java classes have

a toString() method. The idea of the toString() method is to allow you to get some meaningful

representation of a given object. For instance, if you have a Collection of various types of

objects, you can loop through the Collection and print out some sort of meaningful

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 12/23

representation of each object using the toString() method, which is guaranteed to be in every

class. All of the wrapper classes have a no-arg, nonstatic, instance version of toString(). This

method returns a String with the value of the primitive wrapped in the object—for instance,

Code:

Double d = new Double("3.14");

System.out.println("d = " + d.toString() ); // result is "d = 3.14"

All of the numeric wrapper classes provide an overloaded, static toString() method that takes

a primitive numeric of the appropriate type (Double.toString() takes a double, Long.toString()

takes a long, etc.), and, of course, returns a String with that primitive‘s value—for example,

Code:

System.out.println("d = " + Double.toString(3.14); // result is "d = 3.14"

Finally, Integer and Long provide a third toString() method. It is static, its first argument is

the appropriate primitive, and its second argument is a radix. The radix argument tells the

method to take the first argument (which is radix 10 or base 10 by default), and convert it

to the radix provided, then return the result as a String—for instance,Code:

System.out.println("hex = " + Long.toString(254,16); // result is "hex = fe"

toXxxString() method(Binary, Hexadecimal, Octal)

The Integer and Long wrapper classes let you convert numbers in base 10 to other bases.

These conversion methods, toXxxString(), take an int or long, and return a String

representation of the converted number, for example,

Code:

String s3 = Integer.toHexString(254); // convert 254 to hex

System.out.println("254 in hex = " + s3); // result is "254 in hex = fe"

String s4 = Long.toOctalString(254); // convert 254 to octal

System.out.println("254 in octal = "+ s4); // result is "254 in octal = 376"

Difference between C++ and Java:

1. C++ is object oriented program.

2. Java is a purely object oriented program

3. Java does not support Global variables

4. Java does not use the pointers

5. Java does not support operator overloading

6. Java does not template classes as in C++.

7. Java has replaced the destructor function with a finalize function.

Difference between C and Java:

1. C is a structure oriented program.

2. Java does not support explicit pointer type.

3. Java requires that the functions with number arguments must be declared empty

paranthesis and not with the void keyword in C.

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 13/23

4. Java does not define the type modifiers keywords auto, extern, register, signed &

unsigned.

1.C is a structured language and it‘s a platform dependent language it means the executable

code can‘t be run on other operating system. It‘s the first language among in all three. The

programming is hard as compare to c++ and java. C has top down approach.2.c++ is also a very good language. It‘s the advanced version of C language. It‘s also platform

dependent language. C++ is an object oriented language.

3. java is a purely object oriented language. it means all functions are called with the help of

class and objects.java is a very easy, robust, secure, portable language and easy to learn as

compare to other languages.

The most important program that runs on a computer. Every general-purpose computer must

have an operating system to run other programs. Operating systems perform basic tasks, such

as recognizing input from the keyboard, sending output to the display screen, keeping track

of files and directories on the disk, and controlling peripheral devices such as disk

drives and printers. For large systems, the operating system has even greater responsibilities

and powers. It is like a traffic cop -- it makes sure that different programs and

users running at the same time do not interfere with each other. The operating system is also

responsible for security , ensuring that unauthorized users do not access the system.Operating systems can be classified as follows:

multi-user : Allows two or more users to run programs at the same time. Some operating

systems permit hundreds or even thousands of concurrent users.

multiprocessing : Supports running a program on more than one CPU. 

multitasking : Allows more than one program to run concurrently.

multithreading : Allows different parts of a single program to run concurrently.

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 14/23

real time: Responds to input instantly. General-purpose operating systems, such

as DOS and UNIX, are not real-time.

Operating systems provide a software platform on top of which other programs,

called application programs, can run. The application programs must be written to run on top

of a particular operating system. Your choice of operating system, therefore, determines to a

great extent the applications you can run. For PCs, the most popular operating systems areDOS, OS/2, and Windows, but others are available, such as Linux. As a user, you normally

interact with the operating system through a set of commands. For example, the DOS

operating system contains commands such as COPY and RENAME for copying files and changing

the names of files, respectively. The commands are accepted and executed by a part of the

operating system called the command processor or command line interpreter. Graphical user

interfaces allow you to enter commands by pointing and clicking at objects that appear on the

screen.

Q. Difference between "C structure" and "C++ structure".

Ans: - C structure cannot have member functions but C++ structure can have. Also in a C

structure by default all data members of structure are public and access cannot be changed

by specifying the private or protected keywords but in C++ even though by default membersare public we may change the access using the keywords private and protected.

Q. What is the difference between "overloading" and "overriding"?

ans:- Overloading is a process of having the same function name but different no of

arguments or types of arguments within the same class but overriding means redefining a

baseclass functions definition in the subclass.

Q. Explain the need for "Virtual Destructor".

Ans: =Virtual destructor ensures destruction of subclass and base class objects in proper

order.

Q. What are the different types of polymorphism?

Ans:-Overloading and overriding.

Q. What are the different types of Storage classes?Ans:-Auto, Register, static and extern

1.Automatic: The scope is within the class that is like local to its class

2.Extern: The scope of this is used within the class as well as outside the class so it is global

3.Regiter: These are mainly used for faster access of data.

4.Static: Once you declare the variable as static it will remain constant throughout the

program

Q. What is the difference between "calloc" and "malloc"?

Ans: - calloc and malloc are used for dynamic memory allocation. Calloc initializes the memory

locations to zero by default but malloc memory contains garbage values.

Difference between "printf" and "sprintf": printf will write to the console. sprintf will write to

the buffer.Polymorphism means one name implies many forms, which introduces generic programming.

Polymorphism happens in the inheritance hierarchy, so that low level abstractions which extend

higher level abstraction can override

(re-implementing a method of superclass in a subclass with identical signature) the

implementation of the higher level abstraction.

example:

class vehicle {

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 15/23

void accelerate()

 }

class car extends vehicle{

void accelerate()

 {

S.O.P("um a car"); }

 }

class bike extends vehicle{

void accelerate()

 {

S.O.P("um a bike");

 }

 }

now bike and car vehicles .

so we can say

Vehicle[] v = new Vehicle[2];v[0]= new Car();

v[1]=new Bike();

so here i have array of vehicles

i can do the following (generically )

for (i=0;i<v.length;i++)

v[i].accelerate();

output:

um a car

um a bike

like i say ok guys all of u r vehicles so all of u can accelerate so do it everyone on his own

way .now that was a very polymorphic piece of codebecause every time i call the method accelerate on an object the JVM will do

Dynamic resolution and invoke the corresponding method of that object .so not only overriding

is polymorphic but we should keep a consistent inheritance hierarchy or abstraction levels

.method overloading is another form of polymorphism but its easier to implement because at

compilation time all the method calls are resolved .

for ex

class Add {

int add(int a, int b)

 {

return a+b;

 }float add(float a,float b)

 {

return a+b;

 }

 }

so be careful with overloading because methods are identified by it signature which is

-return type

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 16/23

-name

-parameters number

-parameters types

-order of parameters

since overloading means the same name then we are left with

-return type-parameters number

-parameters types

-order of parameters

now let‘s see this code

Add a = new Add();

int x =a.add( 2 , 3 );

float y = a.add( 2.2, 3.4);

dangling pointer: Dangling pointers in computer programming are pointers that do not point to a

valid object of the appropriate type. Dangling pointers arise when an object is deleted or

deallocated, without modifying the value of the pointer, so that the pointer still points to the

memory location of the deallocated memory.write a program to print like this

1,

1,2,

1,2,3,

1,2,3,4,

1,2,3,4,

1,2,3,

1,2,

1,

Logic:for(i=1;i {

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

 {

printf("%d,"j);

 }

printf("\n");

 }

for(i=n;i>0;i--)

 {

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

 {printf("%d,"j);

 }

printf("\n");

 }

Tell me about yourself and your family?

ME: Good Morning sir, Firstly I would like to thank u for giving me an opportunity to introduce

myself. I am bharath from tirupathi. Now i am in Perusing my final Batch in CSE from

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 17/23

RGMCET with an aggregate of 75%. I did my intermediate from Vivekananda Education

Academy with 96%. I did my schooling from Vivekananda Vidya Mandir with 87%

My father is a farmer and my mother is a good home maker My strengths are Hard working,

confident and disciplined I am a team worker and I like working in a group because no one in

this world knows everything we have to share our knowledge and it will be helpful to the

growth of the organization as well as me. My short term goal is to get a job in TCS which Ifeel a better place to put my theoretical knowledge to practical work. My long term goal is to

see TCS as world‘s no.1 IT firm and I would like to be a part of its success. Thank you sir. 

TR: What is Strictly Binary Tree?

ME: A strictly binary tree is a binary tree in which every node has an out degree either 0 or

2.

TR: What is self Referential Structures?

ME: A member of a structure which is pointing to the same structure type is called Self

Referential Structure

TR: OK, Write the syntax of it

ME: struct Node

 {

int data;

struct Node *next;

 };

TR: Why we declare main() as static in java program?

ME: Because main() is executed by JVM with Classname. main (commandlineargs);

A data model is a collection of tools for describing data, data semantics, data abstraction

etc

Dangling pointer: Dangling pointers in computer programming are pointers that do not point toa valid object of the appropriate type. Dangling pointers arise when an object is deleted or

deallocated, without modifying the value of the pointer, so that the pointer still points to the

memory location of the deallocated memory. E.g.

int* a = new int;

int *b = a;

delete b; Now a will be a dandling pointer. Simply Dangling pointer points to a memory location

which is being removed. a dangling pointer is a pointer which points to a dead location in

memory, means the variable or object is exist on that memory location but that was deleted

and pointer is still pointing to that location . this pointer is called dangling pointer.

EX:

int *function() {

int a=500;

return &a;

 }

int main()

 {

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 18/23

int *ptr;

ptr=function();

++*ptr;

printf("%d",*ptr);//output=501

 }

in the above example one function is there which is having return type int * means thisfunction returns an address. now came int main(), i have creating one pointer *ptr and after

that calling the function then whatever the address return by function is stored in *ptr.

but see the storage class of variable a in function it is auto by default and when function

execution is end that variable is destroyed and function will return the address of variable a.

that variable is destroyed but my *ptr is still pointing and utilizing that memory location and

data on that location this is called dangling pointer..

Memory leaks occur when memory allocated to a pointer is not deleted and the pointer goes

out of scope. This allocated memory never gets de-allocated and remains in the heap until the

system is restarted.

E.g.

void foo() {

int* ptr = new int;

*ptr = 10;

......}

Since ptr is allocated memory using 'new', but no 'delete' is called, hence memory allocated

to ptr will leak.

memory leak: A memory leak in computer science is a particular type of unintentional memory

consumption by a computer program where the program fails to release memory when no longer

needed.

An assignment operator (default or user provided) is called when the object already has been

instantiated. A copy constructor is called when the object has not yet been constructed.Class A{/*...*/};

main()

 {

A a;

A b = a; /* copy constructor will be called */

A c;

c = a; /* assignment operator will be called*/

 }

public static void main(String k[]) here

public: The main method will be called by jvm. so jvm is located some other place so invokeour main() should be public

static: before object is creation calling main() method so the main() method will be called by

using static

void: so jvm does not expected any return value

main():its method name

String[]:argument type is String

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 19/23

static keyword specifies that there is no need of instance to call static method and its

information is contained by JVM that calls the static method. That's why we declare main

method as static so that it can be called automatically.

public static void main(String[] args) means

public - is the access modifier .if we declare a method as public means we can access the

method out side of the class.static - It is a key word. If we declare a method as static then we can call this method with

out creating any instance of that class. Directly we can call it by "CLASSNAME.STATIC

METHOD NAME"

void - It is the return type of the method

main - It is the Method name

Because post increment operator uses a temporary variable to store the incremented value for

a variable until it is used in the next executed statement, whereas pre increment operator not

using any temp variable, it is just increase that value at the time of execution using

reference.

C Swap Program -- Fails C Swap Program with Pointers -- Works

 #include <stdio.h>

void swap(int i, int j) {

int t = i;

i = j;

 j = t;

 }

int main() {

int a = 23, b = 47;

printf("Before. a: %d, b: %d\n", a, b);swap(a,b);

printf("After. a: %d, b: %d\n", a, b);

return 0;

 }

 #include <stdio.h>

void swap(int *i, int * j) {

int t = *i;

*i = * j;

* j = t;

 }

void main() {

int a = 23, b = 47;

printf("Before. a: %d, b: %d\n", a, b);swap(&a, &b);

printf("After . a: %d, b: %d\n", a, b);

 }

Runs of the two programs

% cc -o swap0 swap0.c 

% swap0 

Before. a: 23, b: 47

After. a: 23, b: 47

% cc -o swap1 swap1.c 

% swap1 

Before. a: 23, b: 47

After. a: 47, b: 23 

With the program on the left, no swapping took place. The values of a and b are passed

to swap, and the function does swap them, but when the function returns, nothing has

changed in the main function. To get an idea of what this code does, print it out, draw the

two integers a and b, and enter 23 and 47 in them. Now draw the two pointers i and j, along

with the integer t. When swap is called, it is passed the addresses of a and b. Thus, i points

to a (draw an arrow from i to a) and j points to b (draw another arrow from b to j). Once the

pointers are initialized by the function call, *i is another name for a, and*j is another name

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 20/23

for b. Now run the code in swap. When the code uses *i and *j, it really means a and b.

When the function completes, a and b have been swapped. Suppose you accidentally forget

the & when the swap function is called, and that the swap line accidentally looks like

this: swap(a, b);. This causes a segmentation fault. When you leave out the &, the value

of a is passed instead of its address. Therefore, i points to an invalid location in memory and

the system crashes when *i is used. This is also why scanf crashes if you forget the & onvariables passed to it. The scanf function is using pointers to put the value it reads back into

the variable you have passed. Without the &, scanf is passed a bad address and crashes.

Reference parameters are one of the most common uses of pointers in C. Another way to say

this is to say that the calling function is telling the called function where to find the variable.

 #include<stdio.h> 

 #include<conio.h> 

main() 

 { 

int r; 

long n = 0, c, sum = 0, temp; printf("Enter the maximum range up to which you want to find Armstrong numbers "); 

scanf("%ld",&n); 

printf("Following Armstrong numbers are found from 1 to %ld\n",n); 

for( i = 1 ; i <= n ; i++ ) 

 { 

temp = i; 

while( temp != 0 ) 

 { 

r = temp%10; 

sum = sum + r*r*r; 

temp = temp/10;  } 

if ( i == sum ) 

printf("%ld\n", c); 

sum = 0; 

 } 

getch(); 

return 0; 

 }

 #include<stdio.h> 

 #include<conio.h> main() 

 { 

int number, sum = 0, temp, remainder; 

printf("Enter a number\n"); 

scanf("%d",&number); 

temp = number; 

while( temp != 0 ) 

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 21/23

 { 

remainder = temp%10; 

sum = sum + remainder*remainder*remainder; 

temp = temp/10; 

 } 

if ( number == sum ) printf("Entered number is an Armstrong number."); 

else 

printf("Entered number is not an Armstrong number."); 

getch(); 

return 0; 

 }

 #include<stdio.h> 

main() 

 { 

int n, reverse = 0, temp; 

printf("Enter a number to check if it is a palindrome or not\n"); scanf("%d",&n); 

temp = n; 

while( temp != 0 ) 

 { 

reverse = reverse * 10; 

reverse = reverse + temp%10; 

temp = temp/10; 

 } 

if ( n == reverse ) 

printf("%d is a palindrome number.\n", n); 

else printf("%d is not a palindrome number.\n", n); 

return 0; 

 }

gets() read the string values which allows white spaces also. whereas, scanf() doesn't allow.

The while and do-while Statements 

The while statement continually executes a block of statements while a particular condition is

true. Its syntax can be expressed as:

while (expression) {

statement(s) }

The while statement evaluates expression , which must return a boolean value. If the

expression evaluates to true, the while statement executes the statement (s) in the whileblock.

The while statement continues testing the expression and executing its block until the

expression evaluates to false. Using the while statement to print the values from 1 through

10 can be accomplished as in the following WhileDemo program:

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 22/23

class WhileDemo {

public static void main(String[] args){

int count = 1;

while (count < 11) {

System.out.println("Count is: " + count);

count++;

 }

 }

 }

 You can implement an infinite loop using the while statement as follows:

while (true){

// your code goes here

 }

The Java programming language also provides a do-while statement, which can be expressed as

follows:

do {

statement(s)

 } while (expression);

The difference between do-while and while is that do-while evaluates its expression at the

bottom of the loop instead of the top. Therefore, the statements within the do block are

always executed at least once, as shown in the following DoWhileDemo program:

class DoWhileDemo {

public static void main(String[] args){

int count = 1;

do {

System.out.println("Count is: " + count);

count++;

 } while (count <= 11);

 }

 }

Normalization is a design technique that is widely used as a guide in designing relational

databases. Normalization is essentially a two step process that puts data into tabular form by

removing repeating groups and then removes duplicated data from the relational tables.Normalization theory is based on the concepts of normal forms. A relational table is said to

be a particular normal form if it satisfied a certain set of constraints. There are currently

five normal forms that have been defined. In this section, we will cover the first three

normal forms that were defined by E. F. Codd.

Basic Concepts

The goal of normalization is to create a set of relational tables that are free of redundant

data and that can be consistently and correctly modified. This means that all tables in a

8/4/2019 DBMS Keys Auto Saved)

http://slidepdf.com/reader/full/dbms-keys-auto-saved 23/23

relational database should be in the third normal form (3NF). A relational table is in 3NF if

and only if all non-key columns are (a) mutually independent and (b) fully dependent upon the

primary key. Mutual independence means that no non-key column is dependent upon any

combination of the other columns. The first two normal forms are intermediate steps to

achieve the goal of having all tables in 3NF. In order to better understand the 2NF and

higher forms, it is necessary to understand the concepts of functional dependencies andlossless decomposition.