Java Interview Questions

Q: – Can I call a abstract method from a non abstract method ? 

Yes, We can call a abstract method from a Non abstract method in a Java abstract class

Q: – What is a collection ? 

Collection is a group of objects. java.util package provides important types of collections. There are two fundamental types of collections they are Collection and Map. Collection types hold a group of objects, Eg. Lists and Sets where as Map types hold group of objects as key, value pairs Eg. HashMap and Hashtable.

Q: – What methods java providing for Thread communications ? 

Java provides three methods that threads can use to communicate with each other: wait, notify, and notifyAll. These methods are defined for all Objects (not just Threads). The idea is that a method called by a thread may need to wait for some condition to be satisfied by another thread; in that case, it can call the wait method, which causes its thread to wait until another thread calls notify or notifyAll.

Q: – Can you write a Java class that could be used both as an applet as well as an application?

Yes, Add a main() method to the applet.

Q: – What’s the difference between J2SDK 1.5 and J2SDK 5.0?

There’s no difference, Sun Microsystems just re-branded this version.

Q: – You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList?

ArrayList

Q: – Why would you use a synchronized block vs. synchronized method?

Synchronized blocks place locks for shorter periods than synchronized methods.

Q: – Explain the usage of the keyword transient?

This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

Q: – How can you force garbage collection?

You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

Q: – What is Abstraction?

Abstraction refers to the act of representing essential features without including the background details or explanations.

Q: – What is Encapsulation?

Encapsulation is a technique used for hiding the properties and behaviors of an object and allowing outside access only as appropriate. It prevents other objects from directly altering or accessing the properties or methods of the encapsulated object.

Q: – What is Dynamic Binding?

Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time

Q: – Is it possible to override the main method?

NO, because main is a static method. A static method can’t be overridden in Java.

Q: – What is super?

Super is a keyword which is used to access the method or member variables from the superclass.

Q: – Can we instantiate an interface?

You can’t instantiate an interface directly, but you can instantiate a class that implements an interface.

Q: – Can we create an object for an interface?

Yes

Q: – What modifiers are allowed for methods in an Interface?

public
abstract

Q: – What is an abstract class?

Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation.

Q: – When you declare a method as abstract, can other nonabstract methods access it?

Yes

Q: – Can there be an abstract class with no abstract methods in it?

Yes

Q: – What is Constructor?

A constructor is a special method whose task is to initialize the object of its class.

Q: – Can constructor be inherited?

No

Q: – What is an EntrySet View?

Entry Set view is a set that is returned by the entrySet() method in the map and contains Objects of type Map.

Q: – What is a KeySet View ?

KeySet is a set returned by the keySet() method of the Map Interface, It is a set that contains all the keys present in the Map.

Q: – What are the main Implementations of the Map interface ?

HashMap
HashTable
TreeMap
EnumMap

Q: – What is a Map ?

A map is an object that stores associations between keys and values (key/value pairs).

Q: – What is an EnumSet ?

An EnumSet is a specialized set for use with enum types, all of the elements in the EnumSet type that is specified, explicitly or implicitly, when the set is created.

Q: – What are the advantages of ArrayList over arrays ?

It can grow dynamically
It provides more powerful insertion and search mechanisms than arrays.

Q: – What is the List interface?

The List interface provides support for ordered collections of objects. Lists may contain duplicate elements.

Q: – Can null value be added to a List?

Yes

Q: – What is Dictionary class?

The Dictionary class is the abstarct super class of Hashtable and Properties class.Dictionary provides the abstarct functions used to store and retrieve objects by key value. This class allows any object to be used as a key or value

Q: – What is the Hashtable class?

The Hashtable class implements a hash table data structure. A hash table indexes and stores objects in a dictionary using hash codes as the objects’ keys

Q: – Garbage collector thread belongs to which priority?

low-priority

Q: – Which method waits for the thread to die ? 

join() method

Q: – What are all the four states associated in the thread?

new
runnable
blocked
dead

Q: – What is the default thread at the time of starting the program?

main thread

Q: – What is the method available for setting the priority?

setPriority()

Q: – What are all the methods available in the Runnable Interface?

run()

Q: – What are the two types of multitasking?

process-based
Thread-based

Q: – Can we have catch block with out try block?

No

Q: – How do we change the values of the elements of the array?

The array subscript expression can be used to change the values of the elements of the array.

Q: – Is it possible to use few methods of an interface in a class ? If so, how?

Yes. Declare the class as abstract.

Q: – What are the possible access modifiers when implementing interface methods?

public

Q: – How do you achieve multiple inheritances in Java? 

We can use interfaces.

Q: – Is it is necessary to implement all methods in an interface?

Yes

Q: – How this() is used with constructors?

 this() is used to invoke a constructor of the same class.

Q: – How super() used with constructors?

super() is used to invoke a super class constructor

Q: – Which methods in the Object class are declared as final?

getClass()
notify()
notifyAll()
wait()

Q: – Which Java operator is right associatively?

Java support = operator

Q: – Can a byte object be cast to a double value ?

No

Q: – What is the % operator?

The % operator is the modulo operator or reminder operator. It returns the reminder of dividing the first operand by second operand.

Q: – What is the use of bin and lib in JDK?

bin contains all tools such as javac, applet viewer, awt tool etc., whereas lib contains all packages and variables

Q: – What are the three OOPs principles and define them?

Encapsulation, Inheritance and Polymorphism are the three OOPs Principles.

Q: – What declarations are required for every Java application?

A class and the main( ) method declarations.

Q: – What modifiers may be used with top-level class?

public
Abstract
final.

Q: – Is a class a subclass of itself?

Yes

Q: – Which method is used to garbage collect an object?

finalize ()

Q: – What is casting?

Casting is process of convert the value of one type to another.

Q: – What is phantom memory?

Phantom memory is false memory. Memory that does not exist in reality.

Q: – What is MVC?

Model-View-Controller (MVC) is a design pattern put together to help control change.

Q: – What is a framework?

A framework is made up of the set of classes which allow us to use a library in a best possible way for a specific requirement.

Q: – What are the components of Struts?

Model
View
Controller

Q: – What is the ActionForm?

ActionForm is javabean which represents the form inputs containing the request parameters from the View referencing the Action bean.

Q: – What are the important methods of ActionForm?

validate()

reset()

Q: – What is ActionMapping?

Action mapping contains all the deployment information for a particular Action bean. This class is to determine where the results of the Action will be sent once its processing is complete.

Q: – What is role of Action Class?

An Action Class performs a role of an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request.

Q: – Can we have more than one struts-config.xml file for a single Struts application?

Yes

Q: – What are the different kinds of actions in Struts?

ForwardAction
IncludeAction
DispatchAction
LookupDispatchAction
SwitchAction

Q: – What is IncludeAction?

The IncludeAction class is useful when you want to integrate Struts into an application that uses Servlets.

Q: – What is SwitchAction?

The SwitchAction class provides a means to switch from a resource in one module to another resource in a different module. SwitchAction is useful only if you have multiple modules in your Struts application.

Q: – How to display validation errors on jsp page?

<html:errors/> tag displays all the errors. <html:errors/> iterates over ActionErrors request attribute.

Q: – What are the uses of Servlet?

Processing and/or storing data submitted by an HTML form.
Providing dynamic content, e.g. returning the results of a database query to the client.
A Servlet can handle multiple requests concurrently and be used to develop high performance system
Managing state information on top of the stateless HTTP, e.g. for an online shopping cart system which manages shopping carts for many concurrent customers and maps every request to the right customer.

Q: – What is the GenericServlet class?

GenericServlet is an abstract class that implements the Servlet interface and the ServletConfig interface.

Q: – Why is HttpServlet declared abstract?

The HttpServlet class is declared abstract because the default implementations of the main service methods do nothing and must be overridden.

Java Interview Questions And Answers

Q: – Can I call a abstract method from a non abstract method ? 

Yes, We can call a abstract method from a Non abstract method in a Java abstract class

Q: – What is a collection ? 

Collection is a group of objects. java.util package provides important types of collections. There are two fundamental types of collections they are Collection and Map. Collection types hold a group of objects, Eg. Lists and Sets where as Map types hold group of objects as key, value pairs Eg. HashMap and Hashtable.

Q: – What methods java providing for Thread communications ? 

Java provides three methods that threads can use to communicate with each other: wait, notify, and notifyAll. These methods are defined for all Objects (not just Threads). The idea is that a method called by a thread may need to wait for some condition to be satisfied by another thread; in that case, it can call the wait method, which causes its thread to wait until another thread calls notify or notifyAll.

Q: – Can you write a Java class that could be used both as an applet as well as an application?

Yes, Add a main() method to the applet.

Q: – What’s the difference between J2SDK 1.5 and J2SDK 5.0?

There’s no difference, Sun Microsystems just re-branded this version.

Q: – You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList?

ArrayList

Q: – Why would you use a synchronized block vs. synchronized method?

Synchronized blocks place locks for shorter periods than synchronized methods.

Q: – Explain the usage of the keyword transient?

This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

Q: – How can you force garbage collection?

You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

Q: – What is Abstraction?

Abstraction refers to the act of representing essential features without including the background details or explanations.

Q: – What is Encapsulation?

Encapsulation is a technique used for hiding the properties and behaviors of an object and allowing outside access only as appropriate. It prevents other objects from directly altering or accessing the properties or methods of the encapsulated object.

Q: – What is Dynamic Binding?

Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time

Q: – Is it possible to override the main method?

NO, because main is a static method. A static method can’t be overridden in Java.

Q: – What is super?

Super is a keyword which is used to access the method or member variables from the superclass.

Q: – Can we instantiate an interface?

You can’t instantiate an interface directly, but you can instantiate a class that implements an interface.

Q: – Can we create an object for an interface?

Yes

Q: – What modifiers are allowed for methods in an Interface?

public
abstract

Q: – What is an abstract class?

Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation.

Q: – When you declare a method as abstract, can other nonabstract methods access it?

Yes

Q: – Can there be an abstract class with no abstract methods in it?

Yes

Q: – What is Constructor?

A constructor is a special method whose task is to initialize the object of its class.

Q: – Can constructor be inherited?

No

Q: – What is an EntrySet View?

Entry Set view is a set that is returned by the entrySet() method in the map and contains Objects of type Map.

Q: – What is a KeySet View ?

KeySet is a set returned by the keySet() method of the Map Interface, It is a set that contains all the keys present in the Map.

Q: – What are the main Implementations of the Map interface ?

HashMap
HashTable
TreeMap
EnumMap

Q: – What is a Map ?

A map is an object that stores associations between keys and values (key/value pairs).

Q: – What is an EnumSet ?

An EnumSet is a specialized set for use with enum types, all of the elements in the EnumSet type that is specified, explicitly or implicitly, when the set is created.

Q: – What are the advantages of ArrayList over arrays ?

It can grow dynamically
It provides more powerful insertion and search mechanisms than arrays.

Q: – What is the List interface?

The List interface provides support for ordered collections of objects. Lists may contain duplicate elements.

Q: – Can null value be added to a List?

Yes

Q: – What is Dictionary class?

The Dictionary class is the abstarct super class of Hashtable and Properties class.Dictionary provides the abstarct functions used to store and retrieve objects by key value. This class allows any object to be used as a key or value

Q: – What is the Hashtable class?

The Hashtable class implements a hash table data structure. A hash table indexes and stores objects in a dictionary using hash codes as the objects’ keys

Q: – Garbage collector thread belongs to which priority?

low-priority

Q: – Which method waits for the thread to die ? 

join() method

Q: – What are all the four states associated in the thread?

new
runnable
blocked
dead

Q: – What is the default thread at the time of starting the program?

main thread

Q: – What is the method available for setting the priority?

setPriority()

Q: – What are all the methods available in the Runnable Interface?

run()

Q: – What are the two types of multitasking?

process-based
Thread-based

Q: – Can we have catch block with out try block?

No

Q: – How do we change the values of the elements of the array?

The array subscript expression can be used to change the values of the elements of the array.

Q: – Is it possible to use few methods of an interface in a class ? If so, how?

Yes. Declare the class as abstract.

Q: – What are the possible access modifiers when implementing interface methods?

public

Q: – How do you achieve multiple inheritances in Java? 

We can use interfaces.

Q: – Is it is necessary to implement all methods in an interface?

Yes

Q: – How this() is used with constructors?

 this() is used to invoke a constructor of the same class.

Q: – How super() used with constructors?

super() is used to invoke a super class constructor

Q: – Which methods in the Object class are declared as final?

getClass()
notify()
notifyAll()
wait()

Q: – Which Java operator is right associatively?

Java support = operator

Q: – Can a byte object be cast to a double value ?

No

Q: – What is the % operator?

The % operator is the modulo operator or reminder operator. It returns the reminder of dividing the first operand by second operand.

Q: – What is the use of bin and lib in JDK?

bin contains all tools such as javac, applet viewer, awt tool etc., whereas lib contains all packages and variables

Q: – What are the three OOPs principles and define them?

Encapsulation, Inheritance and Polymorphism are the three OOPs Principles.

Q: – What declarations are required for every Java application?

A class and the main( ) method declarations.

Q: – What modifiers may be used with top-level class?

public
Abstract
final.

Q: – Is a class a subclass of itself?

Yes

Q: – Which method is used to garbage collect an object?

finalize ()

Q: – What is casting?

Casting is process of convert the value of one type to another.

Q: – What is phantom memory?

Phantom memory is false memory. Memory that does not exist in reality.

Q: – What is MVC?

Model-View-Controller (MVC) is a design pattern put together to help control change.

Q: – What is a framework?

A framework is made up of the set of classes which allow us to use a library in a best possible way for a specific requirement.

Q: – What are the components of Struts?

Model
View
Controller

Q: – What is the ActionForm?

ActionForm is javabean which represents the form inputs containing the request parameters from the View referencing the Action bean.

Q: – What are the important methods of ActionForm?

validate()

reset()

Q: – What is ActionMapping?

Action mapping contains all the deployment information for a particular Action bean. This class is to determine where the results of the Action will be sent once its processing is complete.

Q: – What is role of Action Class?

An Action Class performs a role of an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request.

Q: – Can we have more than one struts-config.xml file for a single Struts application?

Yes

Q: – What are the different kinds of actions in Struts?

ForwardAction
IncludeAction
DispatchAction
LookupDispatchAction
SwitchAction

Q: – What is IncludeAction?

The IncludeAction class is useful when you want to integrate Struts into an application that uses Servlets.

Q: – What is SwitchAction?

The SwitchAction class provides a means to switch from a resource in one module to another resource in a different module. SwitchAction is useful only if you have multiple modules in your Struts application.

Q: – How to display validation errors on jsp page?

<html:errors/> tag displays all the errors. <html:errors/> iterates over ActionErrors request attribute.

Q: – What are the uses of Servlet?

Processing and/or storing data submitted by an HTML form.
Providing dynamic content, e.g. returning the results of a database query to the client.
A Servlet can handle multiple requests concurrently and be used to develop high performance system
Managing state information on top of the stateless HTTP, e.g. for an online shopping cart system which manages shopping carts for many concurrent customers and maps every request to the right customer.

Q: – What is the GenericServlet class?

GenericServlet is an abstract class that implements the Servlet interface and the ServletConfig interface.

Q: – Why is HttpServlet declared abstract?

The HttpServlet class is declared abstract because the default implementations of the main service methods do nothing and must be overridden.

 

– ‘ C ‘ –

Q: – Explain about storage of union elements. 

The key point about storage of union elements is that Union elements are use to share common memory space.

Q: – What is a memory leak?

Memory leak is that when memory is allocated but its not released because of an application consume memory reducing the available memory for other applications and causing the system to page virtual memory to the hard drive showing the application or crashing the application. When the computer memory resource limits are reached.

Q: – Is C is platform dependent or independent?how and why?

Major issue behind designing C language is that it is a small,portable programming language. It is used to implement an operating system.In past time C is a powerful tool for writing all types of program and has mechanism to achieve all most programming goals.So, we can say that C is platform dependent.

Q: – What are the stream files?

We can open file in C with using stream files.which are identified with a pointer to a FILE structure, or as low-level files, which are identified with an integer handle.

We can open stream files with using one of the following functions.

fopen(): Opens the specified file with the specified mode
freopen(): Closes the file specified, then opens a new file as specified
fdopen(): Opens a duplicate stream file for an already open low-level file

Q: – How the processor registers can be used in C? 

using keyword register we can use the process register in C.Basically process register is used to store variables those i want to access frequently.if these registers are not used in any other program,then those registers we used to allocate memory these variables.

Q: – How to access or modify the constt variable in C ?

We can not modify the constant variable.

Q: – Why n++ executes faster than n+1?

n++ executes faster than n+1 because n++ want only one instruction for execution where n+1 want more one instruction for execution.

Q: – What is the difference between the Heap and the Stack?

The main difference b/n the Heap and the Stack are given below:

– In stack we create object temporary where programmer used to reserve allocation.’
– stack not have automatic garbage collection where as heap have automatic garbage collection.

Q: – What is the Double LinkedList?

Double Linked List is that each data item in the list can point both side(next or previous)data item.It is not specific type means it may be of stack or queue.This is use to increase the performance of program.It is also called as Two-way Linked List or Symmetrically Linked list.

Q: – What are the advantages of high-level programming languages?

Readability, maintainability, and portability

Q: – Why is the main() function needed in a program?

The execution of a C program starts and ends with the main() function. Without the main() function, the computer does not know where to start to run a program.

Q: – What does the #include directive do?

The #include directive is used to include header files that contain the declarations to the functions used in your C program. In other words, the #include directive tells the C preprocessor to look into the include path to find the specified header file.

Q: – Why do you need a linker?

After compiling, some function code may still be missing in the object file of a program. A linker must then be used to link the object file to the C standard library or other user-generated libraries and include the missing function code so that an executable file can be created.

Q: – What is the difference between a constant and a variable?

The major difference is that the value of a constant cannot be changed, whereas the value of a variable can. You can assign different values to a variable whenever it’s necessary in your C program.

Q: – Why do you need a statement block?

Many C keywords can only control one statement. A statement block provides a way to put more than one statement together, and put the statement block under the control of a C keyword. Then, the statement block is treated as a single statement.

Q: – Which arithmetic operators have a higher precedence?

Among the five arithmetic operators, the multiplication, division, and remainder operators have a higher precedence than the addition and subtraction operators.

Q: – How many parts does a function normally have?

A function normally has six parts: the function type, the function name, the arguments, the opening brace, the function body, and the closing brace.

Q: – How can you declare two character variables?

There are two ways to do the declaration. The first one is

…char variable-name1, variable-name2;

The second one is

char variable-name1;
char variable-name2;

Q: – What are %c, %d, and %f?

These are format specifiers. %c is used to obtain the character format; %d is for the integer format; %f is for the floating-point format. %c, %d, and %f are often used with C functions such as printf().

Q: – What are the main differences between the int data type (integer) and the float data type (floating-point)?

First, an integer does not contain any fraction parts, but a floating-point number does. A floating-point number must have a decimal point. In C, the float data type takes more bits than the int data type. In other words, the float data type has a larger range of numeric values than the int data type.

Q: – What are stdin, stdout, and stderr?

In C, a file is treated as a series of bytes that is called file stream. stdin, stdout, and stderr are all pre-opened file streams. stdin is the standard input for reading; stdout is the standard output for writing; stderr is the standard error for outputting error messages.

Q: – What value is yielded by a relational expression?

A relational expression evaluates to either 0 or 1. If the relation indicated by a relational operator in an expression is true, the expression evaluates to 1; otherwise, the expression evaluates to 0.

Q: – Is the unary minus operator (-) the same as the subtraction operator (-)?

No, they are not the same, although the two operators share the same symbol. The meaning of the symbol is determined by the context in which it appears. The unary minus operator is used to change the sign of a numeric value. In other words, the unary minus operator yields the negation of the value. The subtraction operator is an arithmetic operator that performs a subtraction between its two operands.

Q: – Why do we need the sizeof operator?

The sizeof operator can be used to measure the sizes of all data types defined in C. When you write a portable C program that needs to know the size of an integer variable, it’s a bad idea to hard-code the size based on the machine you are currently using. The better way to tell the program the size of the variable is to use the sizeof operator, which yields the size of the integer variable at runtime.

Q: – What can the %lu format specifier do?

The %lu format specifier can be used in a printf() string to convert the corresponding argument to the unsigned long int data type. In addition, the %lu format specifier is equivalent to %Lu.

Q: – What are the left and right values?

The left value is the address of a variable, and the right value is the content stored in the memory location of a variable.

Q: – How can you obtain the address of a variable?

By using the address-of operator, &.

Q: – Can a null pointer point to valid data?

No. A null pointer cannot point to valid data. This is because the value contained by a null pointer has been set to 0.

Q: – What can the null character do?

The null character (‘’) in C can be used to mark the end of a string.

Q: – Can a global variable be hidden by a local variable with block scope?

Yes

Q: – Why do we need function prototypes?

With the help of a function prototype, the compiler can automatically perform type checking on the definition of the function, which saves you time in debugging the program.

Q: – Can a function return a pointer?

Yes

Q: – Why do you need to use arrays of pointers?

It is convenient to use an array of pointers to point to a set of character strings so that you can access any one of the strings referenced by a corresponding pointer in the array.

Q: – What does it mean if the malloc() function returns a null pointer?

If the malloc() function returns a null pointer, it means the function failed to allocate a block of memory whose size is specified by the argument passed to the function.

Q: – What are the differences between the calloc() and malloc() functions?

The calloc() function takes two arguments, while the malloc() function takes only one. The second difference is that the calloc() function initializes the allocated memory space to 0, whereas there is no such guarantee made by the malloc() function.

Q: – Is the free() function necessary?

Yes. The free() function is very necessary, and you should use it to free up allocated memory blocks as soon as you don’t need them.

Q: – What can you do with the enum data type?

The enum data type can be used to declare names that represent integer constants.

Q: – Why do you need to use the typedef keyword?

By using the typedef keyword, you can define your own names to represent the data types in C.

Q: – Can you redirect a standard stream to a disk file?

Yes. With the help of the freopen() function, you can redirect a standard stream and associate the stream with a disk file.

Q: – Is the C preprocessor part of the C compiler?

No

Q: – How do you remove a macro name?

By using the #undef directive with a macro name, that macro name can be removed, or “undefined.”

Q: – Why do you need the #endif directive?

The #endif directive is used with an #if, #ifdef, or #ifndef directives because statements under the control of a conditional preprocessor directive are not enclosed in braces ({ and }). Therefore, #endif must be used to mark the end of the block of statements.

Q: – Can the conditional expression following the #if directive be an arithmetic expression?

Yes

Q: – What is the difference b/n run time binding and compile time binding?

When the address of functions are determined a run time than it is called run time or dynamic binding or late binding. While when the addresses of functions are determined a compile time than it is called compile time or static binding or early binding.

Q: – Why do you need the #endif directive?

The key difference b/n linker and linkage is that linker is used to change an object code into an executable code by linking together the necessary build in functions. Place where we declare the variable in a program is called the linkage of variable.

Q: – What is the Double LinkedList?

Double Linked List is that each data item in the list can point both side(next or previous)data item.

Q: – Can we write a program with out using main() function?

No

Q: – Explain “method”?

A Method is a programmed procedure. It is defined as part of a class also included in any object of that class. Class can have more than one methods. It can be re-used in multiple objects.

Q: – What is the Double LinkedList?

Double Linked List is that each data item in the list can point both side(next or previous)data item.

Q: – Can we write a program with out using main() function?

No

Q: – Explain “method”?

A Method is a programmed procedure. It is defined as part of a class also included in any object of that class. Class can have more than one methods. It can be re-used in multiple objects.

Q: – Write a programme to display number from the bellow string?

char *ptr=”HELLO57hai”

#include<stdio.h>

int main()
{
char *ptr=”HELLO57hai”;
while(*ptr)
{
if(*ptr<‘A’)
printf(“%c”,*ptr);
ptr++;
}
}

Q: – what are compilation process or steps?

prepocessor->compiler->assembler->linkEditor==Executable code

Q: – What is the output of the bellow program?

segmentation fault.because we are trying to read/assign character into const string.

#include<stdio.h>
main()
{
char *ptr=”HELLO”;
ptr[0]=’A’;
printf(“%s”,ptr);
}

Q: – There are numbers range from 1 to n randamly stored in the array and one number is missed in that array.write a program to find out missing number?

int missing_number(int a[],int n)
{
int Total,i;
Total=(n+1)*(n+2)/2;
for(i=0;i<n;i++)
Total -=a[i];
return Total;
}

Q: – What is the output of this Programme?

#include<stdio.h>
int main()
{
int x[]={1,3,2,4,6};
int *ptr,y;
ptr=x+4;
y=ptr-x;
printf(“%d\n”,y);
}

Q: – How do you find middle element in the single linked list by traversing only one time from first to last?

we can findout middle element by taking two pointers.increment twice ptr1 while incrementing the ptr2 once ,so when ptr1 reaches to end of the node in the list,ptr2 will be pointing to middle element in the list. so we just return adress of middle element.
struct person*find_middle(struct person **listhead)
{
struct person *ptr1,*ptr2;
ptr1=ptr2=*listhead;
int i=0;
while(ptr1->link!=NULL)
{
if(i==0)
{
ptr1=ptr1->link;
i=1;
}
else if(i==1)
{
ptr1=ptr1->link;
ptr2=ptr2->link;
i=0;

}
}
return ptr2;
}

Q: – What are “<<” and “>>” in C language. what is the output of the bellow code program?

#include<stdio.h>
int main()
{
int x=0x00AA;
int y=0x0055;
int z;
z=x<<8 + y>>8;
printf(“%d\n”,z);
}

Answer:

In C language <<(Left shift operator) and >>(Right shift operator) are called Bitwise operators and used to work on bits.
Z value is 4194304 for the above program.

Q: – What is Void pointer? can we perform arithimetic operations on void pointers?why? give one example?

void pointer is one kind of pointer ,it supports to hold data of all datatypes(like int,char,float etc).it’s also called generic pointer.we can’t perform arithimatic operations on void pointer because compiler doesn’t know the type of data to increment.

Ex:

#include<stdio.h>
int main()
{
int a[]={100,200};
void *ptr;
ptr=a;
ptr++;
printf(“%d\n”,*ptr); //here error occur.
}

Q: – What is the output of this program?

#include<stdio.h>
char *myfun(char *p)
{
p+=3;
return p;
}
int main()
{
int *p;
int *q;
p=”HELLO”;
q=myfun(p);
printf(“%s”,q);
}

Answer: LO.

Q: – Write a program to reverse a string with out using any array?

#include<stdio.h>
int main()
{
char *str=”Mahesh”;
char *ptr=str+strlen(str);
while(ptr>=str)
{
printf(“%c”,*ptr);
ptr–;
}
}

 

Q: – What is the output of this programe?

#include<stdio.h>
void Allocate(char *str, int size)
{
str =(char *)malloc(size);
}
int main()
{
char *str;
Allocate(str, 20);
strcpy(str, “HCL”);
strcat(str, “Technologies”);
printf(“%s\n”,str);
}

Answer:Run time error(segmentation fault).

Reason: in function Allocate, we have allocated memory by using malloc function and assigned adress of that block to local pointer str. when control returns from that function the pointer (str) dies.so it will not affect in the main function. in main function,we are trying to read memory by using printf statement. so run time error occur.

Q: – What is the output of this programe?

#include<stdio.h>
main()
{
char *ptr =”HCL Technologies”;
(*ptr)++;
printf(“%s\n”,ptr);
ptr++;
printf(“%s\n”,ptr);
}

Answer:segmentation fault.because we are trying to modify the const string.

Q: – What is the output of this programe?

#include<stdio.h>
void show()
{
static int i=1;
printf(“%d\n”,i++);
}

int main()
{
show();show();show();
}

Answer:1 2 3. static varibles values remain in function calls.if i(variable) in function show() islocal variable the out put would be 1 1 1.

 

MYSQL (DBMS) Interview Questions And Answers

Q: – What is REPLCAE statement, and how do I use it?

The REPLACE statement is the same as using an INSERT INTO command. The syntax is pretty much the same. The difference between an INSERT statement and a REPLACE statement is that MySQL will delete the old record and replace it with the new values in a REPLACE statement, hence the name REPLACE.

Q: – MySQL has a lot of neat functions. What if I need one that isn’t there?

MySQL is so flexible that it allows you to create your own functions. These user-defined functions act the same way that MySQL’s own intrinsic functions operate. It is also possible to recompile your functions into the application so that you will always have them, no matter how many times you install.

Q: – Do all unique keys have to be primary keys?

No. MySQL permits only one primary key per table, but there may be a number of unique keys. Both unique keys and primary keys can speed up the selecting of data with a WHERE clause, but a column should be chosen as the primary key if this is the column by which you want to join the table with other tables.

Q: – How many databases can one MySQL RDBMS contain?

Because MySQL uses the file system of the operating system, there really is no limit to the number of databases contained within a single MySQL RDBMS. The size of the database is limited by the operating system. The database tables can only be as big as the OS’s file system will allow.

Q: – I want to sort the values of my ENUM and SET columns. How do I do this?

The sort order depends on the order in which the values were inserted. ENUM and SET types are not case sensitive. The value that is inserted reverts to the value that you used when you created the ENUM or SET.

Q: – What can I do with the contents of a mysqldump file?

This file is a complete replica of your database in SQL format. You can do a lot of things with this data. You could re-create your database in Microsoft SQL Server or Sybase by simply cutting and pasting the contents of the file. You could also restore your database by using the dump file and the batching ability of the mysql program.

Q: – What are features of MYSQL ?

MySQL is a full-featured relational database management system. It is very stable and has proven itself over time. MySQL has been in production for over 10 years.

– MySQL is a multithreaded server. Multithreaded means that every time someone establishes a
connection with the server, the server program creates a thread or process to handle that client’s
requests. This makes for an extremely fast server. In effect, every client who connects to a MySQL
server gets his or her own thread.

– MySQL is also fully ANSI SQL92-compliant. It adheres to all the standards set forth by the American National Standards Institute.

– another feature of MySQL is its portability—it has been ported to almost every platform. This means that you don’t have to change your main platform to take advantage of MySQL. And if you do want to switch, there is probably a MySQL port for your new platform.

– MySQL also has many different application programming interfaces (APIs). They include APIs for Perl, TCL, Python, C/C++, Java (JDBC), and ODBC.

Q: – What do I do if I forget the MySQL root password?

First log in to the system as the same person who is running the mysqld
daemon (probably root). Kill the process, using the kill command.
Restart MySQL with the following arguments:
bin/mysqld Skip-grant
USE mysql;
UPDATE user SET password = password(‘newpassword’) WHERE User = ‘root’;
Exit
bin/mysqladmin reload

The next time you log in, you will use your new password

Q: – Where is the data stored in a MySQL database?

MySQL uses files to store data. These files are under the data/databasename directory, where databasename is the name of the database. There are three file types: .ISM, .FRM, and .ISD. The .FRM file contain the table schema. The .ISD is the file that actually holds the data. The .ISM file is the file that provides quick access between the two of them.

Q: – Explain the terms “mysqlimport”, “mysqldump”, “mysqladmin” and “mysqlcheck”?

mysqlimport for importing data files, mysqldump for making backups, mysqladmin for server administration, and mysqlcheck for checking the integrity of the database files.

Q: – How you will determine the options which are used by mysql?

#mysql –help

Q: – How you will determine the version of MySQL?

mysql –version

mysql  Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (i386) using readline 5.1

Q: – How you will connect to the server at a specific IP address with username and password?

mysql –host=10.168.1.33 –user=NAME –password=PASSWORD

Q: – What do you think about this command “mysql> STATUS;”

It will display information about the current connection to the server, as well as status information about the server itself.

Q: – Have you used this command “mysql> HELP contents;”?

Yes, You can get server-side help from this command.

mysql> HELP contents;

You asked for help about help category: “Contents”

For more information, type ‘help <item>’, where <item> is one of

the following categories:

Administration

Column Types

Data Definition

Data Manipulation

Functions

Geographic features

Transactions

Q: – What is MySQL Query Browser?

The MySQL Query Browser is a graphical tool designed to provide a user friendly environment in which to construct and execute SQL statements.

Q: – Explain “AUTO_INCREMENT” attribute?

AUTO_INCREMENT attribute may be added to an integer column definition to create a column for which MySQL automatically generates a new sequence number each time you create a new row. There may be only one AUTO_INCREMENT column per table, the column must be indexed, and the column must be defined as NOT NULL.

Q: – What this command “mysqladmin status variables” will do?

This command will display a brief status message, followed by the list of server system variables.

Q: – Explain “CHECK TABLE” statement?

The CHECK TABLE statement performs an integrity check on table structure and contents. It works for MyISAM and InnoDB tables. For MyISAM tables, it also updates the index statistics. If the table is a view, CHECK TABLE verifies the view definition.

Q: – Explain “REPAIR TABLE” statement?

The REPAIR TABLE statement corrects problems in a table that has become corrupted. It works only for MyISAM tables.

Q: – Explain “ANALYZE TABLE” statement?

The ANALYZE TABLE statement updates a table with information about the distribution of key values in the table. This information is used by the optimizer to make better choices about query execution plans. This statement works for MyISAM and InnoDB tables.

Q: – Explain “OPTIMIZE TABLE” statement?

The OPTIMIZE TABLE statement cleans up a MyISAM table by defragmenting it. This involves reclaiming unused space resulting from deletes and updates, and coalescing records that have become split and stored non-contiguously. OPTIMIZE TABLE also sorts the index pages if they are out of order and updates the index statistics.

Q: – What is “mysqlcheck Client Program”?

mysqlcheck checks, repairs, analyzes, and optimizes tables. It can perform all these operations on MyISAM tables, and can perform some of them on InnoDB tables. It provides a command-line interface to the various SQL statements that instruct the server to perform table maintenance, such as CHECK TABLE and REPAIR TABLE.

Q: – What is “myisamchk Utility”?

The myisamchk utility performs table maintenance on MyISAM tables.

Q: – What is the use of “INFORMATION_SCHEMA Database”?

The INFORMATION_SCHEMA database provides access to database metadata.INFORMATION_SCHEMA is a “virtual database” in the sense that it is not stored anywhere on disk. But like any other database, it contains tables, and its tables contain rows and columns that can be accessed by means of SELECT statements.

Q: – What is “binary backup”?

A binary backup is a copy of the files in which database contents are stored. Copying these files preserves the databases in exactly the same format in which MySQL itself stores them on disk. Restoration involves copying the files back to their original locations. Techniques for making binary backups include file copy commands.

Q: – What is “text backup”?

A text backup is a dump of database contents into text files. Restoration involves loading the file contents back into databases by processing them through the server. Techniques for making text backups include the SELECT … INTO OUTFILE SQL statement, mysqldump, and MySQL Administrator.

Q: – How you will grant the SELECT privilege for all tables in the TEST database to a user named Ravi, who must connect from the local host and use a password of Ravi123?

Use following command.

GRANT SELECT ON TEST.* TO ‘Ravi’@’localhost’ IDENTIFIED BY ‘Ravi123’;

Q: – Explain “REVOKE statement”?

The REVOKE statement to revoke privileges from an account.

Q: – Explain the command “SHOW GRANTS FOR ‘root’@’localhost’;”

It will show the account has global, database-level, and table-level privileges.

.net Interview Questions And Answers

Q: – What is “Common Language Specification” (CLS) in .NET? 

CLS is the collection of the rules and constraints that every language (that seeks to achieve .NET compatibility) must follow. It is a subsection of CTS and it specifies how it shares and extends one another libraries.

Q: – What are Attributes in .NET? 

Attributes are declarative tags in code that insert additional metadata into an assembly. There exist two types of attributes in the .NET Framework: Predefined attributes such as Assembly Version, which already exist and are accessed through the Runtime Classes; and custom attributes, which you write yourself by extending the System

Q: – What are possible implementations of distributed applications in .NET?

.NET Remoting and ASP.NET Web Services. If we talk about the Framework Class Library, noteworthy classes are in System.Runtime.Remoting and System.Web.Services.

 

Q: – How to manage pagination in a page using .NET?

Using pagination option in DataGrid control is available in .NET. We have to set the number of records for a page, then it takes care of pagination by itself automatically.

 

Q: – What is ADO .NET and what is difference between ADO and ADO.NET?

ADO.NET is stateless mechanism. I can treat the ADO.Net as a separate in-memory database where in I can use relationships between the tables and select insert and updates to the database. I can update the actual database as a batch.

 

Q: – What is Reflection in .NET? 

It extends the benefits of metadata by allowing developers to inspect and use it at runtime. For example, dynamically determine all the classes contained in a given assembly and invoke their methods. Reflection provides objects that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object. You can then invoke the type’s methods or access its fields and properties. Namespace: System.Reflection

Q: – What Is ASP.NET?

ASP.NET, or Active Server Pages for the .NET Framework, is a technology for providing dynamic Web page content to your users.

 

Q Does using code-behind techniques with ASP.NET result in faster code?
No

Q Is the Page_Load event the best place to validate the contents of an ASP.NET page?

No

Q: – What Is XML?

XML is a way to represent structured data. Just like HTML, XML uses tags to enclose each piece of data. Unlike HTML, however, with XML you pick the names for each tag so that they are appropriate for your own dataset. One big advantage of XML is that the data contained in XML files is “self-describing,” because each data element is enclosed in HTML-like tags that give contextual clues about the data.

 

Q: – What Is XSL?

The eXtensible Stylesheet Language (XSL) is used to transform XML files into HTML, new and differently formatted XML files, text files, or other formats.

 

Q: – I want to add a custom method to my typed dataset. How should I do this?

 Don’t modify the automatically generated file itself because Visual Studio could rewrite it when you modify the source XML Schema. Instead, create a new class derived from the automatically generated class with your custom methods.

 

Q: – I store all my application data using XML. Can I still use the techniques presented
in the last part of this chapter?

Yes

 

Q Which UDDI provider should I use to publish my Web Service?

Choosing a UDDI provider is only a matter of personal preference. All UDDI providers share the same database of information. After you make a UDDI entry in one provider, the entry propagates to all other UDDI providers within a short amount of time.

 

Q: – Can malicious users read my configuration files and find out confidential information about my Web site?

No

 

Q: – I store all my application data using XML. Can I still use the techniques presented
in the last part of this chapter?

Yes

 

Q Which UDDI provider should I use to publish my Web Service?

Choosing a UDDI provider is only a matter of personal preference. All UDDI providers share the same database of information. After you make a UDDI entry in one provider, the entry propagates to all other UDDI providers within a short amount of time.

 

Q: – Can malicious users read my configuration files and find out confidential information about my Web site?

No