What Is Difference Between Malloc and Calloc?

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 21

1. what is difference between malloc and calloc?

1. malloc takes only the size of the memory block to be allocated as input parameter.
2. malloc allocates memory as a single contiguous block.
3. if a single contiguous block cannot be allocated then malloc would fail.

1. calloc takes two parameters: the number of memory blocks and the size of each block of memory
2. calloc allocates memory which may/may not be contiguous.
3. all the memory blocks are initialized to 0.
4. it follows from point 2 that calloc will not fail if memory can beallocated in non-contiguous blocks
when a single contiguous blockcannot be allocated.
malloc is dynamic memory allocation it allocates the memory and initialize garbage value.

calloc is similar to malloc but only difference is initialize zero

2. What are enumerations?


enumerations is one type of user defined data type

Enums are group of symbolic constant each having some integer value.

enum(PASS_MARK=60,MERIT_MARK=70)

defines two symbolic constant PASS_MARK and MERIT_MARK as 60 and 70,- it could be
done with #define as well.

However without specific values ,- the values are assigned automatically ,- starting with
0 for the first element and 1 for the second, 3 for the second etc.

In case if we state a number for the first element then it will increment the value of each
consecutive elemts with '1'.

enum(MON=1,TUE,WED,THU,FRI,SAT,SUN);

gives the values of 1-7 to the names of days.


enumerations can be used in place of a macros for example let us consider an example
where a function is failing for many reasons like array out of bounds, divide by zero ,and
memory allocation failure
when you call such a function and if something goes wrong you may not know for what
reason exactly in that case you can make an enum like
enum error
{
ARRAY_OUT =0,
MEMORY_FAIL,
DIVIDE_ZERO
}
and so on instead of defining each one by macro
Then based on return value it would be easy to locate eror . And ofcourse it is a user
defined type.The values assigned will be from 0 to the number of elements present . you
can also assign different values in between like
enum week {
sunday, monday, tuesday=4,wednesday,thursaday}
then wednesday and thursday would have a value of 5 and 6

3. What is the difference between Structure and Union?

Answer
A union is a way of providing an alternate way of describing the same memory area. In this way, you
could have a struct that contains a union, so that the "static", or similar portion of the data is
described first, and the portion that changes is described by the union. The idea of a union could be
handled in a different way by having 2 different structs defined, and making a pointer to each kind of
struct. The pointer to struct "a" could be assigned to the value of a buffer, and the pointer to struct
"b" could be assigned to the same buffer, but now a->somefield and b->someotherfield are both
located in the same buffer. That is the idea behind a union. It gives different ways to break down the
same buffer area.

Answer:
The difference between structure and union in c are: 1. union allocates the memory equal to the
maximum memory required by the member of the union but structure allocates the memory equal to
the total memory required by the members. 2. In union, one block is used by all the member of the
union but in case of structure, each member have their own memory space

Difference in their Usage:


While structure enables us treat a number of different variables stored at different in memory , a
union enables us to treat the same space in memory as a number of different variables. That is a
Union offers a way for a section of memory to be treated as a variable of one type on one occasion
and as a different variable of a different type on another occasion.

There is frequent rwquirement while interacting with hardware to access access a byte or group of
bytes simultaneously and sometimes each byte individually. Usually union is the answer.

=======Difference With example***** Lets say a structure containing an int,char and float is
created and a union containing int char float are declared. struct TT{ int a; float b; char c; } Union
UU{ int a; float b; char c; }

sizeof TT(struct) would be >9 bytes (compiler dependent-if int,float, char are taken as 4,4,1)
sizeof UU(Union) would be 4 bytes as supposed from above.If a variable in double exists in union then
the size of union and struct would be 8 bytes and cumulative size of all variables in struct.

Detailed Example:
struct foo
{
char c;
long l;
char *p;
};

union bar
{
char c;
long l;
char *p;
};

A struct foo contains all of the elements c, l, and p. Each element is


separate and distinct.

A union bar contains only one of the elements c, l, and p at any given
time. Each element is stored in the same memory location (well, they all
start at the same memory location), and you can only refer to the element
which was last stored. (ie: after "barptr->c = 2;" you cannot reference
any of the other elements, such as "barptr->p" without invoking undefined
behavior.)

Try the following program. (Yes, I know it invokes the above-mentioned


"undefined behavior", but most likely will give some sort of output on
most computers.)

==========
#include

struct foo
{
char c;
long l;
char *p;
};

union bar
{
char c;
long l;
char *p;
};

int main(int argc,char *argv[])


{
struct foo myfoo;
union bar mybar;

myfoo.c = 1;
myfoo.l = 2L;
myfoo.p = "This is myfoo";

mybar.c = 1;
mybar.l = 2L;
mybar.p = "This is mybar";

printf("myfoo: %d %ld %s\n",myfoo.c,myfoo.l,myfoo.p);


printf("mybar: %d %ld %s\n",mybar.c,mybar.l,mybar.p);

return 0;
}

==========

On my system, I get:

myfoo: 1 2 This is myfoo


mybar: 100 4197476 This is mybar

==========

credit to original author.

All the members of the structure can be accessed at


once,where as in an union only one member can be used at a time.
Another important difference is in the size allocated to a
structure and an union.
for eg:
struct example
{
int integer;
float floating_numbers;
}
the size allocated here is sizeof(int)+sizeof(float);
where as in an union
union example
{
int integer;
float floating_numbers;
}
size allocated is the size of the highest member.
so size is=sizeof(float);

) Structure: The size in bytes is the sum total of size of


all the elements in the structure, plus padding bytes.
2) Size of in bytes of the union is size of the largest
variable element in the union.
i.e In case of Union, the elements making up the
union 'overlap' in memory OR they are accessed as diffrent
name/type at diffrent places in the program.

Whereas in case of Struct, each of the elements have a


distinct identity.

4. Difference between :- 1) NULL pointer and NULL macro ?


5. How to find GCD of four numbers?

I want to thank you for your reply. However, I need some clarification.

1. I am not familiar with this method.


In your example, you have three numbers 16, 28, and 40. If 16 is subtracted from 28, 12 remains,
but how is 8 determined in 16, 12 and 8 from you example?
Also, can you demonstrate this method with 4, 8, & 16?

2. I am somewhat familiar with the method using division. For example, gcd for (84, 18): "Divide
84 by 18 to get a quotient of 4 and a remainder of 12. Then divide 18 by 12 to get a quotient of 1
and a remainder of 6. Then divide 12 by 6 to get a remainder of 0, which means that 6 is the gcd."
I am curious to know whether or not this method could be used with more than two numbers, 4, 8,
and 16.

6. Write a program to generate the Fibonacci Series?


7. What do the ‘c’ and ‘v’ in argc and argv stand for?
The letter "c" in argc stands for count. The letter "v" in argv stands for vector.

C uses a mechanism which you will find reminiscent of java's command-line-


argument mechanism (the "String []args" argument to main()). There is an alternate
allowable definition of main() in C and C++, whose declaration looks like this:
int main(int argc, char **argv)

"argc" stands for "argument count". It is the number of elements in "argv", "argument
vector". (While "vector" and "array" mean different things in java, traditionally they
are synonyms.)

While "argc" and "argv" are theoretically arbitrary parameter names, the use of the
names "argc" and "argv" is so standard that you should never use any other name.

Since a string can be passed around as a value of type pointer-to-char, argv will be an
array of pointers-to-char. And when argv is passed to main() by the operating system,
it will decay into a pointer to its zeroth element, so the data will be of type pointer-to-
pointer-to-char.

The array is one element larger than you might think. The program name itself is
argv[0], so the first command-line argument is argv[1], and so on, and argc reflects
the total number of items in the argv array including this argv[0]. Often we ignore
argv[0] altogether.

Example 1: Write a program which first checks that argc is at least 2, then prints the
value of argv[1] (using %s). A session with this program might look like this, where
'%' is your shell prompt:
% ./a.out hello, world
hello,
%
Since "world" is argv[2], it didn't print that part. The shell (command interpreter)
divides up the arguments based on spaces.

Solution:
#include <stdio.h>

int main(int argc, char **argv)


{
if (argc >= 2)
printf("%s\n", argv[1]);
return(0);
}
8. Does mentioning the array name gives the base address in all the contexts?

Mentioning the array name in C or C++ gives the base address in all contexts except one.

Syntactically, the compiler treats the array name as a pointer to the first element. You can
reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even
mix the usages within an expression. When you pass an array name as a function argument, you
are passing the "value of the pointer", which means that you are implicitly passing the array by
reference, even though all parameters in functions are "call by value".

There is, however, one very important distinction. While an array name is referentially the same
as a pointer, it is not a pointer in that it does not occupy program referential space in the process.
This means that, while you can change the value of a pointer, and thus the address to which it
points, you can not change the value of an array name. This distinction is what we call R-Value
(array or pointer) as opposed to L-Value (pointer only), i.e. can the object appear on the left sign
of an assignment operator.

9. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL
Macro?

Null macro is defined in stdio.h and stddef.h.It is used to represent a null pointer in your code.

its value is zero.

NULL Macro is simply what is defined as 0 in a macro provided by the library

Null pointer is a pointer which has 0 or NULL value stored and points to nowhwere still it
points to 0x00 i.e. the first memory location of the OS

Null pointer != Uninitialized pointer because an uninitialised pointer can point anywhere in
the memory location ...but a NULL pointer surely points to no where(but still behind the scene
we can say that it only points to 0x00). Never we can retrive a Null pointer location using
th"&" operator..neither will malloc/calloc return NULL IF THERE IS SPACE IN THE
MEMORY. NULL pointer is unique !!
10. What is a NULL Pointer? Whether it is same as an uninitialized pointer?
NULL pointer is pointer which is not pointing to anything in the memory. NULL is defined as
(void*)0.

Uninitialised pointer is pointing to some memory location but the pointer values are not
assigned.
Mallocreturns the memory address, but the contents of the pointer are junk values.

A null pointer is conceptually different from an uninitialized


pointer. A null pointer is known not to point to any object; an
uninitialized pointer might point anywhere.
Null pointer is making reference to something that is not
initialized,it does not point to any data object !
Uninitialized object moighgt point anywhere !
Int *money=NULL;------------- null pointer;

11. what is HTTP in asp.net?

HTTP modules and HTTP handlers are an integral part of the ASP.NET architecture. While a request is being
processed, each request is processed by multiple HTTP modules (for example, the authentication module
and the session module) and is then processed by a single HTTP handler. After the handler has processed
the request, the request flows back through the HTTP modules.

This article is divided into the following sections:

• HTTP Modules
o Available Events
o Configuring HTTP Modules
o Creating HTTP Modules
• HTTP Handlers
o Configuring HTTP Handlers
o Creating HTTP Handlers

Back to the top

HTTP Modules
Modules are called before and after the handler executes. Modules enable developers to intercept,
participate in, or modify each individual request. Modules implement theIHttpModule interface, which is
located in the System.Web namespace.
Available Events
An HttpApplication class provides a number of events with which modules can synchronize. The following
events are available for modules to synchronize with on each request. These events are listed in sequential
order:

• BeginRequest: Request has been started. If you need to do something at the beginning of a
request (for example, display advertisement banners at the top of each page), synchronize this
event.
• AuthenticateRequest: If you want to plug in your own custom authentication scheme (for
example, look up a user against a database to validate the password), build a module that
synchronizes this event and authenticates the user how you want to.
• AuthorizeRequest: This event is used internally to implement authorization mechanisms (for
example, to store your access control lists (ACLs) in a database rather than in the file system).
Although you can override this event, there are not many good reasons to do so.
• ResolveRequestCache: This event determines if a page can be served from the Output cache. If
you want to write your own caching module (for example, build a file-based cache rather than a
memory cache), synchronize this event to determine whether to serve the page from the cache.
• AcquireRequestState: Session state is retrieved from the state store. If you want to build your
own state management module, synchronize this event to grab the Session state from your state
store.
• PreRequestHandlerExecute: This event occurs before the HTTP handler is executed.
• PostRequestHandlerExecute: This event occurs after the HTTP handler is executed.
• ReleaseRequestState: Session state is stored back in the state store. If you are building a custom
session state module, you must store your state back in your state store.
• UpdateRequestCache: This event writes output back to the Output cache. If you are building a
custom cache module, you write the output back to your cache.
• EndRequest: Request has been completed. You may want to build a debugging module that
gathers information throughout the request and then writes the information to the page.

The following events are available for modules to synchronize with for each request transmission. The order
of these events is non-deterministic.

• PreSendRequestHeaders: This event occurs before the headers are sent. If you want to add
additional headers, you can synchronize this event from a custom module.
• PreSendRequestContent: This event occurs when the Response.Flush method is called. If you
want to add additional content, you can synchronize this event from a custom module.

Error: This event occurs when an unhandled exception occurs. If you want to write a custom error
HTTP Handlers
Handlers are used to process individual endpoint requests. Handlers enable the ASP.NET framework to
process individual HTTP URLs or groups of URL extensions within an application. Unlike modules, only one
handler is used to process a request. All handlers implement theIHttpHandler interface, which is located in
the System.Web namespace. Handlers are somewhat analogous to Internet Server Application
Programming Interface (ISAPI) extensions.

Configuring HTTP Handlers


The <httpHandlers> configuration section handler is responsible for mapping incoming URLs to
the IHttpHandler or IHttpHandlerFactory class. It can be declared at the computer, site, or application
level. Subdirectories inherit these settings.
Administrators use the <add> tag directive to configure the <httpHandlers> section. <Add> directives are
interpreted and processed in a top-down sequential order. Use the following syntax for the <httpHandler>
section handler:

<httpHandlers>
<add verb="[verb list]" path="[path/wildcard]" type="[COM+ Class], [Assembly]"
validate="[true/false]" />
<remove verb="[verb list]" path="[path/wildcard]" />
<clear />
</httpHandlers>

Creating HTTP Handlers


To create an HTTP handler, you must implement the IHttpHandler interface. TheIHttpHandler interface
has one method and one property with the following signatures:

void ProcessRequest(HttpContext);
bool IsReusable {get;}

NOTE: If session state is required in your HTTP handler, you also need to implement
theIRequiresSessionState interface. For additional information about creating HTTP handlers, click the
article numbers below to view the articles in the Microsoft Knowledge Base:

308001 HOW TO: Create an ASP.NET HTTP Handler by Using Visual C# .NET

• handler module, synchronize this event.

12. What is the difference between transaction database and data warehouse databases?

Transaction Database Vs DataWarehouse Database-

1. Transaction Database is Relational Database with the normalised table, whereas DataWarehouse is
with denormalised Table.

2. Transaction Database is highly volatile... Designed to maintain transaction of the business Where
DataWarehouse is non volatile.. with periodic updates.

3. Transaction Database is OLTP... Datawarehouse ... is for analysis...

4. Transaction Database is functional data... DataWarehouse database Data is subject oriented.

A Tx database is more of a Tx based (insert update rollback) oriented whereas a


Datawarehouse database is repository based & hence * select * oriented.

13. What is TSQL?


Transact-SQL is central to using SQL Server. All applications that communicate with an instance of
SQL Server do so by sending Transact-SQL statements to the server, regardless of the user interface
of the application.

The following is a list of the kinds of applications that can generate Transact-SQL:
• General office productivity applications.
• Applications that use a graphical user interface (GUI) to let users select the tables and
columns from which they want to see data.
• Applications that use general language sentences to determine what data a user wants to
see.
• Line of business applications that store their data in SQL Server databases. These applications
can include both applications written by vendors and applications written in-house.
• Transact-SQL scripts that are run by using utilities such as sqlcmd.
• Applications created by using development systems such as Microsoft Visual C++, Microsoft
Visual Basic, or Microsoft Visual J++ that use database APIs such as ADO, OLE DB, and ODBC.
• Web pages that extract data from SQL Server databases.
• Distributed database systems from which data from SQL Server is replicated to various
databases, or distributed queries are executed.
• Data warehouses in which data is extracted from online transaction processing (OLTP) systems
and summarized for decision-support analysis.

Also in short,
T-SQL (Transact-SQL) is a set of programming extensions from Sybase and Microsoft that add several
features to the Structured Query Language (SQL) including transaction control, exception and error
handling, row processing, and declared variables. Microsoft's SQL server and Sybase's SQL server
support T-SQL statements.

14. Difference between tnsnames.ora and listener.ora?


Listener.ora is the configuration file for the listener living on theserver. Tnsnames.ora is one of the
sqlnet configuration files on the client.
15. What is denormalization and when would you go for it?
16. What is lock escalation?
Lock escalation is the process of converting many fine-grained locks (such as row or page locks) into table
locks. Microsoft SQL Server dynamically determines when to perform lock escalation. When making this
decision, SQL Server takes into account the number of locks that are held on a particular scan, the number
of locks that are held by the whole transaction, and the memory that is being used for locks in the system
as a whole. Typically, SQL Server's default behavior results in lock escalation occurring only at those points
where it would improve performance or when you must reduce excessive system lock memory to a more
reasonable level. However, some application or query designs may trigger lock escalation at a time when it
is not desirable, and the escalated table lock may block other users. This article discusses how to determine
whether lock escalation is causing blocking and how to deal with undesirable lock escalation.

he simplest and safest way to prevent lock escalation is to keep transactions short and to reduce the lock
footprint of expensive queries so that the lock escalation thresholds are not exceeded. There are several
ways to obtain this goal, many of which are listed:
• Break up large batch operations into several smaller operations.

17. What is bit datatype and what,s the information that can be stored inside a bit column?
24. What is bit data type and what's the information that can be stored inside a bit column? Bit data type
is used to store Boolean information like 1 or 0 (true or false). Until SQL Server 6.5 bit data type could
hold either a 1 or 0 and there was no support for NULL. But from SQL Server 7.0 onwards, bit data type
can represent a third state, which is NULL.

18. What is a transaction and what are ACID properties? Explain the architecture of SQL Server

A transaction is a logical unit of work in which, all the steps must be performed or none. ACID
stands for Atomicity, Consistency, Isolation, Durability. These are the properties of a transaction.
For more information and explanation of these properties, see SQL Server books online or any
RDBMS fundamentals text book

SQL Server was originally developed by Sybase in the mid-


1980s and licensed to Microsoft until 1997. Even today,
most of the core technology in SQL Server is the same as
Sybase Adaptive Server Enterprise. Architecturally, Sybase
and Microsoft are very similar, and both use the Transact-
SQL dialect of SQL that is copyrighted by Sybase. To this
day, Sybase receives a royalty for every copy of SQL Server
sold.

Key architecture points:


1. Multi-threaded, scales to multiple processors
2. Main databases are master, model, tempdb
3. Each database has at least one data segment and one
log segment
4. Transaction log is used for rollback and recovery
Sql Server is having Physical database and logical database
in physical database-Filegroups,transcation log
Filegroups contains - datafiles
datafiels contains - tables
tables contains - Extents
Extents contains - pages
Pages contains - Rows
Trancastion log is user defined file group by default it is
primary file group,
Logical database objects like
storedprocedre,views,indexes,trigeers
19. Explain the storage models of OLAP

This tutorial covers the different types of OLAP models like Relational Online Analytical Processing
mode( ROLAP), Multidimensional Online Analytical processing mode(MOLAP) and Hybrid Online
Analytical Processing mode or HOLAP.
Sponsored Links
Cubes in a data warehouse are stored in three different modes. A relational storage model is called
Relational Online Analytical Processing mode or ROLAP, while a MultidimensionalOnline Analytical
processing mode is called MOLAP. When dimensions are stored in a combination of the two modes
then it is known as Hybrid Online Analytical Processing mode or HOLAP.

MOLAP

This is the traditional mode in OLAP analysis. In MOLAP data is stored in form
of multidimensionalcubes and not in relational databases. The advantages of this mode is
that it provides excellent query performance and the cubes are built for fast data retrieval.
All calculations are pre-generated when the cube is created and can be easily applied while
querying data. The disadvantages of this model are that it can handle only a limited amount
of data. Since allcalculations have been pre-built when the cube was created, the cube
cannot be derived from a large volume of data. This deficiency can be bypassed by including
only summary level calculations while constructing the cube. This model also requires huge
additional investment as cube technology is proprietary and the knowledge base may not
exist in the organization.

ROLAP

The underlying data in this model is stored in relational databases. Since the data is stored
in relational databases this model gives the appearance of traditional OLAP’s slicing and
dicing functionality. The advantages of this model is it can handle a large amount of data
and can leverage all the functionalities of the relational database. The disadvantages are
that the performance is slow and each ROLAP report is an SQL query with all the limitations
of the genre. It is also limited by SQL functionalities. ROLAP vendors have tried to mitigate
this problem by building into the tool out-of-the-box complex functions as well as providing
the users with an ability to define their own functions.

HOLAP

HOLAP technology tries to combine the strengths of the above two models. For summary
type information HOLAP leverages cube technology and for drilling down into details it uses
the ROLAP model.

Comparing the use of MOLAP, HOLAP and ROLAP

The type of storage medium impacts on cube processing time, cube storage and cube
browsing speed. Some of the factors that affect MOLAP storage are:
Cube browsing is the fastest when using MOLAP. This is so even in cases where no
aggregations have been done. The data is stored in a compressed multidimensional format
and can be accessed quickly than in the relational database. Browsing is very slow in ROLAP
about the same in HOLAP. Processing time is slower in ROLAP, especially at higher levels of
aggregation.

MOLAP storage takes up more space than HOLAP as data is copied and at very low levels of
aggregation it takes up more room than ROLAP. ROLAP takes almost no storage space as
data is not duplicated. However ROALP aggregations take up more space than MOLAP or
HOLAP aggregations.

All data is stored in the cube in MOLAP and data can be viewed even when the original data
source is not available. In ROLAP data cannot be viewed unless connected to the data
source.

MOLAP can handle very limited data only as all data is stored in the cube.

20. What are the ODBC drivers that are available for PostgreSQL?

psqlODBC is the official PostgreSQL ODBC Driver.

21. what is difference between generalization and normalization?


Aggregation: Selecting the data in group of records is called aggregation.

There are five aggregate system functions they are viz. Sum Min Max Avg Count. They all have their
own purpose Decomposition: Selecting all data without
any grouping and aggregate functions is called Decomposition. The data is selected as it is present in
the table.

Generalization: while generalization seems to be simplification of data i.e. to bring the data from Un-
normalized form to normalized form.

Data Generalization is the process of creating successive layers of summary data in an


evaluational database. It is a process of zooming out to get a broader view of a problem,
trend or situation. It is also known as rolling-up data
Data generalization can provide a great help in Online Analytical Processing (OLAP)
technology. OLAP is used for providing quick answers to analytical queries which are by
nature multidimensional. They are commonly used as part of a broader category of business
intelligence. Since OLAP is used mostly for business reporting such as those for sales,
marketing, management reporting, business process management and other related areas,
having a better view of trends and patterns greatly speeds up these reports.

Data generalization is also especially beneficial in the implementation of an Online


transaction processing (OLTP). OLTP refers to a class systems designed for managing and
facilitating transaction oriented applications especially those involved with data entry and
retrieval transaction processing. OLAP was created later than OLTP and had slight
modifications from OLTP.

22. What are concepts of oops?


Three of the most basic concepts for object oriented programming are Classes, Objects, and
Methods. However, there are a few more concepts that you will want to become familiar
with. These areInheritance, Abstraction, Polymorphism, Event, and Encapsulation.
Sponsored Links
In this article, I will be using the class Cats as an example. Inheritance will allow a sub-
group to make a connection with the associates of its parent class. For example, lets say the
class Cats decides to create a method called purr() and a property named Colorfur. As the
name implies, a property is a specific attribute which is connected to an object.

Every sub-group will be able to inherit the associates, and this means the developer only
needs to create the code for them one time. The traits that are inherited by the sub-group
can be changed. For example, the Persian cat class may choose to make the Colorfur white
for their default color. In contrast, another cat breed may choose a different Colorfur trait.
It is also possible for the sub-group to add new associates. If a specific cat Class sub-group
wants to set a default eye color, this can be inherited as well. Some object oriented
programming languages may also allow a class to inherit traits from multiple ancestors, and
this is called multiple inheritance. Some programs may not allow this.

The next concept that you will want to be familiar with is called
"abstraction." Abstraction can be defined as the process in which an application will ignore
the characteristics of a sub-group and work on a general level when it is needed. As an
example, Betsy the cat may be treated as a cat when it is necessary, but she may also be
processed as a Felidae, which is a superclass of cat family. Polymorphism is an important
concept of object oriented programming that you will want to become familiar. It can be
defined as a behavior which is dependent on the class to which it is connected. As an
example, if a Cat is sent a command to speak, this may cause it to purr, while a dog will
bark, or a lion may roar.

Anyone who is interested in object oriented programming will also need to know
encapsulation. Encapsulation will allow a class to hide information from objects that may
use the code. For example, the Cat class will have a purr() method. A code will be written
which will explain how the cat purrs. Despite this, it is not necessary for Betsy the cat to
know how she purrs. Encapsulation makes it easier for the developer to change the code
without having to change the code for Betsy. When the structure of class is hidden, it is
harder for it to be used in the wrong way.

Encapsulation will basically state which class is allowed to use the members of a certain
object. This concept makes it easier for programmers to deal with or avoid errors when
developing a program. The members within OOP can be categorized as being protected,
public, or private. The last concept that you will want to become familiar with is called an
event. An event can simply be defined as anything that happens to an object. Generally, an
event is something that will cause the object to react with a method. Another term that
advanced programmers may run into is called multiple inheritance. It is a situation where a
class is able to inherit traits from a number of different superclasses.

A multiple inheritance can create a number of perplexing situations. Because of this, there is
debate in the programming community about whether it is beneficial or risky. One example
of a program which deals with multiple inheritances is Java.

23. what is the correct meaning of primary key?


24. storein charge
25. How do you verify the name of the database

dbv
The Database Verify utility (dbv) provides a mechanism to
validate the structure of Oracle data files at the operating
system level. It should be used on a regular basis to
inspect data files for signs of corruption.

Although it can be used against open data files, the


primary purpose of dbv is to verify the integrity of cold
datafiles that would be used for a backup. If used against
online datafiles, intermittent errors can occur and the
utility should be executed again against the same file to
verify accuracy. The utility can only be used against
datafiles however, not control files or archived redo logs.

dbv Command Line Options

• File – The name of the Oracle datafile to verify. The


file must be specified with full path name and file
name including extension (.dbf).
26. how to store images in oracle Database
intercept the datastream coming in from the client, save it into a byte array, and store that into a
BLOB in the database.

I once had a databse with over 800,000 signature images.


There are two approaches:
1. store the image in an Oracle 'blob' type field;
2. store the image somewhere in the file system and store the path name in the db. use the pathname to
retrieve the image.
we used option #2.

try{

File fileObject = new File("img path");


FileInputStream fisObject = new FileInputStream(fileObject);
PreparedStatement pstmt =
conn.prepareStatement("insert into IMG_TABLE values (?,?)");
pstmt.setString(1,fileObject.getName());
pstmt.setBinaryStream(2,fisObject,(int)fileObject.length());
pstmt.executeUpdate();

}
catch(SQLException se)
{
se.printStackTrace();
}
catch(Exception ee)
{
ee.printStackTrace();
}
To insert images into a database, the database must support images. Images are stored in binary in a
table cell. The data type for the cell is a binary large object (BLOB), which is a new SQL type in SQL3
for storing binary data. Another new SQL3 type is character large object (CLOB), for storing a large text
in the character format. JDBC 2 introduced the interfaces java.sql.Blob and java.sql.Clob to support
mapping for these new SQL types. JBDC 2 also added new methods, such as getBlob, setBinaryStream,
getClob, setBlob, and setClob, in the interfaces ResultSet, PreparedStatement, and CallableStatement,
to access SQL BLOB and CLOB values.

To store an image in a cell in a table, the corresponding column for the cell must be of the BLOB type.
For example, the following SQL statement creates a table whose type for the flag column is BLOB:

create table Country(name varchar(30), flag blob,


description varchar(500));
In the preceding statement, the description column is limited to 500 characters. The upper limit for
the VARCHAR type is 32,672 bytes. For a large character field, you can use the CLOB type, which can
store up to 2GB characters.

To insert a record with images to a table, define a prepared statement like this one:

PreparedStatement pstmt = connection.prepareStatement(


"insert into Country values(?, ?, ?)");

Images are usually stored in files. You may first get an instance of InputStream for an image file and
then use the setBinaryStream method to associate the input stream with cell in the table, as follows:

// Store image to the table cell


File file = new File(imageFilenames[i]);
InputStream inputImage = new FileInputStream(file);
pstmt.setBinaryStream(2, inputImage, (int)(file.length()));

To retrieve an image from a table, use the getBlob method, as shown here:

// Store image to the table cell


Blob blob = rs.getBlob(1);
ImageIcon imageIcon = new ImageIcon(
blob.getBytes(1, (int)blob.length()));
27. who can create a database without query?

28. what is the difference between MS Access and SQL server?

SQl Server is a server based database. Access is used as local database.Access is used for small
desktop size databases used by less then 5 users at the same time. It has a front end gui system to
design applications quickly. SQL Server is a more robust system and is able to handle large amounts
of users as well as data sizes. There is no front end gui system so it will require other development
tools (Visual Studios, .NET, VB, C++, ect.).

Access is intended more for end-user(s), as it's an all-inclusive package. It's mainly for one use at a
time, but it does support multiple users, albeit in a clunky roundabout way. Remember, it is a tool in
MS Office.

MS SQL Server is an actual SQL database. It's designed to sit on a server an act as the database
for whatever front-end you wish to put on it. It's mainly for multiple users and intended to be
centralized.

MS Access is actually a combination of a rapid development UI tool and file system based relational
database (JET).
MS SQL Server is a Client-server relational database system, with no UI development tools built in.
29. How can I get the heading of a report to appear on every page?
Sql reporting service,crystalreports.
The Report Header is only displayed once, at the very beginning of a report.

There is a page header section in the report that you can use when you want that to repeat
on every page. You can turn off repeat on first and last page for the page header using the 2
properties that the page header supports. There is no report header in RDL.

If you only want the header to show on the first page, you cannot use the page header. To
get that affect, you can place a rectangle at the top of your report body and put any
information you want in it. The rectangle will only show on the first page and can act as a
page header for you.

Hope this helps,

30. How do I email just one report in my database?

In exceldatabase using mailmerge !

31. How do I password protect my Access database?


Password protecting an Access database allows you to protect your sensitive data from prying eyes. In
this tutorial, we walk you through the process of encrypting your database and protecting with a
password, step by step.

We'll need to open the database using a special procedure to ensure there are no other users. The first
step is to click the Microsoft Office button, as shown in the image above.

Note that this feature is only available if you're using Microsoft Office Access 2007 and your database
is in ACCDB format.

Next, choose Open from the Office menu. Please read the next step before opening your database. We
need to open it in a special way to ensure that it's ready for encryption. This process is shown in the
image above.

Navigate to the database you'd like to encrypt and then click it once. Then, instead of just clicking the
Open button, click the downward arrow icon to the right of the button, as shown in the image above.
Choose "Open Exclusive" to open the database in exclusive mode.

From the Database Tools tab, double-click on the "Encrypt with Password" option, as shown in the
image above
Choose a strong password for your database and enter it in both the Password and Verify boxes in the
Set Database Password dialog box, as shown in the image above. Once you've done this, click OK.

That's all there is to it. After clicking OK, your database will be encrypted. (This may take a while
depending upon the size of your database). The next time you open your database, you'll be prompted
to enter the password before accessing it.

32. I am using the Switchboard Manager in MS Access. I am getting an error message "...

The Switchboard manager in MS Access offers only limited information on errors that occur within the
database. Execute the selection directly from the database window to get more detailed information on
the error.

Verifiaction:Means are we doing right thing.i.e we have to

check whether we are implementing right process.

validation:Means are we doing things right.i.e we have to

check whether we have developed a software as per the

client requirement.
Verification ensures that the application complies to
standards and processes. This answers the question " Did we
build the right system? "

Eg: Design reveiws, code walkthroughs and inspections.

Validation ensures whether the application is built as per


the plan. This answers the question " Did we build the
system in the right way? ".

Eg: Unit Testing, Integration Testing, System Testing and


UAT.
erification-

1 it emphasize on building the product right.


2 it is a low level activity.
3 it only checks the correspondence between a program and
its specification.
4 we do the Defect Testing to uncover errors.
validation-

1 it emphasize on building the right product.


2 it is a high level activity.
3 it checks that whether the software is operationelly
useful or not.
4 we do the Validation Testing to meet the customer
requirements.

You might also like