Saturday 31 December 2011

What is an instruction set?


  • The complete collection of instructions that are understood by a CPU

  • Machine Code

  • Binary

  • Usually represented by assembly codes


Elements of an Instruction



  • Operation code (Op code)

  • Source Operand reference

  • Result Operand reference

  • Next Instruction Reference


Instruction Cycle State Diagram



Instruction Representation



  • In machine code each instruction has a unique bit pattern

Friday 30 December 2011

Polymorphism in Java

Polymorphism means "any forms." In object-oriented programming, it refers to the capability of objects to react differently to the same method. Polymorphism can be implemented in the Java language in the form of multiple methods having the same name. Java code uses a late-binding technique to support polymorphism; the method to be invoked is decided at runtime.

Overloaded methods are methods that have the same name, but different argument lists. Overriding, on the other hand, occurs when a subclass method has the same name, same return type, and same argument list as the superclass method.

Overloading


As we mentioned, it is mandatory for overloaded methods to have the same names but different argument lists. The arguments may differ

APPSC Group-2 Previous Questions - 2

21. The local name of Mohenjodaro is

1. Mound of the Great                2. Mound of the living


3. Mound of the Survivor          4. Mound of the Dead


22. Name the ruler of the Kushan dynasty.

1. Kadphises I                          2. Ugrasena


3. Vikramaditya                          4. Pushyamitra


23. The title 'Vikramaditya' was assumed by

1. Ashoka                                      2. Kanishka


3. Samudragupta                        4. Chandragupta II


24. The great granary of the Harappan civilisation has been found at

1. Ropar           2. Harappa           3. Kalibangan        4. Mohenjodaro


25. When did Alexander invade India ?

Why Yoga ?

Yoga is a way of life and enables us to have multidimensional approach to life. The human body is not the aim of yoga but is considered means of going beyond physical form of body. Unbalanced state of cause and effect result in ill health. Equilibrium of two is the basic aim of Yoga. A healthy body, therefore may be called as the foundation of Yoga.

Yoga is both an art and science. It can alone save the modern man from personal determination and circumstantial frustration. In other words the practice of 'Yoga' postulates keeping the body healthy and the mind calm and peaceful. Health is our birth-right, and to remain healthy, it is not necessary to depend upon any health centre, physician or medication. It is entirely in our hands to keep healthy. However, in the present-day conditions keeping good health is

Thursday 29 December 2011

Performance of Sorting or Searching

One of the chief concerns in searching and sorting is speed. Often, this concern is misguided, because the sort or search takes negligible time compared to the rest of the program. For most sorting and searching applications, you should use the easiest method available . If you later find that the program is too slow because of the searching or sorting algorithm used, you can substitute another method easily. By starting with a simple method, you haven’t invested much time and effort on code that has to be replaced.

One measure of the speed of a sorting or searching algorithm is the number of operations that must be performed in the best, average,

APPSC Group-1 Prelims Previous Questions

1. The hill ranges between Narmada and Tapti rivers are

1. Aravalli          2. Vindhya          3. Kalmur           4. Satpura


2. The Land of Thousand lakes is in

1. England          2. Finland        3. Canada           4. Korea


3. The violent and destructive tropical cyclones in China and Japan are known as

1. Hurricanes    2. Tornadoes        3. Typhoons    4. Willy-willies


4. 'Stalagmites and Stalactites' are the landforms formed due to

1. Wind              2. Glaciers              3. Rivers           4. Ground water


5. Jurala Project is situated in the district of

Wednesday 28 December 2011

Frequently Asked Questions in Technical Round at MNCs like TCS, WIPRO, INFOSYS,..etc

Predict the output or error(s) for the following:


1)

main()

{

int i=1;


while (i<=5)


{


printf("%d",i);


if (i>2)


goto here;


i++;


}


}

fun()

{

here:


    printf("PP");


}

Answer:

Compiler error: Undefined label 'here' in function main


Explanation:

Tuesday 27 December 2011

DotNet Frequently Asked Questions on Threading

What does AddressOf operator do in background ?


The AddressOf operator creates a delegate object to the BackgroundProcess method. A delegate within VB.NET is a type-safe, object-oriented function pointer. After the thread has been instantiated, you begin the execution of the code by calling the Start() method of the thread.

How can you reference current thread of the method ?


"Thread.CurrentThread" refers to the current thread running in the method."CurrentThread" is a public static property.

What's Thread.Sleep() in threading ?


Thread's execution can be paused by calling the Thread.Sleep

Civil Services Preliminary Previous Questions

1. In the 'Individual Satyagraha', Vinoba Bhave was chosen as the first Satyagrahi. Who was the second ?

1. Dr. Rajendra Prasad
2. Pandit Jawaharlal Nehru
3. C. Rajagopalachari
4. Sardar Vallabhai Patel


2. Consider the following statements:

The Cripps Proposals include the provision for
a. Full independence for India.
b. Creation of Constitution-making body.


Which of the statements given above is / are correct ?

1. a only        2. b only        3. Both a and b        4. Neither a nor b


3. During the freedom struggle, Aruna Asaf Ali was a major woman organizer of underground activity in

1. Civil Disobedience Movement
2. Non-Cooperation Movement
3. Quit India Movement
4. Swadeshi Movement


4. With whose permission did the English set up their first factory in Surat ?

1. Akbar        2. Jahangir         3. Shahjahan          4. Aurangzeb


5. In a dry cell (battery), which of the following are used as elecrolytes ?

Monday 26 December 2011

APPSC Group-2 Previous Questions

1. The first India-Russsia-China trilateral business conference was held in

1. New Delhi         2. Moscow        3. Beijing        4. Guwahati


2. Ban Ki-Moon took over as United Nations Secretary-General on

1. July 1 ,2006      2. January 1, 2007      3. July 1, 2008       4. January 1,2008


3. India's Communications satellite INSAT-4B was launched from

1. Thumba        2. Biakonur       3. Sriharikota       4. French Guiana


4.The Central Salt and Marine Chemicals Research Institute is situated in

1. West Bengal    2. Orissa          3. Gujarat         4. Andhra Pradesh


5. The institute produced by the Uruguay Round of talks is

Floating point representation

The floating point representation of a number has two parts. The first parts represent a signed, fixed- point number called the mantissa. The second part designates the position of the decimal point and is called the exponent. The fixed-point mantissa may be a fraction or an integer. For example, the decimal number +6132.789 is represented in floating-point with a fraction and an exponent as follows:

Fraction                 Exponent


+0.6132789          +04


This representation is equivalent to the scientific notation +0.6132789*10^+4.

Floating –point is always interpreted to represent a number in the following form:

M*r ^e


Only the mantissa m and the exponent e are physically represented in

Sunday 25 December 2011

Encapsulation in Java

Encapsulation is the concept of hiding the implementation details of a class and allowing access to the class through a public interface. For this, we need to declare the instance variables of the class as private or protected. The client code should access only the public methods rather than accessing the data directly. Also, the methods should follow the Java Bean's naming convention of set and get.

Encapsulation makes it easy to maintain and modify code. The client code is not affected when the internal implementation of the code

APPSC Group-1 General Studies Previous Questions

1. The Supreme Court of Bengal was constituted by the Crown in the year

1. 1776         2. 1777          3. 1774           4. 1775


2. In which year did Gandhiji come actively on the political scene ?

1. 1916         2. 1919          3. 1930          4. 1932


3. The 'Sri Bagh Pact' (Sri Bagh Agreement) concluded on 16th November 1937 was between

1. Andhra - Rayalaseema - Telangana


2. Andhra - Telangana


3. Andhra - Hyderabad


4. Andhra - Rayalaseema


4. The Rampa rebellion happened during

1. 1922 - 1924        2. 1919 - 1920        3. 1921 -1922        4. 1925 - 1926


5. The Provincial Governments were given more powers under the system of Dyarchy by

Saturday 24 December 2011

Searching - Brief Idea

Searching algorithms have been studied nearly as much as sorting algorithms. The two are related in that many searching algorithms rely on the ordering of the data being searched. There are four basic kinds of searching algorithms:

  • Sequential searching

  • Comparison searching

  • Radix searching

  • Hashing


Each of these methods can be described using the same deck of cards example that was used for sorting.

In sequential searching, you go through the deck from top to bottom, looking at each card until you find the card you are looking for.

In comparison searching (also called binary searching), you start with

Friday 23 December 2011

Predict the output or error(s) for the following:

1)

main()

{

printf("%p",main);


}

Answer:

Some address will be printed.


Explanation:

Function names are just addresses (just like array names are addresses).


main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers.

2)

main()

{

clrscr();


}

clrscr();

Answer:

No output/error


Explanation:

Thursday 22 December 2011

Threading in DotNet

What is Multi-tasking ?


It’s a feature of modern operating systems with which we can run multiple programs at same time example Word, Excel etc.

What is Multi-threading ?


Multi-threading forms subset of Multi-tasking. Instead of having to switch between programs this feature switches between different parts of the same program. Example you are writing in word and at the same time word is doing a spell check in background.

What is a Thread ?


A thread is the basic unit to which the operating system allocates processor time.

Did VB support multi-threading ?


While VB supports multiple single-threaded apartments, it does not support a freethreading model, which allows multiple threads to run against the same set of data.

Can we have multiple threads in one App domain ?


One or more threads run in an AppDomain. An AppDomain is a

Wednesday 21 December 2011

Arithmetic & Logic Unit


  • Does the calculations

  • Everything else in the computer is there to service this unit

  • Handles integers

  • May handle floating point (real) numbers

  • May be separate FPU (maths co-processor)

  • May be on chip separate FPU (486DX +)


ALU Inputs and Outputs



Integer Representation



  • Only have 0 & 1 to represent everything

  • Positive numbers stored in binary


—   e.g. 41=00101001




  • No minus sign

  • No period

  • Sign-Magnitude

  • Two’s compliment


Sign-Magnitude

Tuesday 20 December 2011

What will be the result of compiling and running the following code fragment?

Integer i= new Integer("10");

if (i.toString() == i.toString())

System.out.println("Equal");


else

System.out.println("Not Equal");


Choices:

A. Compiler error
B. Prints "Equal"
C. Prints "Not Equal"
D. None of the above


Correct choice:

  • C


Explanation:

Monday 19 December 2011

Brief idea about Sorting

Five basic kinds of sorting algorithms are available to the programmer:

  • Insertion sorts

  • Exchange sorts

  • Selection sorts

  • Merge sorts

  • Distribution sorts


An easy way to visualize how each sorting algorithm works is to think about how to sort a shuffled deck of cards lying on the table using each method. The cards are to be sorted by suit (clubs, diamonds, hearts, and spades) as well as by rank (2 through ace). You might have seen some of these algorithms in action at your last bridge game.

In an insertion sort, you pick up the cards one at a time, starting with the top card in the pile, and insert them into the correct position in

Predict the output or error(s) for the following:

1)

#include <stdio.h>

#define a 10

main()

{

#define a 50


printf("%d",a);


}

Answer:

50


Explanation:

Saturday 17 December 2011

What are types of compatibility in VB?

There are three possible project compatibility settings:

  • No Compatibility

  • Project Compatibility

  • Binary Compatibility


No Compatibility


With this setting, new class ID’s, new interface ID’s and a new type library ID will be generated by VB each time the ActiveX component project is compiled. This will cause any compiled client components to fail (with error 429!) and report a missing reference to the 'VB ActiveX Test Component' when a client project is loaded in the VB IDE.

Note :- Use this setting to compile the initial release of a component to other developers.



Project Compatibility


With this setting, VB will generate new interface ID’s for classes

Friday 2 December 2011

Is it acceptable to declare/define a variable in a C header?

A global variable that must be accessed from more than one file can and should be declared in a header file. In addition, such a variable must be defined in one source file. Variables should not be defined in header files, because the header file can be included in multiple source files, which would cause multiple definitions of the variable. The ANSI C standard will allow multiple external definitions, provided that there is only one initialization. But because there’s really no advantage to using this feature, it’s probably best to avoid it and maintain a higher level of portability.

“Global” variables that do not have to be accessed from more than

Thursday 1 December 2011

The equals() method

We can use the == operator to compare the values of primitive variables and determine if they are equal. However, if object reference variables are compared using the == operator, it returns true only if the reference variables are referring to the same object. To check for the equality of two objects, the Object class provides the equals(Object obj) method, which can be overridden to return true for logically equal objects. The default implementation of the equals() method in the Object class returns true only if an object is

Wednesday 30 November 2011

How do you do object pooling in .NET ?

COM+ reduces overhead by creating object from scratch. So in COM+ when object is activated its activated from pool and when its deactivated it’s pushed back to the pool. Object pooling is configures by using the “ObjectPoolingAttribute” to the class.

Note:- When a class is marked with objectpooling attribute it can not be inherited.


ObjectPooling(MinPoolSize := 2, MaxPoolSize := 5, CreationTimeout := 20000)> _
Public Class testingclass

Tuesday 29 November 2011

Predict the output or error(s) for the following:

main()

{

char *p="hai friends",*p1;


p1=p;


while(*p!='\0') ++*p++;


printf("%s   %s",p,p1);


}

Answer:

ibj!gsjfoet


Explanation:

What is a Bus?


  • A communication pathway connecting two or more devices

  • Often grouped


---- A number of channels in one bus


---- e.g. 32 bit data bus is 32 separate single bit channels


Data Bus :

  • Carries data


---- Remember that there is no difference between “data” and “instruction” at this level.




  • Width is a key determinant of performance


---- 8, 16, 32, 64 bit



Address bus :



  • Identify the source or destination of data


e.g. CPU needs to read an instruction (data) from a given

Monday 28 November 2011

Operators and assignments

Using operators - 2


Increment and decrement operators


Two shortcut arithmetic operators are ++, which increments its operand by 1, and --, which decrements its operand by 1.

  • ++ increment operator (increments value by 1)

  • -- decrement operator (decrements value by 1)


These operators can appear before the operand (prefix) or after the operand (postfix). In the case of the prefix style, the value of the operand is evaluated after the increment/decrement operation. For postfix, the value of the operand is evaluated before the

Operators and assignments

Using operators - 1


Assignment operators


You can assign a primitive variable using a literal or the result of an expression. The result of an expression involving integers (int, short, and byte) is always at least of type int. Narrowing conversions are not allowed, as they would result in the loss of precision. For instance:

byte b = 5;
byte c = 4;
byte d = b + c;               // does not compile because int cannot fit in a byte


float f = (float)35.67;   // implicitly double, so casting to float
float f = 35.67F;


A boolean cannot be assigned any type other than boolean.

If we assign an existing object reference to a reference variable, both reference variables refer to the same object. It is legal to assign

Sunday 27 November 2011

What is operator promotion?

If an operation is specified with operands of two different types, they are converted to the smallest type that can hold both values. The result has the same type as the two operands wind up having. To interpret the rules, read the following table from the top down, and stop at the first rule that applies.

The following example code illustrates some cases of operator

Are there any problems with performing mathematical operations on different variable types?

C has three categories of built-in data types: pointer types, integral types, and floating-point types.

Pointer types are the most restrictive in terms of the operations that can be performed on them. They are limited to

" -  " subtraction of two pointers, valid only when both pointers point to elements in the same array. The result is the same as subtracting the integer subscripts corresponding to the two pointers.

" + " addition of a pointer and an integral type. The result is a

Saturday 26 November 2011

How many types of Transactions are there in COM + .NET ?

There are 5 transactions types that can be used with COM+. Whenever an object is registered with COM+ it has to abide either to these 5 transaction types.

Disabled: - There is no transaction. COM+ does not provide transaction support for this component.

Not Supported: - Component does not support transactions. Hence even if the calling component in the hierarchy is transaction

How to implement DTC in .NET ?

DTC is implemented using COM+.

Following are the steps to implement COM + in .NET :-

  • “EnterpriseService” namespace has all the classes by which we can implement DTC in .NET. You have to add reference “EnterpriseService” namespace.


Add reference to EnterpriseServices.




  • Your class must derive from “Serviced Component” object.

  • Then you have to define your class with the transaction attribute (For all transaction attribute look the down

Friday 25 November 2011

What will be the result of compiling and running the following program

public class Test
{

static int i;
static public void main(String[] args)
{


do
{


System.out.println(args[++i]);


} while (i < args.length);


}


}

Choices:
A. Prints "hello"
B. Prints "Test"
C. Code does not compile
D. Throws an ArrayIndexOutOfBoundsException

Correct choice:

  • D


Explanation:

Interrupts

Mechanism by which other modules (e.g. I/O) may interrupt normal sequence of processing

  • Program


e.g. overflow, division by zero

  • Timer :Generated by internal processor timer


Used in pre-emptive multi-tasking I/O from I/O controller

  • Hardware failure


e.g. memory parity error

Interrupt Cycle :



  • Added to instruction cycle

  • Processor checks for interrupt


          ---Indicated by an interrupt signal




  • If no interrupt, fetch next instruction

  • If interrupt pending:


         ---Suspend execution of current program

Thursday 24 November 2011

Can you explain what is DCOM ?

DCOM differs from COM in that it allows for creating objects distributed across a network, a protocol for invoking that object’s methods, and secures access to the object. DCOM provides a wrapper around COM, hence it is a backwards compatible extension. DCOM uses Remote Procedural Calls (RPC) using Open Software Foundation’s Distributed Computing Environment.

These RPC are implemented over TCP/IP and named pipes. The protocol which is actually being used is registered just prior to use, as opposed to being registered at initialization time. The reason for

What is Reference counting in COM ?

Reference counting is a memory management technique used to count how many times an object has a pointer referring to it. The first time it is created, the reference count is set to one. When the last reference to the object is nulled, the reference count is set to zero and the object is deleted. Care must be exercised to prevent a context switch from changing the reference count at the time of deletion. In the methods that follow, the syntax is shortened to keep

Wednesday 23 November 2011

Literals in Java

Integer literals can be decimal, octal, or hexadecimal.

Octal literals begin with zero and only digits 0 through 7 are allowed. For instance:

011


Hexadecimal literals begin with 0x or oX, the digits allowed are 0 through 9 and a through f (or A through F). For instance:

0x0001;


All integer literals are of type int by default. To define them as long, we can place a suffix of L or l after the number.

For char literals, a single character is enclosed in single quotes. You can also use the prefix \u followed by four hexadecimal digits

Java keywords and identifiers

Keywords are reserved words that are predefined in the language; see the table below. All the keywords are in lowercase.

Note: assert is a new keyword since J2SE 1.4

An identifier is composed of a sequence of characters where each

How can you determine the maximum value that a numeric variable can hold?

The easiest way to find out how large or small a number that a particular type can hold is to use the values defined in the ANSI standard header file limits.h. This file contains many useful constants defining the values that can be held by various types, including these:

For integral types, on a machine that uses two’s complement

How reliable are floating-point comparisons?

Floating-point numbers are the “black art” of computer programming. One reason why this is so is that there is no optimal way to represent an arbitrary number. The Institute of Electrical and Electronic Engineers (IEEE) has developed a standard for the representation of floating-point numbers, but you cannot guarantee that every machine you use will conform to the standard.

Even if your machine does conform to the standard, there are deeper issues. It can be shown mathematically that there are an infinite number of “real” numbers between any two numbers. For the computer to distinguish between two numbers, the bits that

Tuesday 22 November 2011

Computer Components:

Top Level View



Instruction Cycle :

The IAS computer operated by a repetitively performing an instruction cycle .Each instruction cycle consists of two sub cycles.

  1. Fetch Cycle

  2. Execute Cycle


Basic Instruction cycle:

Fetch Cycle :

During the Fetch cycle, the opcode of the next instruction is loaded

What is COM ?

Microsoft’s COM is a technology for component software development. It is a binary standard which is language independent. DCOM is a distributed extension of COM.

When we use windows API in .NET is it managed or unmanaged code?

Windows API in .NET is unmanaged code.

Note:- Even though VB6 and V C++ has gone off still many people do ask these old questions again and again. Still there are decent old application which are working with COM very much fine. So interviewer still asks you these questions so that those application’s can be ported to .NET. So let’s play some old music...

How can we make Windows API calls in .NET?

Windows API calls are not COM based and they are invoked through Platform Invoke Services.

Declare StringConversionType (Function | Sub) MethodName Lib "DllName" ([Args]) As Type

  • StringConversionType is for what type of conversion should take place. Either we can specify Unicode to convert all strings to Unicode values, or Auto to convert strings according to the .NET runtime rules.

  • MethodName is the name of the API to call.

  • DllName is the name of the DLL.

  • Args are any arguments to the API call.

  • Type is the return type of the API call.


Below is a sample code for VB.NET which uses Sleep windows API

Sunday 20 November 2011

Saving a file for older versions of Microsoft Office

If you need to share files with people using older versions of Microsoft Office, you need to save your files in a different file format known as 97-2003, such as Word 97-2003 Document or PowerPoint 97-2003 Presentation.

This special 97-2003 file format saves Office 2007 files so that previous versions of Microsoft Office 97/2000/XP/2003 can open and edit your files.

When you save files in the 97-2003 format, Microsoft Office 2007 saves your files with a three-letter file extension, like .doc or .xls. When you save files in the Office 2007 format, Microsoft Office

Saturday 19 November 2011

Sun Certified Java Programmer (SCJP)

Interfaces


An interface is like a public class that has only abstract and public methods. The variables declared in an interface are implicitly public, static, and final. For instance:

interface MyInterface
{


void f();


}


class MyClass implements MyInterface
{


public void f() {}


}


A concrete class implementing an interface has to implement all the methods declared in it.

Interface methods are implicitly public and cannot be declared

Sun Certified Java Programmer (SCJP)

Language fundamentals


Package and class declarations


A package represents a group of classes. A package statement should be the first valid statement in the source file. If there is no package statement, the classes in the source file belong to the default unnamed package, or else they belong to the named package. Only one package statement is allowed in a source file.

In a source file, there can be only one public class, and the name of the file should match that of the class. An import statement allows

Friday 18 November 2011

Classify the Hashing Functions based on the various methods by which the key value is found.


  • Direct method,

  • Subtraction method,

  • Modulo-Division method,

  • Digit-Extraction method,

  • Mid-Square method,

  • Folding method,

  • Pseudo-random method.

Sort the given values using Quick Sort :

Sorting takes place from the pivot value, which is the first value of the given elements, this is marked bold. The values at the left pointer and right pointer are indicated using L and R respectively.

Since pivot is not yet changed the same process is continued after

Predict the output or error(s) for the following:

const int size = 5;

void print(int *ptr)

{

cout<<ptr[0];


}

void print(int ptr[size])

{

cout<<ptr[0];


}

void main()

{

int a[size] = {1,2,3,4,5};


int *b = new int(size);


print(a);


print(b);


}

Answer:

Compiler Error : function 'void print(int *)' already has a body

Explanation:

Predict the output or error(s) for the following:

void main()

{

int a, *pa, &ra;


pa = &a;


ra = a;


cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;


}

Answer :

Compiler Error: 'ra',reference must be initialized


Explanation :

Thursday 17 November 2011

When should the const modifier be used?

There are several reasons to use const pointers. First, it allows the compiler to catch errors in which code accidentally changes the value of a variable, as in

while (*str = 0) /* programmer meant to write *str != 0 */
{


/* some code here */
str++;


}


in which the = sign is a typographical error. Without the const in the declaration of str, the program would compile but not run properly.

Another reason is efficiency. The compiler might be able to make

Once I have developed the COM wrapper do I have to still register the COM in registry?

Yes.

How can we use .NET components in COM?

What is CCW (COM callable wrapper) ?


How do we ensure that .NET components is compatible with COM ?


.NET components can not be used in straight forward way with COM. You will need to create CCW in order that COM components communicate with .NET assemblies. Following are the different approaches to implement it :-

Wednesday 16 November 2011

Predict the output or error(s) for the following:

 #include<stdio.h>

main()

{

struct xx


{


int x;


struct yy


{


char s;


 struct xx *p;


};


struct yy *q;


};


}

Answer:

Compiler Error


Explanation:

How can we use COM Components in .NET?

.NET components communicate with COM using RCW (Runtime Callable Wrapper). Following are the ways with which you can generate RCW :-

  • Adding reference in Visual Studio.net. See figure below. Wrapper class is generated and placed in the “BIN” directory.


Adding Reference using VS.NET




  • Using Type library import tool. Tlbimp.exe yourname.dll.

  • Using interopservices.System.runtime.Interopservices

Monday 14 November 2011

How Gateway is different from Routers?

A gateway operates at the upper levels of the OSI model and translates information between two completely different network architectures or data formats.

A router is a device in computer networking that forwards data packets to their destinations, based on their addresses.

What is passive topology?

When the computers on the network simply listen and receive the signal, they are referred to as passive because they don’t amplify the signal in any way. Example for passive topology - linear bus.

Predict the output or error(s) for the following:

class base

{

        public:


            virtual void baseFun(){ cout<<"from base"<<endl;}


        };

class deri:public base

{

        public:


            void baseFun(){ cout<< "from derived"<<endl;}


        };

void SomeFunc(base *baseObj)

{

        baseObj->baseFun();


}

int main()

{

base baseObject;


SomeFunc(&baseObject);


deri deriObject;


SomeFunc(&deriObject);


}

Answer:

            from base


            from derived


Explanation:

Predict the output or error(s) for the following:

class base

{

public:


void baseFun(){ cout<<"from base"<<endl;}


};

class deri:public base

{

public:


void baseFun(){ cout<< "from derived"<<endl;}


};

void SomeFunc(base *baseObj)

{

baseObj->baseFun();


}

int main()

{

base baseObject;


SomeFunc(&baseObject);


deri deriObject;


SomeFunc(&deriObject);


}

Answer:

from base


from base


Explanation:

Sunday 13 November 2011

Sun Certified Java Programmer (SCJP)

How many objects will be eligible for garbage collection after line 7?


public class TutorialGC
{


public static void main(String [] args)
{


Object a = new Integer(100);   // Line1
Object b = new Long(100);       // Line2
Object c = new String("100");  // Line3
a = null;                                        // Line4
a = c;                                             // Line5
c = b;                                             // Line6
b = a;                                             // Line7
// Rest of the code here


}


}



Choices:



  • A. 0

  • B. 1

  • C. 2

  • D. 3

  • E. Code does not compile


Correct choice:



  • B


Explanation:

Sun Certified Java Programmer (SCJP)

Garbage collection


Finalization


Java technology allows you to use the finalize() method to do the necessary cleanup before the garbage collector removes the object from memory. This method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. It is defined in the Object class, thus it is inherited by all classes. A subclass overrides the finalize() method to

Sun Certified Java Programmer (SCJP)

Garbage collection


Eligibility for garbage collection


An object is eligible for garbage collection when no live thread can access it.

An object can become eligible for garbage collection in different ways:

  • If the reference variable that refers to the object is set to null, the object becomes eligible for garbage collection, provided that no other reference is referring to it.

  •  If the reference variable that refers to the object is made to refer to some other object, the object becomes eligible

Sun Certified Java Programmer (SCJP)-10

Garbage collection


Behavior of the garbage collector


A Java programmer does not have to worry about memory management, because it is automatically taken care of by the garbage collector. The Java virtual machine (JVM) decides when to run the garbage collector. The garbage collector is a low priority thread that runs periodically, releasing memory used by objects that are not needed anymore.

The garbage collection (GC) algorithm varies from one JVM to another. There are different algorithms being used, like reference

Friday 11 November 2011

Predict the output or error(s) for the following:

#include<stdio.h>

main()

{

struct xx


{


      int x=3;


      char name[]="hello";


 };


struct xx *s;


printf("%d",s->x);


printf("%s",s->name);


}

Answer:

Compiler Error


Explanation:

Predict the output or error(s) for the following:

#include<stdio.h>

main()

{

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8}  };


int *p,*q;


p=&a[2][2][2];


*q=***a;


printf("%d----%d",*p,*q);


}

Answer:

SomeGarbageValue---1

Explanation:

Tuesday 8 November 2011

Write a program to print Pascal triangle

Algorithm:

 Step1:         start

Step2:         initialize binom =1, f=0

Step3:         check the condition f<p

Step4:         for r=40-3*f;r>0; --r

Step5:         print" "

Step6:         for x=0; x<f; ++x

Step7:         if x == 0 or f==0

          Binom = 1


Step8:         else

          Binom=(bimom*(f-x+1)/x


          Printf binom


Step9:         stop

 

Program:

Write a Program to find Armstrong number

Algorithm:

Step1:         start

Step2:         read the number

Step3:         while n!=0 calculate sum+pow(n%10,3);

          Else


          Goto 5


Step4:         n=n/10 goto 3

Step5:         if sum==n print the no is armstrong else goto 6

Step6:         print the no is not prime

Step7:         stop

 

Program:

Can a variable be both const and volatile?

Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the above example, the timer structure was accessed through a volatile const pointer. The function itself did not change the value of the timer, so it

When should the volatile modifier be used?

The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the volatile modifier is desirable. The first case involves memory-mapped hardware (a device such as a graphics adaptor that appears to the computer’s hardware as if it were part of the computer’s memory), and the second involves shared memory (memory used by two or more programs running simultaneously).

Most computers have a set of registers that can be accessed faster than the computer’s main memory. A good compiler will perform a

Monday 7 November 2011

What is CodeDom?

“CodeDom” is an object model which represents actually a source code. It is designed to be language independent - once you create a “CodeDom” hierarchy for a program we can then generate the source code in any .NET compliant language. So let’s try to do something real practical and simple to just get a feel of how powerful “CodeDom” is.

Note :- You can get the source code in CD in “CodeDom” folder.


We will try to generate the following code below. The below code

If we have two version of same assembly in GAC how do we make a choice ?

OK first let’s try to understand what the interviewer is talking about. Let’s say you have made an application and its using a DLL which is present in GAC. Now for some reason you make second version of the same DLL and put it in GAC. Now which DLL does the application refer? Ok by default it always uses the version by which you have compiled you application in IDE. But you want that it should actually use the older version.

So first we answer in short. You need to specify “bindingRedirect” in your config file. For instance in the below case “ClassLibraryVersion” has two versions “1.1.1830.10493” and “1.0.1830.10461” from

Sunday 6 November 2011

Saturday 5 November 2011

Sun Certified Java Programmer (SCJP)-9

What will be printed out if you attempt to compile and run the following code?

int i = 3;
switch (i)
{


default:


System.out.println("default");


case 0:


System.out.println("zero");


case 1:


System.out.println("one");
break;


case 2:


System.out.println("two");


}


Choices:

  • A. default

  • B. default, zero, one

  • C. Compiler error

  • D. No output displayed


Correct choice:  B

Explanation:

Sun Certified Java Programmer (SCJP)-8

Exception handling


Exceptions are Java objects; exception classes are derived from java.lang.Throwable.

An exception is thrown to denote an abnormal occurrence like accessing an array index that exceeds the size of the array. Exceptions can be checked or unchecked. Subclasses of RuntimeException and Error are called unchecked exceptions. All other classes, which inherit from Exception, are checked exceptions. Any method that might throw a checked exception must either

Sun Certified Java Programmer (SCJP)-7

Assertions


An assertion is a statement containing a boolean expression that is assumed to be true when the statement is executed. The system reports an AssertionError if the expression evaluates to false. It is used for debugging purposes:

assert(a > 0); // throws an AssertionError if a <= 0



Assertions can be in two forms:


assert Expression1 ;
assert Expression1 : Expression2 ;


Expression1 should always result in a boolean value.

Expression2 can be anything that results in a value. The value is

When should the register modifier be used? Does it really help?

The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster. There are several restrictions on the use of the register modifier.

First, the variable must be of a type that can be held in the CPU’s register. This usually means a single value of a size less than or equal to the size of an integer. Some machines have registers that can hold floating-point numbers as well.

Second, because the variable might not be stored in memory, its

What is a const pointer?

The access modifier keyword const is a promise the programmer makes to the compiler that the value of a variable will not be changed after it is initialized. The compiler will enforce that promise as best it can by not enabling the programmer to write code which modifies a variable that has been declared const.

A “const pointer,” or more correctly, a “pointer to const,” is a pointer which points to data that is const (constant, or unchanging). A pointer to const is declared by putting the word const at the

What is page thrashing?

Some operating systems (such as UNIX or Windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk space to simulate RAM (random-access memory). In the 80386 and higher Intel CPU chips, and in most other modern microprocessors (such as the Motorola 68030, Sparc, and Power PC), exists a piece of hardware called the Memory Management Unit, or MMU.

The MMU treats memory as if it were composed of a series of “pages.” A page of memory is a block of contiguous bytes of a certain

Do variables need to be initialized?

No. All variables should be given a value before they are used, and a good compiler will help you find variables that are used before they are set to a value. Variables need not be initialized, however. Variables defined outside a function or defined inside a function with the static keyword are already initialized to 0 for you if you do not explicitly initialize them.

Automatic variables are variables defined inside a function or block

Program Using Switch Case

A Maruthi car dealer maintains a record of sales of various vehicles in the following form:

Vehicle type             Month of sales           Price(Rs)

Maruthi-800                 02/87                      75,000

Maruthi-van                 07/87                       95,000

Maruthi-DX                  04/88                      1,10,000

Gypsy                             08/88                      85,000

Write a c program to read this data in to a table of strings and o/p the details of particular  vehicle sold during a specified period the program should request the user to input the  vehicle type and the period.(starting month and ending month)

Algorithm:

Step 1: Start

Step 2: Enter your choice

Step 3: Read ch value

Step 4: if ch =1 then

4.1 printf "Month of sales is : 02/87”


4.2 printf "Price is : 75,000"


Step 5: if ch =2 then

5.1 print "Month of sales is : 07/87 "


5.2 print "Price is  : 95,000”


step 6: if ch=3 then

6.1 print "Month of sales is  : 04/88 "


6.2 print " Price is  : 1,10,000"


Step 7:

7.1 print "Month of sales is : 08/88 "

7.2 print " Price is  : 85,000"


Step 8 : end

Program:

Write a program to read x and to compute y=1 for x>0,y=0 for x=0 and y=-1 for x

Algorithm:

 Step1:         Start


Step2:         Read the value of x.


Step3:         if (x>0) y-1 else if (x=0) y=0 else x<0) y=-1


Step4:         Print y


Step5:         Stop.



Program:

evaluate the expression 2.5 log(x) +cos(a)+|x2-y2|+2(xy)1/2

Algorithm:

Step1:         Start


Step2:         Read the values of x,y and a.


Step3:         p=2.5*log(x)+ cos(a*3.14/180)+sqrt(2*x*y)+(x*x-y*y)


Step4:         Print p


Step5:         Stop.


 

 

Program:

Friday 4 November 2011

What is Native Image Generator (Ngen.exe)?

The Native Image Generator utility (Ngen.exe) allows you to run the JIT compiler on your assembly's MSIL and generate native machine code which is cached to disk. After the image is created .NET runtime will use the image to run the code rather than from the hard disk. Running Ngen.exe on an assembly potentially allows the assembly to load and execute faster, because it restores code and data structures from the native image cache rather than generating them dynamically.

Below are some points to be remembered for Native Image Generator:-

What is the difference between Convert.ToString and .ToString() method ?

Just to give an understanding of what the above question means seethe below code.

int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));


We can convert the integer “i” using “i.ToString()” or “Convert.ToString” so what’s the difference.

The basic difference between them is “Convert” function handles

How to prevent my .NET DLL to be decompiled?

By design .NET embeds rich Meta data inside the executable code using MSIL. Any one can easily decompile your DLL back using tools like ILDASM (owned by Microsoft) or Reflector for .NET which is a third party. Secondly there are many third party tools which make this decompiling process a click away. So any one can easily look in to

Thursday 3 November 2011

Predict the output or error(s) for the following:

class base

{

        public:


        int bval;


        base(){ bval=0;}


        };

 

class deri:public base

{

        public:


        int dval;


        deri(){ dval=1;}


        };

void SomeFunc(base *arr,int size)

{

for(int i=0; i<size; i++,arr++)


        cout<<arr->bval;

cout<<endl;


}

 

int main()

{

base BaseArr[5];


SomeFunc(BaseArr,5);


deri DeriArr[5];


SomeFunc(DeriArr,5);


}

Answer:

 00000


 01010


Explanation:  

Predict the output or error(s) for the following:

class Sample

{

public:

int *ptr;

Sample(int i)

{


        ptr = new int(i);


        }

~Sample()

{


        delete ptr;


        }

void PrintVal()

{


        cout << "The value is " << *ptr;


        }

};

void SomeFunc(Sample x)

{

cout << "Say i am in someFunc " << endl;


}

int main()

{

Sample s1= 10;


SomeFunc(s1);


s1.PrintVal();


}

Answer:

Say i am in someFunc


Null pointer assignment(Run-time error)


Explanation:

Wednesday 2 November 2011

Sun Certified Java Programmer (SCJP)-6

Flow control statements


The flow control statements allow you to conditionally execute statements, to repeatedly execute a block of statements, or to just change the sequential flow of control.

if/else statement


The if/else statement is used for decision-making -- that is, it decides which course of action needs to be taken. The syntax is:

if(boolean expression)
{

Tuesday 1 November 2011

What is CODE Access security?

CAS is part of .NET security model that determines whether or not a piece of code is allowed to run and what resources it can use while running. Example CAS will allow an application to read but not to write and delete a file or a resource from a folder.

What is the difference between System exceptions and Application exceptions?

All exception derives from Exception Base class. Exceptions can be generated programmatically or can be generated by system. Application Exception serves as the base class for all applicationspecific exception classes. It derives from Exception but does not provide any extended functionality. You should derive your

What is the difference between VB.NET and C# ?

Well this is the most debatable issue in .NET community and people treat there languages like religion. Its a subjective matter which language is best. Some like VB.NET’s natural style and some like professional and terse C# syntaxes. Both use the same framework and speed is also very much equivalents. But still let’s list down some major differences between them :-

Advantages of VB.NET :-

  • Has support for optional parameters which makes COM

What is concept of Boxing and Unboxing ?

Boxing permits any value type to be implicitly converted to type object or to any interface type implemented by value type. Boxing is a process in which object instances are created and copy values into that instance.

Unboxing is vice versa of boxing operation where the value is copied

What are Value types and Reference types ?

Value types directly contain their data which are either allocated on the stack or allocated in-line in a structure.

Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types.

Variables that are value types each have their own copy of the data,

Monday 31 October 2011

Where in memory are my variables stored?

Variables can be stored in several places in memory, depending on their lifetime. Variables that are defined outside any function (whether of global or file static scope), and variables that are defined inside a function as static variables, exist for the lifetime of the program’s execution. These variables are stored in the “data segment.” The data segment is a fixed-size area in memory set aside for these variables. The data segment is subdivided into two parts,

Variables and Data Storage

One of the C language’s strengths is its flexibility in defining data storage. There are two aspects that can be controlled in C: scope and lifetime. Scope refers to the places in the code from which the variable can be accessed. Lifetime refers to the points in time at which the variable can be accessed.

Three scopes are available to the programmer:

extern:


This is the default for variables declared outside any function. The scope of variables with extern scope is all the code in the entire program.


static:

Sun Certified Java Programmer (SCJP)

What will be the result of an attempt to compile and run the following program?


class Box
{

int b,w;
void Box(int b,int w)
{


this.b = b;
this.w = w;


}


}

public class MyBox extends Box
{

MyBox()
{


super(10,15);
System.out.println(b + "," + w);


}


static public void main(String args[])
{


MyBox box = new MyBox();


}


}

Choices:

A. Does not compile; main method is not declared correctly
B. Prints 10,15
C. Prints 0,0
D. None of the above

Correct choice:

  • D


Explanation:

Sun Certified Java Programmer (SCJP)

Constructors


A constructor is used when creating an object from a class. The constructor name must match the name of the class and must not have a return type. They can be overloaded, but they are not inherited by subclasses.

Invoking constructors


A constructor can be invoked only from other constructors. To invoke a constructor in the same class, invoke the this() function with

Sunday 30 October 2011

Predict the output or error(s) for the following:

#define int char

main()

{

            int i=65;

            printf("sizeof(i)=%d",sizeof(i));

}

Answer:

sizeof(i)=1

Explanation:

Predict the output or error(s) for the following:

main()

{

int c=- -2;


printf("c=%d",c);


}

Answer:

c=2;

Explanation:

Here unary minus (or negation) operator is used twice. Same maths

Saturday 29 October 2011

What are short-, long- and medium-term scheduling?

Long term scheduler determines which programs are admitted to the system for processing. It controls the degree of multiprogramming. Once admitted, a job becomes a process.

Medium term scheduling is part of the swapping function. This relates to processes that are in a blocked or suspended state. They are swapped

Friday 28 October 2011

What does the modulus operator do?

The modulus operator (%) gives the remainder of two divided numbers. For instance, consider the following portion of code:

x = 15/7

If x were an integer, the resulting value of x would be 2. However, consider what would happen if you were to apply the modulus operator to the same equation:

x = 15%7

The result of this expression would be the remainder of 15 divided by

What is the difference between ++var and var++?

The ++ operator is called the increment operator. When the operator is placed before the variable (++var), the variable is incremented by 1 before it is used in the expression. When the operator is placed after the
variable (var++), the expression is evaluated, and then the variable is incremented by 1. The same holds true for the decrement operator (--). When the operator is placed before the variable, you are said to

Is left-to-right or right-to-left order guaranteed for operator precedence?

The simple answer to this question is neither. The C language does not always evaluate left-to-right or right-to-left. Generally, function calls are evaluated first, followed by complex expressions and then simple expressions. Additionally, most of today’s popular C compilers often rearrange the order in which the expression is evaluated in order to get better optimized code. You therefore should always

A binary tree with 20 nodes has ____ null branches?

Ans: 21

Let us take a tree with 5 nodes (n=5)

It will have only 6 (ie,5+1) null branches. In general,

            A binary tree with n nodes has exactly n+1 null nodes.

Sorting is not possible by using which of the following methods?


  1. Insertion

  2. Selection

  3. Exchange

  4. Deletion


Ans: Deletion

Using insertion we can perform insertion sort, using selection we can perform selection sort, using exchange we can perform the bubble sort (and other similar sorting methods). But no sorting method can be done just using deletion.

What is the data structures used to perform recursion?

Stack. Because of its LIFO (Last In First Out) property it remembers its ‘caller’ so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls.

Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used.

If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.

Sun Certified Java Programmer (SCJP)

Declaring classes, variables, and methods


Now let's look at ways we can modify classes, methods, and variables. There are two kinds of modifiers -- access modifiers and non-access modifiers. The access modifiers allow us to restrict access or provide more access to our code.

Class modifiers


The access modifiers available are public, private, and protected. However, a top-level class can have only public and default access levels. If no access modifier is specified, the class will have default access. Only classes within the same package can see a class with

Thursday 27 October 2011

Sun Certified Java Programmer (SCJP)

Declarations and access control


Arrays


Arrays are dynamically created objects in Java code. An array can hold a number of variables of the same type. The variables can be primitives or object references; an array can even contain other arrays.

Declaring array variables


When we declare an array variable, the code creates a variable that can hold the reference to an array object. It does not create the array object or allocate space for array elements. It is illegal to specify the

Sun Certified Java Programmer (SCJP)

The SCJP exam is the first in a series of Java certification exams offered by Sun Microsystems, and for many programmers it is the first step to becoming established as a competent Java developer.

The exam tests the knowledge of Java fundamentals and requires in-depth knowledge of the syntax and semantics of the language. Even experienced Java programmers can benefit from preparing for the SCJP exam. You get to learn very subtle and useful tips you might not have been aware of, even after many years of Java programming.

What are different types of JIT ?

Note :- This question can only be asked when the interviewer does not know what he wants. It was asked to me in one of interview and for 15 minutes he was roaming around the same question in order to get answer from me (requirement was for a simple database project). Beware of such companies and interviewers you can land up no where.


JIT compiler is a part of the runtime execution environment.

In Microsoft .NET there are three types of JIT compilers:

What is reflection?

All .NET assemblies have metadata information stored about the types defined in modules. This metadata information can be accessed by mechanism called as “Reflection”.System. Reflection can be used to browse through the metadata information.

Using reflection you can also dynamically invoke methods using System.Type.Invokemember. Below is sample source code if needed

Tuesday 25 October 2011

Predict the output or error(s) for the following:

main()

{

            char string[]="Hello World";

            display(string);

}

void display(char *string)

{

printf("%s",string);

}

Answer:

Compiler Error : Type mismatch in redeclaration of function display

Explanation :

Predict the output or error(s) for the following:

 main()

{

              printf("%x",-1<<4);

}

Answer:

fff0

Explanation :

What is an rvalue?

In the previous post, an lvalue was defined as an expression to which a value can be assigned. It was also explained that an lvalue appears on the left side of an assignment statement. Therefore, an rvalue can be defined as an expression that can be assigned to an lvalue. The rvalue appears on the right side of an assignment statement.
Unlike an lvalue, an rvalue can be a constant or an expression, as

Can an array be an lvalue?

In the last post, an lvalue was defined as an expression to which a value can be assigned. Is an array an expression to which we can assign a value? The answer to this question is no, because an array is composed of several separate array elements that cannot be treated as a whole for assignment purposes. The following statement is therefore illegal:

int x[5], y[5];
x = y;

You could, however, use a for loop to iterate through each element of

Sunday 23 October 2011

Predict the output or error(s) for the following:

 main()

{

int i=3;


            switch(i)


             {


                default:printf("zero");


                case 1: printf("one");


                           break;


               case 2:printf("two");


                          break;


              case 3: printf("three");


                          break;


              } 


}

Answer :

three

Explanation :

Predict the output or error(s) for the following:

main()

{

char *p;


printf("%d %d ",sizeof(*p),sizeof(p));


}

Answer:

1 2

Explanation:

The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer,

Can we force garbage collector to run ?

System.GC.Collect() forces garbage collector to run. This is not recommended but can be used if situations arises.

What is garbage collection?

Garbage collection is a CLR feature which automatically manages memory. Programmers forget to release the objects while coding ..... Laziness (Remember in VB6 where one of the good practices is to set object to nothing). CLR automatically releases objects when they are no longer in use and refernced. CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is

What is Delay signing ?

During development process you will need strong name keys to be exposed to developer which is not a good practice from security aspect point of view.In such situations you can assign the key later on and during development you can use delay signing

Following is process to delay sign an assembly:

  • First obtain your string name keys using SN.EXE.

  • Annotate the source code for the assembly with two custom attributes from System.Reflection: AssemblyKeyFileAttribute, which passes the name of the file

How to add and remove an assembly from GAC?

There are two ways to install .NET assembly in GAC:-

  • Using Microsoft Installer Package. You can get download of installer from http://www.microsoft.com.

  • Using Gacutil. Goto “Visual Studio Command Prompt” and type “gacutil –i (assembly_name)”, where (assembly_name) is the DLL name of the project.


 

What is the concept of strong names?

How do we generate strong names ?

What is the use of SN.EXE ?

How do we apply strong names to assembly?

How do you sign an assembly?

Strong name is similar to GUID(It is supposed to be unique in space and time) in COM components.Strong Name is only needed when we need to deploy assembly in GAC. Strong Names helps GAC to differentiate between two versions. Strong names use public key

Saturday 22 October 2011

What is an lvalue?

An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment statement. Each assignment statement must have an lvalue and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant. For instance,

Predict the output or error(s) for the following:

main()

{

            int i=-1,j=-1,k=0,l=2,m;

            m=i++&&j++&&k++||l++;

            printf("%d %d %d %d %d",i,j,k,l,m);

}

Answer:

0 0 1 3 1

Explanation :

Logical operations always give a result of 1 or 0 . And also the logical AND (&&) operator has higher priority over the logical OR (||)

Predict the output or error(s) for the following:

 main()

{

            extern int i;

            i=20;

           printf("%d",i);

}

 Answer:

Linker Error : Undefined symbol '_i'

Explanation:

extern storage class in the following declaration,

extern int i;

specifies to the compiler that the memory for i is allocated in some

Friday 21 October 2011

What is a binary semaphore? What is its use?

A binary semaphore is one, which takes only 0 and 1 as values. They are used to implement mutual exclusion and synchronize concurrent processes.

Explain Belady's Anomaly.

Also called FIFO anomaly. Usually, on increasing the number of frames allocated to a process' virtual memory, the process execution is faster, because fewer page faults occur. Sometimes, the reverse happens, i.e., the execution time increases even when more frames are allocated to the process. This is Belady's Anomaly. This is true for certain page reference patterns.

Explain the concept of Reentrancy.

It is a useful, memory-saving technique for multiprogrammed timesharing systems. A Reentrant Procedure is one in which multiple users can share a single copy of a program during the same period. Reentrancy has 2 key aspects: The program code cannot modify itself, and the local data for each user process must be stored separately. Thus, the permanent part is the code, and the temporary part is the pointer back to the calling program and local variables used by that

What is GAC in DotNet?

What are situations when you register .NET assembly in GAC ?

GAC (Global Assembly Cache) is used where shared .NET assembly reside. GAC is used in the following situations :-

  • If the application has to be shared among several application.

  • If the assembly has some special security requirements like only administrators can remove the assembly. If the assembly is private then a simple delete of assembly the

Is versioning applicable to private assemblies?

Versioning concept is only applicable to global assembly cache (GAC) as private assembly lie in their individual folders.

Where is version information stored of an assembly ?

Version information is stored in assembly in manifest.

What is Manifest in .Net?

Assembly metadata is stored in Manifest. Manifest contains all the metadata needed to do the following things

  • Version of assembly

  • Security identity

  • Scope of the assembly

  • Resolve references to resources and classes.

  • The assembly manifest can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a stand-alone PE file that contains only assembly manifest information.


 

Thursday 20 October 2011

What is the difference between goto and longjmp()and setjmp()?

A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind should be avoided because it is not considered good programming practice to use such statements as goto and longjmp in your program.

A goto statement simply bypasses code in your program and jumps to a predefined position. To use the goto statement, you give it a

How can you tell whether a loop ended prematurely?

Generally, loops are dependent on one or more variables. Your program can check those variables outside the loop to ensure that the loop executed properly. For instance, consider the following example:

#define REQUESTED_BLOCKS 512
int x;
char* cp[REQUESTED_BLOCKS];


/* Attempt (in vain, I must add...) to
allocate 512 10KB blocks in memory. */


for (x=0; x< REQUESTED_BLOCKS; x++)
{
cp[x] = (char*) malloc(10000, 1);

Predict the output or error(s) for the following:

main()

{

int c[ ]={2.8,3.4,4,6.7,5};


             int j,*p=c,*q=c;


             for(j=0;j<5;j++) {


                        printf(" %d ",*c);


                        ++q;     }


             for(j=0;j<5;j++){


                       printf(" %d ",*p);


                       ++p;     }


}

Answer:

2 2 2 2 2 2 3 4 6 5

Explanation:

Does PL/SQL support "overloading"? Explain

The concept of overloading in PL/SQL relates to the idea that you can define procedures and functions with the same name. PL/SQL does not look only at the referenced name, however, to resolve a procedure or function call. The count and data types of formal parameters are also considered.

PL/SQL also attempts to resolve any procedure or function calls in locally defined packages before looking at globally defined packages or

What are the different type of networking / internetworking devices?

Repeater:

Also called a regenerator, it is an electronic device that operates only at physical layer. It receives the signal in the network before it becomes weak, regenerates the original bit pattern and puts the refreshed copy back in to the link.

Bridges:

These operate both in the physical and data link layers of LANs of same type. They divide a larger network in to smaller segments. They contain logic that allow them to keep the traffic for each

If you want to view a Assembly how do you go about it ?

What is ILDASM ?

When it comes to understanding of internals nothing can beat ILDASM. ILDASM basically converts the whole exe or dll in to IL code. To run ILDASM you have to go to "C:\Program Files\MicrosoftVisual Studio .NET 2008\SDK\v1.1\Bin". Note that i had v1.1 you have to probably change it depending on the type of framework version you have.

If you run IDASM.EXE from the path you will be popped with the IDASM exe program as shown in figure ILDASM. Click on file and

What is Difference between NameSpace and Assembly?

Following are the differences between namespace and assembly :

  • Assembly is physical grouping of logical units. Namespace logically groups classes.

  • Namespace can span multiple assembly.

What is NameSpace?

Namespace has two basic functionality :-

  • NameSpace Logically group types, example System.Web.UI logically groups our UI related features.

  • In Object Oriented world many times its possible that programmers will use the same class name.By qualifying NameSpace with classname this collision can be avoided.

What are the different types of Assembly in .Net?

There are two types of assembly Private and Public assembly. A private assembly is normally used by a single application, and is stored in the application's directory, or a sub-directory beneath. A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will find useful, e.g. Crystal report classes which will be used by all application for Reports.

Wednesday 19 October 2011

Other than in a for statement, when is the comma operator used?

The comma operator is commonly used to separate variable declarations, function arguments, and expressions, as well as the elements of a for statement. Look closely at the following program, which shows some of the many ways a comma can be used:

#include <stdio.h>
#include <stdlib.h>
void main(void);
void main()
{

/* Here, the comma operator is used to separate
three variable declarations. */
int i, j, k;

Can the last case of a switch statement skip including the break?

Even though the last case of a switch statement does not require a break statement at the end, you should add break statements to all cases of the switch statement, including the last case. You should do so primarily because your program has a strong chance of being maintained by someone other than you who might add cases but neglect to notice that the last case has no break statement. This oversight would cause what would formerly be the last case statement

What is a Assembly in .Net?


  • Assembly is unit of deployment like EXE or a DLL.



  • An assembly consists of one or more files (dlls, exe’s, html files etc.), and represents a group of resources, type definitions, and implementations of those types. An assembly may also contain references to other assemblies. These resources, types and references are described in a block of data called a manifest. The manifest is part of the assembly, thus making the assembly self-describing.



  • An assembly is completely self-describing.An assembly

What is a Managed Code?

Managed code runs inside the environment of CLR i.e. .NET runtime. In short all IL are managed code. But if you are using some third party software example VB6 or VC++ component they are unmanaged code as .NET runtime (CLR) does not have control over the source code execution of the language.

List out some reasons for process termination.


  • Normal completion

  • Time limit exceeded

  • Memory unavailable

  • Bounds violation

  • Protection error

  • Arithmetic error

  • Time overrun

  • I/O failure

  • Invalid instruction

  • Privileged instruction

  • Data misuse

  • Operator or OS intervention

  • Parent termination.

What is Project 802?

It is a project started by IEEE to set standards to enable intercommunication between equipment from a variety of manufacturers. It is a way for specifying functions of the physical layer, the data link layer and to some extent the network layer to allow for interconnectivity of major LAN protocols.

It consists of the following:

  • 802.1 is an internetworking standard for compatibility of different LANs and MANs across protocols.

  • 802.2 Logical link control (LLC) is the upper sublayer of

How are exceptions handled in PL/SQL?

PL/SQL exception handling is a mechanism for dealing with run-time errors encountered during procedure execution. Use of this mechanism enables execution to continue if the error is not severe enough to cause procedure termination.

The exception handler must be defined within a subprogram specification. Errors cause the program to raise an exception with a transfer of control to the exception-handler block. After the

Predict the output or error(s) for the following:

 main()

            {

            static int var = 5;

            printf("%d ",var--);

            if(var)

              main();

            }

Answer:

5 4 3 2 1

Explanation:

When static storage class is given, it is initialized once. The change in

Tuesday 18 October 2011

Is a default case necessary in a switch statement?

No, but it is not a bad idea to put default statements in switch statements for error- or logic-checking purposes. For instance, the following switch statement is perfectly normal:

switch (char_code)
{
case ‘Y’:
case ‘y’: printf(“You answered YES!\n”);
break;
case ‘N’:
case ‘n’: printf(“You answered NO!\n”);
break;
}


Consider, however, what would happen if an unknown character

What is a CLS(Common Language Specification)?

This is a subset of the CTS which all .NET languages are expected to support. It was always a dream of Microsoft to unite all different languages in to one umbrella and CLS is one step towards that. Microsoft has defined CLS which are nothing but guidelines that language to follow so that it can communicate with other .NET languages in a seamless manner.

What is a CTS?

In order that two language communicate smoothly CLR has CTS (Common Type System). Example in VB you have “Integer” and in C++ you have “long” these datatypes are not compatible so the interfacing between them is very complicated. In order to able that two different languages can communicate Microsoft introduced Common Type System. So “Integer” datatype in VB6 and “int” datatype in C++ will convert it to System.int32 which is datatype of CTS. CLS which is covered in the coming question is subset of  CTS.

Note: If  you  have undergone COM programming period

What is time-stamping?

It is a technique proposed by Lamport, used to order events in a distributed system without the use of clocks. This scheme is intended to order events consisting of the transmission of messages.

Each system 'i' in the network maintains a counter Ci. Every time a system transmits a message, it increments its counter by 1 and attaches the time-stamp Ti to the message. When a message is

What are the types of Transmission media?

Signals are usually transmitted over some transmission media that are broadly classified in to two categories.

a) Guided Media:


These are those that provide a conduit from one device to another that include twisted-pair, coaxial cable and fiber-optic cable. A signal traveling along any of these media is directed and is contained by the physical limits of the medium. Twisted-pair and coaxial cable use

Name two utilities that Oracle provides, which are use for backup and recovery.

Along with the RDBMS software, Oracle provides two utilities that you can use to back up and restore the database. These utilities are Export and Import.

The Export utility dumps the definitions and data for the specified part of the database to an operating system binary file. The Import utility reads the file produced by an export, recreates the definitions of objects, and inserts the data.

If Export and Import are used as a means of backing up and

Predict the output or error(s) for the following:

  main()

{

            float me = 1.1;

            double you = 1.1;

            if(me==you)

                  printf("I love U");

          else

                 printf("I hate U");

}

Answer:

I hate U

Explanation:

Sunday 16 October 2011

Types of programming language:

Non-procedural Approach:

It is a language, which doesn’t support any structured or systematic way in its execution. It will increase the complexity. Debugging is very difficult because it will not support procedure-orientation or modularity.

Procedure-oriented Approach

Divide the program into different sections and each and every section will do some specific task. That section is called module or procedure or a function. What ever the set of statements which are repeated number of times will be placed into a module will decrease the

  1. Complexity

  2. Memory wastage

  3. Retyping time

  4. Compilation time


It follows top-down approach

It contains set of steps, which are required to develop a project

  1.  Planning

  2. Analysis

  3. Designing

  4. Coding

  5. Debugging

  6. Testing

  7. Documentation

  8. Maintenance


Drawbacks of Procedure Oriented Approach: -

  1.  In the procedure- oriented approach, entire concentration is on Procedures only.

  2.  So it doesn’t concentrate on security to the data.

  3. It gives the freedom to the data.

  4. It will not provide any reusability.


Object- - Oriented Programming:

To over come the above drawbacks, we have to introduce Object-Oriented approach. It will support both procedure-oriented and object oriented Methodologies.

Every object must have set of properties to express its behavior and sets of actions are used to change the behavior while modifying the properties so that more than 1 object may have set of properties and actions commonly, without repeating these properties and actions common to more than 1 object in a single unit to maintain the reusability. That unit is called class.

Class:

Class is a template, which contains the set of properties and actions to specify the behavior of objects and provide security to the data. It will give an abstract view of given real life entity to create model.

Object:

It is a communicate entity to provide the communication among set of classes. It will store the state of a class at a particular time.

Instance:

It is a state of a class at a particular time but it cannot preserve that state for future use. But in the case of objects, they are the preserving mechanisms to maintain the state for future use.

What is database Trigger?

A database trigger is a PL/SQL block that can defined to automatically execute for insert, update, and delete statements against a table. The trigger can be defined to execute once for the entire statement or once for every row that is inserted, updated, or deleted. For any one table,

Predict the output or error(s) for the following:

  void main()

{

            int  const * p=5;

            printf("%d",++(*p));

}

Answer:

                        Compiler error: Cannot modify a constant value.

Explanation:

p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".

 

Saturday 15 October 2011

What is a CLR?

Full form of CLR is Common Language Runtime and it forms the heart of the .NET framework. All Languages have runtime and its the responsibility of the runtime to take care of the code execution of the program. For example VC++ has MSCRT40.DLL,VB6 has MSVBVM60.DLL, Java has Java Virtual Machine etc. Similarly .NET has CLR. Following are the responsibilities

Friday 14 October 2011

Is a default case necessary in a switch statement?

No, but it is not a bad idea to put default statements in switch statements for error- or logic-checking purposes. For instance, the following switch statement is perfectly normal:

switch (char_code)
{
case ‘Y’:
case ‘y’: printf(“You answered YES!\n”);
break;
case ‘N’:
case ‘n’: printf(“You answered NO!\n”);
break;
}


Consider, however, what would happen if an unknown character code were passed to this switch statement. The program would not print anything. It would be a good idea, therefore, to insert a default case where this condition would be taken care of:


...
default: printf(“Unknown response: %d\n”, char_code);
break;
...


Additionally, default cases come in handy for logic checking. For instance, if your switch statement handled a fixed number of conditions and you considered any value outside those conditions to be a logic error, you could insert a default case which would flag that condition. Consider the following example:

void move_cursor(int direction)
{
switch (direction)
{
case UP: cursor_up();
break;
case DOWN: cursor_down();
break;
case LEFT: cursor_left();
break;
case RIGHT: cursor_right();
break;
default: printf(“Logic error on line number ld!!!\n”,  __LINE__);
break;
}
}

Registry

Two Types of Control

Although, in general, the Registry controls all 32-bit applications and drivers, the type of control it exercises is based on users and computers, not on applications or drivers. Every Registry entry controls a user function or a computer function. User functions would include the desktop appearance and home directory, for example. Computer functions are related to installed hardware and software, items that are common to all users.

Some application functions affect users, and others affect the computer and are not specifically set for an individual. Similarly,

Thursday 13 October 2011

Registry

Data File for OS to Hardware/Drivers:

The Registry is a database of all the settings and locations of 32-bit drivers in the system. When the OS needs to access hardware devices, it uses drivers, even if the device is a BIOS-supported device. Non-BIOS-supported devices that are installed must also have a driver. The drivers are independent of the OS, but the OS needs to know where to find them, the filename, the version, and other settings and information. Without Registry entries for each of the devices, they would not be usable.

Data File for OS to Applications:

When is a switch statement better than multiple if statements?

A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type. For instance, rather than the code

Tuesday 11 October 2011

What is difference b/w static IP address and dynamic IP address?

IP addresses assigned by a DHCP server are static dynamic IP addresses while the one released by IEEE (through the ISP) are dynamic IP addresses. OR

Static address is given by administrator manually.

Dynamic address is given by DHCP server. OR

How to prevent Asthma?

Asthma
Studies conducted at yoga institutions in India have reported impressive success in improving asthma. It has also been proved that asthma attacks can usually be prevented by yoga methods without resorting to drugs.

Physicians have found that the addition of improved concentration abilities and yogic meditation together with the practice of simple postures and pranayama makes treatment more effective. Yoga practice also results in greater reduction in anxiety scores than drug therapy. Doctors believe that yoga practice helps patients by enabling them to gain access to their own internal experience and increased self-awareness.