Monday, 31 October 2011
Where in memory are my variables stored?
Variables and Data Storage
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:
main()
{
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}
Answer:
sizeof(i)=1
Explanation:
Predict the output or error(s) for the following:
{
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?
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?
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++?
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?
A binary tree with 20 nodes has ____ null branches?
Sorting is not possible by using which of the following methods?
- Insertion
- Selection
- Exchange
- 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?
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?
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 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?
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:
{
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:
{
printf("%x",-1<<4);
}
Answer:
fff0
Explanation :
What is an rvalue?
Unlike an lvalue, an rvalue can be a constant or an expression, as
Can an array be an lvalue?
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:
{
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:
{
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 ?
What is garbage collection?
What is 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?
- 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?
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?
Predict the output or error(s) for the following:
{
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:
{
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?
Explain Belady's Anomaly.
Explain the concept of Reentrancy.
What is GAC in DotNet?
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?
Where is version information stored of an assembly ?
What is Manifest in .Net?
- 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 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?
#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:
{
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
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?
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 ?
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?
- Assembly is physical grouping of logical units. Namespace logically groups classes.
- Namespace can span multiple assembly.
What is NameSpace?
- 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?
Wednesday, 19 October 2011
Other than in a for statement, when is the comma operator 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?
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?
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 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?
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:
{
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?
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)?
What is a CTS?
Note: If you have undergone COM programming period
What is time-stamping?
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?
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.
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:
{
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:
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
- Complexity
- Memory wastage
- Retyping time
- Compilation time
It follows top-down approach
It contains set of steps, which are required to develop a project
- Planning
- Analysis
- Designing
- Coding
- Debugging
- Testing
- Documentation
- Maintenance
Drawbacks of Procedure Oriented Approach: -
- In the procedure- oriented approach, entire concentration is on Procedures only.
- So it doesn’t concentrate on security to the data.
- It gives the freedom to the data.
- 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?
Predict the output or error(s) for the following:
{
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?
Friday, 14 October 2011
Is a default case necessary in a switch statement?
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
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
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?
Tuesday, 11 October 2011
What is difference b/w static IP address and dynamic IP address?
Static address is given by administrator manually.
Dynamic address is given by DHCP server. OR
How to prevent 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.
What the Registry Does?
The Registry is the data file for all 32-bit hardware/driver combinations and 32-bit applications in both Windows NT and Windows 95. Sixteen-bit drivers do not work in NT, so all devices are controlled through the Registry, even those normally controlled by the BIOS. In Windows 95, 16-bit drivers will continue to work as real-mode devices, and they use SYSTEM.INI for control.
Sixteen-bit applications will work in either NT or 95, and the applications still refer to WIN.INI and SYSTEM.INI files for information and control.
Without the Registry, the operating system would not have the necessary information to run, to control attached devices, to launch and control applications, and to respond correctly to user input.
Monday, 10 October 2011
What is the Registry?
Sunday, 9 October 2011
Predict the output or error(s) for the following:
{
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
Thursday, 6 October 2011
Benefits of Meditation
It lowers oxygen consumption.
It decreases respiratory rate.
It increases blood flow and slows the heart rate.
Increases exercise tolerance.
Real data types
Hence float, double, and long double are real data types.
How would you round off a value from 1.66 to 2.0 in C-language?
{
printf("%f",ceil(1.66));
}
Output: 2.0