Campus Buzz

all the stuffs learned while preparin for campus will be posted here!

 

Wednesday, May 24, 2006

OOPS objective questions

I prepared these questions in 4th semester. If u found it nifty, plz let me know. If u dont, do definitely know me so that I can improve on it.

click here to download 60 + questions

please post some comments. Itna to banta hein yaar!

Tuesday, May 23, 2006

SQL questions

I can gather 40 questions overall.

click here to download it.

Sunday, May 21, 2006

TCS wordlist

Download TCS wordlist compiled.

Software Engineering Revision notes


The most basic and crude definition of software is that it is a set of instructions given to computer to perform certain operations. But it only includes set of instructions. It requires also some data to perform operation which may or may not be a part of the given software. For example, in a strategy game, a scenario may be loaded before the execution of game begins. Here, the scenario or map is the data structure that enables a game to adequately manipulate information. Further, we may require embedded menus to display and explain various controls keys used in the game. As our sphere of thinking widens, we find another definition.

More.... click here to download it.

Source: Software Engg., Pressman

DAY 5- C is amusing!

What are the various built-in data tpyes that can be used for storing integers.
Myth:int short int long int
Reality: Even char data type(espcially unsigned char) can be used for storing integers also known as "tiny" integers. However, doing so is sometimes troublesome. Unlike integers, we dont know whether the char type by default is signed type or unsigned tpye. It varies from machine to machines. Also, the conversion of char value to larger data type value during calculation is to be considered.


consider this code,
char c;
while((c = getchar()) != EOF)
What's wrong with this code?

getchar() will definitely accept integer value. Also, EOF should not be similiar to any other character value. hence it is assigned value -1. two errors may arise:If type char is signed, and if EOF is defined (as is usual) as -1, the character with the decimal value 255 ('\377' or '\xff' in C) will be sign-extended and will compare equal to EOF, prematurely terminating the input. If type char is unsigned, an actual EOF value will be truncated (by having its higher-order bits discarded, probably resulting in 255 or 0xff) and will not be recognized as EOF, resulting in effectively infinite input.


Myth: the size of int is 2 bytes
Reality: The size of int can be equal to 2 byte or 4 byte dpending upon the machine to machine. The point is Type int is supposed to represent a machine's natural word size. if u r using 32-bit processor and if u get the size of int as 4 byte, dont assume that your system has gone haywireHowever, if u want to control the size of data type, u can use typedef int16 and int32 for 16-bit and 32-bit integers respectiverly.however, Typedefs will never do anything about byte order problems (e.g. if you're trying to interchange data or conform to externally-imposed storage layouts). You no longer have to define your own typedefs, because the Standard header contains a complete set.

what is the difference between int (*ip)[] and int *ip[]
there is a lot of difference b/w them. int (*ip)[] means that ip is the pointer to integer array whereas *ip[] means that ip is an array of pinters pointing towards an integer. Why it is so?
when ip is parethesis, it has a higher priority than that of [], that's why ip is considered as a pointer to array in the first declaration while in other it is considered as array of pointers.

Is it legal to write
typedef struct x1(.......)x1;

it is absolutely legal.You can use both
struct x1 X;
x1 x;
It is possible to use the same name for both the tag and the typedef, since they live in separate namespaces.

What are various kind of namespaces?

There are four different kinds of namespaces, for:

  • labels (i.e. goto targets);
  • tags (names of structures, unions, and enumerations; these three aren't separate even though they theoretically could be);
  • structure/union members (one namespace per structure or union); and
  • everything else (functions, variables, typedef names, enumeration constants), termed ``ordinary identifiers'' by the Standard.
Can we have identifier starting with underscore? Why it is allowed?
They are some rules like:

1. Don't give anything a name with a leading underscore.
2. Don't give anything a name which is already a standard macro (including the ``future directions'' patterns).
3. Don't give any functions or global variables names which are already taken by functions or variables in the standard library, or which match any of the ``future directions'' patterns. (Strictly speaking, ``matching'' means matching in the first six characters, without regard to case )
4. Don't redefine standard typedef or tag names.

However, there are some exceptios to these rules:
1. You may use identifiers consisting of an underscore followed by a digit or lower case letter for labels and structure/union members.
2. You may use identifiers consisting of an underscore followed by a digit or lower case letter at function, block, or prototype scope.
3. You may use names matching standard macro names if you don't #include any header files which #define them.
4. You may use names of standard library routines as static or local variables (strictly speaking, as identifiers with internal or no linkage, remember global vairables have external linkages whereas static and local have internal or on linkages ).
5. You may use standard typedef and tag names if you don't #include any header files which declare them.

The main motive for providing such provisions so that the programmer can create its own hidden or internal identifiers.

Source: C FAQs

Tuesday, May 16, 2006

DAY 2 -The maya of 'Static'
Topic: Java Basics

What if you want to implement main() function in the program. What should be the syntax?
public static void main( string[] args)
is the customary declaration of main() function followed by its definition.

Why to declare main() function static?
The reason is that there is only one main() method in a particular class and it doesn't require an object to access the main(). main() is available througout the execution of program.In fact, all the fields and methods declared static are available throughout the class and are stored in a heap whereas local variables are stored in stack

let us take an example, it will clear some of my and ur doubts:
class Demo
{
private int count ;
public static void main(String[ ] args)
{
int newValue;
system.out.println(newValue + " = " +count );
}
}
Here, the field private to the class (if not static) when used in main() give Compile Time Error. as main() is static.To make it code compilable, alter the code so that
class Demo
{
private static int count ;
public static void main(String[ ] args)
{
int newValue;
system.out.println(newValue + " = " +count );
}
}


When 'Demo' is executed , it creates 'count' variable immediately as it is declared as a static member of class. But 'newValue' is created only when main() is called. Variables inside a method are dynamically created when they are called.

Can static field be shared?
Yes static field can be shared. For example
class A
{
static int a;
A()
{
int value;
}
}
if we instantiate in another class the object a1, a2, a3, a4... of class A. All we share the variable 'a' with individual 'value' variable. The advantage of such a variable is that a lot of space is saved but it also has disadvantage: any object can modify its value.

How to access static members?
Inside class, static fields are accessed by their name only, while outside class the static field are accessed in this way.
classname.fieldname
only if it is public.

In constructor, can we declare static methods or fields?
The answer is obvious no. The constructor is used to instantiate object and we know that the static members r available throughout the class, not when the object is instantiated.

Now let us consider the code:
class xyz
{
public double x()
{ .... }
public static int getcount()
{
x();
return count;
}
}
It will give an compile time error as static method getcount() cannot access non-static method x().
To access the non-static method, we need to instantiate an object in getcount()
{
xyz x1= new xyz();
x1.x();
return count;
}
Recall C! Is there any such restriction related to static storage class??

Till now, we saw that static methods can access members outside the function only if
(i) they r static or
(ii) they r accessed by the object which belongs to that class.


Are there any such restriction on non-static members?
I didn't find any, non-static methods can access both static and non-static methods.

There are some static blocks in the program. Like static method, static blocks can access only static members. Static blocks are executed first, that too only once. Static block execution is followed by static sub blocks and then by non-static blocks.

class A
{
static //static block
{
...
}
{ //non-static block

}
}

Why static blocks are created?
I'm not really sure why they r created but they can be created to avoid repetition of initialization. Remeber, non-static members can use static members.

Why non-static blocks are created?
I think they are useful in creating anonymous classes.

DAY 2- I Love Java
Emotions

This is what I felt when I came to know about Java. Concrete, precise with almost no "ifs and buts" and very near to real-life object model. Java is a strictly object-oriented language.Whatmore, everythin is written in class code and dont need to mandatorily include main() function. When a program is compiled by running 'javac' at command prompt, its .class file is generated. the file is called byte code. the interpreter 'java' loads the given class file and any other program requires & begin execution by invoking the main method of given class.

Byte code has its own advantages. It is portable & suitable for any kind of OS (However in reality, different architectures have different JVM). Byte code is smaller in size when compared to .exe, therefore it takes less transfer time on networks. But everythin isn't rosy here. Interpreter i.e. JVM is slower (as it is virtual machine) than compiler, so the execution is slower when compared to C where the EXE code can be directly understood by machine. JVM is a kind of virtual micro-processor different for different platform with its own instruction, obviously implemented in software.

Java doesn't have pointers just removing redundancy complexity and making it secure. some ppl argue that Java is just a successor of C++. Definitely, it is more than that.It is platform indpendent. Java has vast range of packages from simple system tools to highly comples packages for artificial intelligence. The enormity of Java sometimes send the shiver in my spines. This is not the language u can master by joinin any course. It might happen that u may study all ur life this language and still consider urself an intermediate in it. It ranges from applet to sockets, from complex servlet to java to RMI and what not. To master Java, u should have endurance to keep in pace with ever-changing Java technologies. Yes, Java in itself is technology and will remain in the future.

Monday, May 15, 2006

DAY 1

C is amusing!

OK! why I'm sayin this b'coz I discovered some real amusing facts about C.let's start declarations and initializations.

what do u think the size of a and b if
char far *a, *b;

Let me guess: 2 2.
but the right answer is 4 bytes for a and 2 bytes for b.
Reason: far pointer would require 4 bytes of memory. Now what the hell is far pointer and why it is required?

The answer is related to memory model of earlier IBM PC. The PC, when running in real mode, is able to address only 64K at any time using16-bit addresses, referred to as near pointers. This limitation is a problem because many programs and their data are larger than 64K. To address more than 64K, it is necessary to use segments and offsets, which are forms of 24-bit addresses. If the compiler is told to use segments, it generally creates two problems: Segment arithmetic will cause your application to be slightly slower, and the size of the program will be larger.Using segments and offsets is referred to as far pointers.

Now enough of historical reasons, lets look the other problems which will definitely stir ur head...

Consider this program,
main()
{
extern int i;
i=100;
printf("%d",sizeof(i));
}
2 4 or error, if error ,what kind of error...

The answer it will give the error like: C:\DOCUME~1\General\LOCALS~1\Temp\cc0gcaaa.o(.text+0x3b)
In function `main': [Linker error] undefined reference to `i' now, what caused tis error: Whenever C compiler find the variable declared extern, it assumes that this variable is declared somewhere else. This program is syntantically correct, but when the compiler tries to link the program it finds the refernce of the extern variable which is not defined elsewhere. This code can be debugged in this way to compile successfully.

main()
{
extern int i;
i=100;
printf("%d",sizeof(i));
}i=20;

the value of i inside main() function is 100 whereas outside the function, the value is 20.
Here, u just saw the extern variable can have many definitions within the program. What about global variable? can they enjoy the same liberty? fortunately, the answer is No. Global variable can have many declarations but only one definition. The same is applicable to functions definiton and declaration.