Category Archives: DB Articles

Important Backup Options

Important Backup options

INIT

Specifies that all backup sets should be overwritten, but preserves the media header. If INIT is specified, any existing backup set data on that device is overwritten.

The backup media is not overwritten if any one of the following conditions is met:

  • All backup sets on the media have not yet expired. For more information, see the EXPIREDATE and RETAINDAYS options.
  • The backup set name given in the BACKUP statement, if provided, does not match the name on the backup media. For more information, see the NAME clause.

Use the SKIP option to override these checks. For more information about interactions when using SKIP, NOSKIP, INIT, and NOINIT, see the Remarks section.

Note If the backup media is password protected, SQL Server does not write to the media unless the media password is supplied. This check is not overridden by the SKIP option. Password-protected media may be overwritten only by reformatting it. For more information, see the FORMAT option.

NOINIT

Indicates that the backup set is appended to the specified disk or tape device, preserving existing backup sets. NOINIT is the default.

The FILE option of the RESTORE command is used to select the appropriate backup set at restore time

STANDBY = undo_file_name

Used only with BACKUP LOG. Backs up the tail of the log and leaves the database in read-only and standby mode. The undo file name specifies storage to hold rollback changes which must be undone if RESTORE LOG operations are to be subsequently applied.

If the specified undo file name does not exist, SQL Server creates it. If the file does exist, SQL Server overwrites it

NOUNLOAD

Specifies the tape is not unloaded automatically from the tape drive after a backup. NOUNLOAD remains set until UNLOAD is specified. This option is used only for tape devices.

UNLOAD

Specifies that the tape is automatically rewound and unloaded when the backup is finished. UNLOAD is set by default when a new user session is started. It remains set until that user specifies NOUNLOAD. This option is used only for tape devices.

RESTART

Specifies that SQL Server restarts an interrupted backup operation. The RESTART option saves time because it restarts the backup operation at the point it was interrupted. To RESTART a specific backup operation, repeat the entire BACKUP statement and add the RESTART option. Using the RESTART option is not required but can save time.

NO_LOG | TRUNCATE_ONLY

Removes the inactive part of the log without making a backup copy of it and truncates the log. This option frees space. Specifying a backup device is unnecessary because the log backup is not saved. NO_LOG and TRUNCATE_ONLY are synonyms.

After backing up the log using either NO_LOG or TRUNCATE_ONLY, the changes recorded in the log are not recoverable

NO_TRUNCATE

Allows backing up the log in situations where the database is damaged.

Java Interview Questions

Q) What is difference between Java and C++?

A) (i) Java does not support pointers. Pointers are inherently insecure and troublesome. Since pointers do not exist in Java. (ii) Java does not support operator overloading. (iii) Java does not perform any automatic type conversions that result in a loss of precision (iv) All the code in a Java program is encapsulated within one or more classes. Therefore, Java does not have global variables or global functions. (v) Java does not support multiple inheritance.

Java does not support destructors, but rather, add the finalize() function. (vi) Java does not have the delete operator. (vii) The <<>> are not overloaded for I/O operations

Q) Opps concepts

Polymorphism
Ability to take more than one form, in java we achieve this using Method Overloading (compile time polymorphism), Method overriding (runtime polymorphism)
Inheritance
Is the process by which one object acquires the properties of another object. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.
Encapsulation
Wrapping of data and function into a single unit called encapsulation. Ex:- all java programs.
(Or)
Nothing but data hiding, like the variables declared under private of a particular class are accessed only in that class and cannot access in any other the class. Or Hiding the information from others is called as Encapsulation. Or Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse.
Abstraction
Nothing but representing the essential futures without including background details.
Dynamicbinding
Code associated with a given procedural call is not known until the time of the call at runtime. Dynamic binding is nothing but late binding.

Q) class & object?
class
class is a blue print of an object
Object
instance of class.

Q) Object creation?
Object is constructed either on a memory heap or on a stack.

Memory heap
Generally the objects are created using the
new keyword. Some heap memory is allocated to this newly created object. This memory remains allocated throughout the life cycle of the object. When the object is no more referred, the memory allocated to the object is eligible to be back on the heap.

Stack
During method calls, objects are created for method arguments and method variables. These objects are created on stack.

Q) System.out.println()
println() is a methd of java.io.printWriter.
“out” is an instance variable of java.lang.System class.

Q) Transient & volatile

Transient –> The transient modifier applies to variables only, the object are variable will not persist. Transient variables are not serialized.

Volatile –> value will be changed unexpectedly by the other part of the program, “it tells the
compiler a variable may change asynchronously due to threads”

Q) Access Specifiers & Access modifiers?
Access Specifiers A.S gives access privileges to outside of application (or) others, they are Public, Protected, Private, Defaults.

Access Modifiers A.M which gives additional meaning to data, methods and classes, final cannot be modified at any point of time.


Private

Public

Protected

No modifier

Same class

No

Yes

Yes

Yes

Same package Subclass

No

Yes

Yes

Yes

Same package non-subclass

No

Yes

Yes

Yes

Different package subclass

No

Yes

Yes

No

Different package non-subclass

No

Yes

No

No

Q) Default Values

long

-2^63 to 2^63 –1 à 0L

double

0.0d

Int

-2^31 to 2^31 –1 à 0

float

0.0f

Short

-2^15 to 2^15 –1 à 0

Boolean

false

Byte

-2^7 to 2^7 –1 à 0

char

0 to 2^7 –1 à null character (or) ‘\u 0000’


Q) Byte code & JIT compiler & JVM & JRE & JDK
Byte code is a highly optimized set of instructions. JVM is an interpreter for byte code. Translating a java program into byte code helps makes it much easier to run a program in a wide variety of environment.

JVM is an interpreter for byte code
JIT (Just In Time) is a part of JVM, it compiles byte code into executable code in real time, will increase the performance of the interpretations.
JRE
is an implementation of the Java Virtual Machine, which actually executes Java programs.
JDK is bundle of software that you can use to develop Java based software, Tools provided by JDK is

(i) javac – compiler (ii) java – interpretor (iii) jdb – debugger (iv) javap – Disassembles

(v) appletviewer – Applets (vi) javadoc – documentation generator (vii) javah – ‘C’ header file generator

Q) Wrapper classes

Primitive data types can be converted into objects by using wrapper classes. These are java.lang.package.

Q) Does Java pass method arguments by value or by reference?

Java passes all arguments by value, not by reference

Q) Arguments & Parameters

While defining method, variable passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

Q) Public static void main (String [] args)

à We can overLoad the main() method.

à What if the main method is declared as “Private”?

The program compiles properly but at runtime it will give “Main method not public.” Message

à What if the static modifier is removed from the signature of the main method?

Program compiles. But at runtime throws an error “NoSuchMethodError”.

à We can write “static public void” instead of “public static void” but not “public void static”.

à Protected static void main(), static void main(), private static void main() are also valid.

à If I do not provide the String array as the argument to the method?

Program compiles but throws a runtime error “NoSuchMethodError”.

à If no arguments on the command line, String array of Main method will be empty or null?

It is empty. But not null.

à Variables can have the same name as a method or a class

 

Q) Can an application have multiple classes having main() method?

A) Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.

 

Q) Can I have multiple main methods in the same class?

A) No the program fails to compile. The compiler says that the main method is already defined in the class.

Q) Constructor

The automatic initialization is performed through the constructor, constructor has same name has class name. Constructor has no return type not even void. We can pass the parameters to the constructor. this() is used to invoke a constructor of the same class. Super() is used to invoke a super class constructor. Constructor is called immediately after the object is created before the new operator completes.

à Constructor can use the access modifiers public, protected, private or have no access modifier

à Constructor can not use the modifiers abstract, static, final, native, synchronized or strictfp

à Constructor can be overloaded, we cannot override.

à You cannot use this() and Super() in the same constructor.

Class A(
A(){

System.out.println(“hello”);

}}

Class B extends A {

B(){

System.out.println(“friend”);

}}

Class print {

Public static void main (String args []){

B b = new B();

}

o/p:- hello friend

Q) Diff Constructor & Method

Constructor

Method

Use to instance of a class
Grouping java statement

No return type

Void (or) valid return type

Same name as class name

As a name except the class method name, begin with lower case.

“This” refer to another constructor in the same class

Refers to instance of class

“Super” to invoke the super class constructor

Execute an overridden method in the super class
Inheritance” cannot be inherited

Can be inherited

We can “overload” but we cannot “overridden

Can be inherited

Will automatically invoke when an object is created

Method has called explicitly

Q) Garbage collection

G.C is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program cann’t directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use, calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected. Garbage collection is a low-priority thread.

 

G.C is a low priority thread in java, G.C cannot be forced explicitly. JVM may do garbage collection if it is running short of memory. The call System.gc() does NOT force the garbage collection but only suggests that the JVM may make an effort to do garbage collection.
<!–[if !supportLineBreakNewLine]–>
<!–[endif]–>

Q) How an object becomes eligible for Garbage Collection?

A) An object is eligible for garbage collection when no object refers to it, An object also becomes eligible when its reference is set to null. The objects referred by method variables or local variables are eligible for garbage collection when they go out of scope.

Integer i = new Integer(7);
i =
null;

Q) Final, Finally, Finalize

Final: – When we declare a sub class a final the compiler will give error as “cannot subclass final class” Final to prevent inheritance and method overriding. Once to declare a variable as final it cannot occupy memory per instance basis.

à Final class cannot have static methods

à Final class cannot have abstract methods (Because of final class never allows any class to inherit it)

à Final class can have a final method.

Finally: – Finally create a block of code that will be executed after try catch block has completed. Finally block will execute whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally clause is also execute.

Using System.exit() in try block will not allow finally code to execute

Finalize: – some times an object need to perform some actions when it is going to destroy, if an object holding some non-java resource such as file handle (or) window character font, these resources are freed before the object is going to destroy.

Q) Can we declare abstract method in final class?

A) It indicates an error to declare abstract method in final class. Because of final class never allows any class to inherit it.

Q) Can we declare final method in abstract class?

A) If a method is defined as final then we can’t provide the reimplementation for that final method in it’s derived classes i.e overriding is not possible for that method. We can declare final method in abstract class suppose of it is abstract too, then there is no used to declare like that.

Q) Superclass & Subclass

A super class is a class that is inherited whereas subclass is a class that does the inheriting

Q) How will u implement 1) polymorphism 2) multiple inheritance 3) multilevel inheritance in java?

A) Polymorphism – overloading and overriding

Multiple inheritances – interfaces.

Multilevel inheritance – extending class.

Q) Overloading & Overriding?

Overloading (Compile time polymorphism)

Define two or more methods within the same class (or) subclass that share the same name and their number of parameter, order of parameter & return type are different then the methods are said to be overloaded.

· Overloaded methods do not have any restrictions on what return type of Method (Return type are different) (or) exceptions can be thrown. That is something to worry about with overriding.

· Overloading is used while implementing several methods that implement similar behavior but for different data types.

Overriding (Runtime polymorphism)

 

When a method in a subclass has the same name, return type & parameters as the method in the super class then the method in the subclass is override the method in the super class.
The access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method.

 

· If the superclass method is public, the overriding method must be public.

· If the superclass method is protected, the overriding method may be protected or public.

· If the superclass method is package, the overriding method may be packagage, protected, or public.

· If the superclass methods is private, it is not inherited and overriding is not an issue.

· Methods declared as final cannot be overridden.

 

The throws clause of the overriding method may only include exceptions that can be thrown by the superclass method, including its subclasses.

member method can be overriden, not member variable

class Parent{

int i = 0;

void amethod(){

System.out.println(“in Parent”);

}

}

class Child extends Parent{

int i = 10;

void amethod(){

System.out.println(“in Child”);

}

}

class Test{

public static void main(String[] args){

Parent p = new Child();

Child c = new Child();

System.out.print(“i=”+p.i+” “);

p.amethod ();

System.out.print(“i=”+c.i+” “);

c.amethod();

}

}

o/p: – i=0 in Child i=10 in Child

Q) Final variable

Once to declare a variable as final it cannot occupy memory per instance basis.

Q) Static block

Static block which exactly executed exactly once when the class is first loaded into JVM. Before going to the main method the static block will execute.

 

Q) Static variable & Static method

Static variables & methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class.

Static methods can be referenced with the name of the class. It may not access the instance variables of that class, only its static variables. Further it may not invoke instance (non-static) methods of that class unless it provides them with some object.
a member is declared a static it can be accessed before any object of its class are created.
Instance variables declared as static are essentially global variables.
If you do not specify an initial value to an instance & Static variable a default value will be assigned automatically.
Methods declared as static have some restrictions they can access only static data, they can only call other static data, they cannot refer this or super.

Static methods cant be overriden to non-static methods.
Static methods is called by the static methods only, an ordinary method can call the static methods, but static methods cannot call ordinary methods.

 

 

 

Static methods are implicitly “final”, because overriding is only done based on the type of the objects
They cannot refer “this” are “super” in any way.
Q) Class variable & Instance variable & Instance methods & class methods
Instance variable
à variables defined inside a class are called instance variables with multiple instance of class, each instance has a variable stored in separate memory location.
Class variables
à you want a variable to be common to all classes then we crate class variables. To create a class variable put the “static” keyword before the variable name.
Class methods
à we create class methods to allow us to call a method without creating instance of the class. To declare a class method use the “static” key word .
Instance methods
à we define a method in a class, in order to use that methods we need to first create objects of the class.
Q) Static methods cannot access instance variables why?
Static methods can be invoked before the object is created; Instance variables are created only when the new object is created. Since there is no possibility to the static method to access the instance variables. Instance variables are called called as non-static variables.

Q) String & StringBuffer
String is a fixed length of sequence of characters, String is immutable.

StringBuffer represent growable and writeable character sequence, StringBuffer is mutable which means that its value can be changed. It allocates room for 16-addition character space when no specific length is specified. Java.lang.StringBuffer is also a final class hence it cannot be sub classed. StringBuffer cannot be overridden the equals() method.

Q) Conversions

String to Int Conversion: –
int I = integer.valueOf(“24”).intValue();
int x = integer.parseInt(“433”);
float f = float.valueOf(23.9).floatValue();

Int to String Conversion :-

String arg = String.valueOf(10);

Q) Super()

Super() always calling the constructor of immediate super class, super() must always be the first statements executed inside a subclass constructor.

 

Q) What are different types of inner classes?

A) Nested top-level classes– If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. e.g., outer.inner. Top-level inner classes implicitly have access only to static variables. There can also be inner interfaces. All of these are of the nested top-level variety.

Member classes – Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.

Local classesLocal classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface. Because local classes are not members the modifiers public, protected, private and static are not usable.

Anonymous classes – Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.

Inner class inside method cannot have static members or blocks

Q) Which circumstances you use Abstract Class & Interface?
–> If you need to change your design make it an interface.
–> Abstract class provide some default behaviour, A.C are excellent candidates inside of application framework. A.C allow single inheritance model, which should be very faster.

Q) Abstract Class

Any class that contain one are more abstract methods must also be declared as an abstract, there can be no object of an abstract class, we cannot directly instantiate the abstract classes. A.C can contain concrete methods.

Any sub class of an Abstract class must either implement all the abstract methods in the super class or be declared itself as Abstract.

Compile time error occur if an attempt to create an instance of an Abstract class.

You cannot declare “abstract constructor” and “abstract static method”.

An “abstract method” also declared private, native, final, synchronized, strictfp, protected.

Abstract class can have static, final method (but there is no use).

Abstract class have visibility public, private, protected.

By default the methods & variables will take the access modifiers is , which is accessibility as package.

An abstract method declared in a non-abstract class.

An abstract class can have instance methods that implement a default behavior.

A class can be declared abstract even if it does not actually have any abstract methods. Declaring such a class abstract indicates that the implementation is somehow incomplete and is meant to serve as a super class for one or more subclasses that will complete the implementation.

A class with an abstract method. Again note that the class itself is declared abstract, otherwise a compile time error would have occurred.

Abstract class A{
Public abstract callme();
Void callmetoo(){
}
}

class B extends A( void callme(){

}
}

class AbstractDemo{
public static void main(string args[]){
B b = new B();
b.callme();
b.callmetoo();
}
}

 Q) When we use Abstract class?
A) Let us take the behaviour of animals, animals are capable of doing different things like flying, digging, Walking. But these are some common operations performed by all animals, but in a different way as well. When an operation is performed in a different way it is a good candidate for an abstract method.

Public Abstarctclass Animal{
Public void eat(food food) {
}
public void sleep(int hours) {
}
public abstract void makeNoise()
}

public Dog extends Animal
{
public void makeNoise() {
System.out.println(“Bark! Bark”);
}
}

public Cow extends Animal
{
public void makeNoise() {
System.out.println(“moo! moo”);
}
}

Q) Interface 
Interface is similar to class but they lack instance variable, their methods are declared with out any body. Interfaces are designed to support dynamic method resolution at run time. All methods in interface are implicitly 
abstract, even if the abstract modifier is omitted. Interface methods have no implementation; 

Interfaces are useful for?
a) Declaring methods that one or more classes are expected to implement
b) Capturing similarities between unrelated classes without forcing a class relationship.

 

 

c) Determining an object’s programming interface without revealing the actual body of the class.Why Interfaces?
“ one interface multiple methods “ signifies the polymorphism concept.
Interface has visibility public.
Interface can be extended & implemented.
A
n interface body may contain constant declarations, abstract method declarations, inner classes and inner interfaces.
All methods of an interface are implicitly Abstract, P
ublic, even if the public modifier is omitted.
An interface methods cannot be declared
protected, private, strictfp, native or synchronized.
All Variables are implicitly final, public, static fields.
A compile time error occurs if an interface has a simple name the same as any of it’s enclosing classes or interfaces.
An Interface can only declare constants and instance methods, but cannot implement default behavior.

top-level
interfaces may only be declared public, inner interfaces may be declared private and protected but only if they are defined in a class.
A class can only extend one other class.
A class may implements more than one interface.
Interface can extend more than one interface.
Interface A
{
final static float pi = 3.14f;
}

 

class B implements A
{
public float compute(float x, float y) {
return(x*y);
}
}

 

class test{
public static void main(String args[])
{
A a = new B();
a.compute();
}
}

Q) Diff Interface & Abstract Class?
A.C may have some executable methods and methods left unimplemented. Interface contains no implementation code.
An A.C can have nonabstract methods. All methods of an Interface are abstract.
An A.C can have instance variables. An Interface cannot.
An A.C must have subclasses whereas interface can’t have subclasses
An A.C can define constructor. An Interface cannot.
An A.C can have any visibility: public, private, protected. An Interface visibility must be public (or) none.
An
A.C can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior.

Q) What is the difference between Interface and class?
A class has instance variable and an Interface has no instance variables.
Objects can be created for classes where as objects cannot be created for interfaces.
All methods defined inside class are concrete. Methods declared inside interface are without any body.

 

Q) What is the difference between Abstract class and Class?
Classes are fully defined. Abstract classes are not fully defined (incomplete class)
Objects can be created for classes, there can be no objects of an abstract class.

Q) What are some alternatives to inheritance?
A)
Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

 

Q) Serializable & Externalizable
Serializable –> is an interface that extends serializable interface and sends data into streams in compressed format. It has 2 methods writeExternal(objectOutput out), readExternal(objectInput in).
Externalizable
is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)

Q) Internalisation & Localization
Internalisation — Making a programme to flexible to run in any locale called internalisation.
Localization — Making a programme to flexible to run in a specific locale called Localization.

Q) Serialization
Serialization is the process of writing the state of the object to a byte stream, this is useful when ever you want to save the state of your programme to a persistence storage area.

Q) Synchronization
Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. (Or) When 2 are more threads need to access the shared resources they need to some way ensure that the resources will be used by only one thread at a time. This process which is achieved is called synchronization.

(i) Ex: – Synchronizing a function:
public synchronized void Method1 () {
}
<!–[if !supportLineBreakNewLine]–>
<!–[endif]–>(i) Ex: – Synchronizing a block of code inside a function:
public myFunction (){
synchronized (this) {
}
}

 

(iii) Ex: – public Synchronized void main(String args[])
But this is not the right approach because it means servlet can handle one request at a time.

 

(iv) Ex: – public Synchronized void service()
Servlet handle one request at a time in a serialized manner

 

Q) Different level of locking using Synchronization?
A)
Class level, Object level, Method level, Block level

 

Q) Monitor
A monitor is a mutex, once a thread enter a monitor, all other threads must wait until that thread exist the monitor.

 

Q) Diff = = and .equals()?
A)
== Compare object references whether they refer to the sane instance are not.
equals ()
method compare the characters in the string object.

StringBuffer sb1 = new StringBuffer(“Amit”);
StringBuffer sb2= new StringBuffer(“Amit”);
String s1 = “Amit”;
String s2 = “Amit”;
String s3 = new String(“abcd”);
String s4 = new String(“abcd”);
String ss1 = “Amit”;

String s1 = “abc”;
String s2 = new String(“abc”);

s1 == s2 F
s1.equals(s2))

Q) Marker Interfaces (or) Tagged Interfaces :-
An Interface with no methods. Is called marker Interfaces, eg. Serializable, SingleThread Model, Cloneable.

Q) URL Encoding & URL Decoding
URL Encoding is the method of replacing all the spaces and other extra characters into their corresponding Hex Characters and URL Decoding is the reverse process converting all Hex Characters back their normal form.

Q) URL & URLConnection
URL is to identify a resource in a network, is only used to read something from the network.
URL url = new URL(protocol name, host name, port, url specifier)

URLConnection can establish communication between two programs in the network.
URL hp = new URL(“www.yahoo.com”);
URLConnection con = hp.openConnection();

Q) Runtime class
Runtime class encapsulate the run-time environment. You cannot instantiate a Runtime object. You can get a reference to the current Runtime object by calling the static method Runtime.getRuntime()

Runtime r = Runtime.getRuntime()
Long mem1;
Mem1 = r.freeMemory();
Mem1 = r.totalMemory();

Q) Execute other programs
You can use java to execute other heavy weight process on your multi tasking operating system, several form of exec() method allow you to name the programme you want to run.

Runtime r = Runtime.getRuntime();
Process p = null;
Try{
p = r.exce(“notepad”);
p.waiFor()
}

Q) System class System class hold a collection of static methods and variables. The standard input, output, error output of the java runtime are stored in the in, out, err variables.

Q) Native Methods Native methods are used to call subroutine that is written in a language other than java, this subroutine exist as executable code for the CPU.

Q) Cloneable Interface
Any class that implements the cloneable interface can be cloned, this interface defines no methods. It is used to indicate that a class allow a bit wise copy of an object to be made.

Q) Clone
Generate a duplicate copy of the object on which it is called. Cloning is a dangerous action.

Q) Comparable Interface
Classes that implements comparable contain objects that can be compared in some meaningful manner. This interface having one method compare the invoking object with the object. For sorting comparable interface will be used.
Ex:- int compareTo(Object obj)

Q) Class
Class encapsulate the run-time state of an object or interface. Methods in this class are

static Class forName(String name) throws ClassNotFoundException

getClass()

getClassLoader()

getConstructor()

getField()

getDeclaredFields()

getMethods()

getDeclearedMethods()

getInterface()

getSuperClass()

Q) java.jlang.Reflect (package)
Reflection is the ability of software to analyse it self, to obtain information about the field, constructor, methods & modifier of class. You need this information to build software tools that enables you to work with java beans components.

Q) InstanceOf Instanceof means by which your program can obtain run time type information about an object.
Ex:- A a = new A();

a.instanceOf A;

Q) Java pass arguments by value are by reference? A) By value
Q) Java lack pointers how do I implements classic pointer structures like linked list? A) Using object reference.
Q) java. Exe Microsoft provided sdk for java, which includes “jexegentool”. This converts class file into a “.Exec”  form. Only disadvantage is user needs a M.S java V.M installed.

Q) Bin & Lib in jdk?
Bin contains all tools such as javac, appletviewer and awt tool.
Lib contains API and all packages.

SQL Server Fixed Database-Level Roles

SQL Server Fixed Database-Level Roles

Fixed database roles are defined at the database level and exist in each database. Members of the db_owner and db_securityadmin database roles can manage fixed database role membership; however, only members of the db_owner database role can add members to the db_owner fixed database role.

The fixed database roles are the following:
* db_accessadmin
* db_backupoperator
* db_datareader
* db_datawriter
* db_ddladmin

For the full version of article please visit http://sqldbpool.blogspot.com/

SQL Server 2005 Interview Questions

Download SQL Server Interview Question

• If I want to see what fields a table is made of, and what the sizes of the
fields are, what option do I have to look for?
Sp_Columns ‘TableName’

• What is a query?
A request for information from a database. There are three general methods for posing queries:
# Choosing parameters from a menu: In this method, the database system presents a list of parameters from which you can choose. This is perhaps the easiest way to pose a query because the menus guide you, but it is also the least flexible.
# Query by example (QBE): In this method, the system presents a blank record and lets you specify the fields and values that define the query.
# Query language: Many database systems require you to make requests for information in the form of a stylized query that must be written in a special query language. This is the most complex method because it forces you to learn a specialized language, but it is also the most powerful.

• What is the purpose of the model database?
It works as Template Database for the Create Database Syntax

• What is the purpose of the master database?
Master database keeps the information about sql server configuration, databases users etc

• What is the purpose of the tempdb database?
Tempdb database keeps the information about the temporary objects (#TableName, #Procedure). Also the sorting, DBCC operations are performed in the TempDB

• What is the purpose of the USE command?
Use command is used for to select the database. For i.e Use Database Name

• If you delete a table in the database, will the data in the table be deleted too?
Yes

• What is the Parse Query button used for? How does this help you?
Parse query button is used to check the SQL Query Syntax

• Tables are created in a ____________________ in SQL Server 2005.
resouce database(System Tables)

• What is usually the first word in a SQL query?
SELECT

• Does a SQL Server 2005 SELECT statement require a FROM?
NO

• Can a SELECT statement in SQL Server 2005 be used to make an assignment? Explain with examples.
Yes. Select @MyDate = GetDate()

• What is the ORDER BY used for?
Order By clause is used for sorting records in Ascending or Descending order

• Does ORDER BY actually change the order of the data in the tables or does it just
change the output?

Order By clause change only the output of the data

• What is the default order of an ORDER BY clause?
Ascending Order

• What kind of comparison operators can be used in a WHERE clause?

Operator Meaning
= (Equals) Equal to
> (Greater Than) Greater than
< (Less Than) Less than
>= (Greater Than or Equal To) Greater than or equal to
<= (Less Than or Equal To) Less than or equal to
<> (Not Equal To) Not equal to
!= (Not Equal To) Not equal to (not SQL-92 standard)
!< (Not Less Than) Not less than (not SQL-92 standard)
!> (Not Greater Than) Not greater than (not SQL-92 standard)

• What are four major operators that can be used to combine conditions on a WHERE
clause?

OR, AND, IN and BETWEEN

• What are the logical operators?

Operator Meaning
ALL TRUE if all of a set of comparisons are TRUE.
AND TRUE if both Boolean expressions are TRUE.
ANY TRUE if any one of a set of comparisons are TRUE.
BETWEEN TRUE if the operand is within a range.
EXISTS TRUE if a subquery contains any rows.
IN TRUE if the operand is equal to one of a list of expressions.
LIKE TRUE if the operand matches a pattern.
NOT Reverses the value of any other Boolean operator.
OR TRUE if either Boolean expression is TRUE.
SOME TRUE if some of a set of comparisons are TRUE.

•In a WHERE clause, do you need to enclose a text column in quotes? Do you need to enclose a numeric column in quotes?
Enclose Text in Quotes (Yes)
Enclose Number in Quotes (NO)

• Is a null value equal to anything? Can a space in a column be considered a null value? Why or why not?
No NULL value means nothing. We can’t consider space as NULL value.

• Will COUNT(column) include columns with null values in its count?
Yes, it will include the null column in count

• What are column aliases? Why would you want to use column aliases? How can you embed blanks in column aliases?
You can create aliases for column names to make it easier to work with column names, calculations, and summary values. For example, you can create a column alias to:
* Create a column name, such as “Total Amount,” for an expression such as (quantity * unit_price) or for an aggregate function.
* Create a shortened form of a column name, such as “d_id” for “discounts.stor_id.”
After you have defined a column alias, you can use the alias in a Select query to specify query output

• What are table aliases?
Aliases can make it easier to work with table names. Using aliases is helpful when:
* You want to make the statement in the SQL Pane shorter and easier to read.
* You refer to the table name often in your query — such as in qualifying column names — and want to be sure you stay within a specific character-length limit for your query. (Some databases impose a maximum

length for queries.)
* You are working with multiple instances of the same table (such as in a self-join) and need a way to refer to one instance or the other.

• What are table qualifiers? When should table qualifiers be used?
[@table_qualifier =] qualifier
Is the name of the table or view qualifier. qualifier is sysname, with a default of NULL. Various DBMS products support three-part naming for tables (qualifier.owner.name). In SQL Server, this column represents the database name. In some products, it represents the server name of the table’s database environment.

• Are semicolons required at the end of SQL statements in SQL Server 2005?
No it is not required

• Do comments need to go in a special place in SQL Server 2005?

No its not necessary

• When would you use the ROWCOUNT function versus using the WHERE clause?

Returns the number of rows affected by the last statement. If the number of rows is more than 2 billion, use ROWCOUNT_BIG.
Transact-SQL statements can set the value in @@ROWCOUNT in the following ways:
* Set @@ROWCOUNT to the number of rows affected or read. Rows may or may not be sent to the client.
* Preserve @@ROWCOUNT from the previous statement execution.
* Reset @@ROWCOUNT to 0 but do not return the value to the client.
Statements that make a simple assignment always set the @@ROWCOUNT value to 1.

• Is SQL case-sensitive? Is SQL Server 2005 case-sensitive?

No both are not case-sensitive. Case sensitivity depends on the collation you choose.
If you installed SQL Server with the default collation options, you might find that the following queries return the same results:

CREATE TABLE mytable
(
mycolumn VARCHAR(10)
)
GO

SET NOCOUNT ON

INSERT mytable VALUES(‘Case’)
GO

SELECT mycolumn FROM mytable WHERE mycolumn=’Case’
SELECT mycolumn FROM mytable WHERE mycolumn=’caSE’
SELECT mycolumn FROM mytable WHERE mycolumn=’case’

You can alter your query by forcing collation at the column level:

SELECT myColumn FROM myTable
WHERE myColumn COLLATE Latin1_General_CS_AS = ‘caSE’

SELECT myColumn FROM myTable
WHERE myColumn COLLATE Latin1_General_CS_AS = ‘case’

SELECT myColumn FROM myTable
WHERE myColumn COLLATE Latin1_General_CS_AS = ‘Case’

— if myColumn has an index, you will likely benefit by adding
— AND myColumn = ‘case’

• What is a synonym? Why would you want to create a synonym?

SYNONYM is a single-part name that can replace a two, three or four-part name in many SQL statements. Using SYNONYMS in RDBMS cuts down on typing.
SYNONYMs can be created for the following objects:

* Table
* View
* Assembly (CLR) Stored Procedure
* Assembly (CLR) Table-valued Function
* Assembly (CLR) Scalar Function
* Assembly Aggregate (CLR) Aggregate Functions
* Replication-filter-procedure
* Extended Stored Procedure
* SQL Scalar Function
* SQL Table-valued Function
* SQL Inline-table-valued Function
* SQL Stored Procedure

Syntax
CREATE SYNONYM [ schema_name_1. ] synonym_name FOR < object >

< object > :: =
{
[ server_name.[ database_name ] . [ schema_name_2 ].| database_name . [ schema_name_2 ].| schema_name_2. ] object_name
}

• Can a synonym name of a table be used instead of a table name in a SELECT statement?
Yes

• Can a synonym of a table be used when you are trying to alter the definition of a table?
Not Sure will try

• Can you type more than one query in the query editor screen at the same time?
Yes we can.

• While you are inserting values into a table with the INSERT INTO .. VALUES option, does the order of the columns in the INSERT statement have to be the same as the order of the columns in the table?
Not Necessary

• While you are inserting values into a table with the INSERT INTO .. SELECT option, does the order of the columns in the INSERT statement have to be the same as the order of the columns in the table?
Yes if you are not specifying the column names in the insert clause, you need to maintain the column order in SELECT statement

• When would you use an INSERT INTO .. SELECT option versus an INSERT INTO .. VALUES option? Give an example of each.
INSERT INTO .. SELECT is used insert data in to table from diffrent tables or condition based insert
INSERT INTO .. VALUES you have to specify the insert values

• What does the UPDATE command do?
Update command will modify the existing record

• Can you change the data type of a column in a table after the table has been created? If so,which command would you use?

Yes we can. Alter Table Modify Column

• Will SQL Server 2005 allow you to reduce the size of a column?
Yes it allows

• What integer data types are available in SQL Server 2005?

Exact-number data types that use integer data.

Data type Range Storage
bigint -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807) 8 Bytes
int -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647) 4 Bytes
smallint -2^15 (-32,768) to 2^15-1 (32,767) 2 Bytes
tinyint 0 to 255 1 Byte


• What is the default value of an integer data type in SQL Server 2005?

NULL

• What is the difference between a CHAR and a VARCHAR datatype?

CHAR and VARCHAR data types are both non-Unicode character data types with a maximum length of 8,000 characters. The main difference between these 2 data types is that a CHAR data type is fixed-length while a VARCHAR is variable-length. If the number of characters entered in a CHAR data type column is less than the declared column length, spaces are appended to it to fill up the whole length.

Another difference is in the storage size wherein the storage size for CHAR is n bytes while for VARCHAR is the actual length in bytes of the data entered (and not n bytes).

You should use CHAR data type when the data values in a column are expected to be consistently close to the same size. On the other hand, you should use VARCHAR when the data values in a column are expected to vary considerably in size.

• Does Server SQL treat CHAR as a variable-length or fixed-length column?
SQL Server treats CHAR as fixed length column

• If you are going to have too many nulls in a column, what would be the best data type to use?
Variable length columns only use a very small amount of space to store a NULL so VARCHAR datatype is the good option for null values

• When columns are added to existing tables, what do they initially contain?

The column initially contains the NULL values

• What command would you use to add a column to a table in SQL Server?

ALTER TABLE tablename ADD column_name DATATYPE

• Does an index slow down updates on indexed columns?
Yes

• What is a constraint?

Constraints in Microsoft SQL Server 2000/2005 allow us to define the ways in which we can automatically enforce the integrity of a database. Constraints define rules regarding permissible values allowed in columns and are the standard mechanism for enforcing integrity. Using constraints is preferred to using triggers, stored procedures, rules, and defaults, as a method of implementing data integrity rules. The query optimizer also uses constraint definitions to build high-performance query execution plans.

• How many indexes does SQL Server 2005 allow you to have on a table?
250 indices per table

• What command would you use to create an index?
CREAT INDEX INDEXNAME ON TABLE(COLUMN NAME)

• What is the default ordering that will be created by an index (ascending or descending)?
Clustered indexes can be created in SQL Server databases. In such cases the logical order of the index key values will be the same as the physical order of rows in the table.
By default it is ascending order, we can also specify the index order while index creation.
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
ON { table | view } ( column [ ASC | DESC ] [ ,…n ] )

• How do you delete an index?
DROP INDEX authors.au_id_ind

• What does the NOT NULL constraint do?
Constrain will not allow NULL values in the column

• What command must you use to include the NOT NULL constraint after a table has already been created?
DEFAULT, WITH CHECK or WITH NOCHECK

• When a PRIMARY KEY constraint is included in a table, what other constraints does this imply?
Unique + NOT NULL

• What is a concatenated primary key?

Each table has one and only one primary key, which can consist of one or many columns. A concatenated primary key comprises two or more columns. In a single table, you might find several columns, or groups of columns, that might serve as a primary key and are called candidate keys. A table can have more than one candidate key, but only one candidate key can become the primary key for that table

• How are the UNIQUE and PRIMARY KEY constraints different?
A UNIQUE constraint is similar to PRIMARY key, but you can have more than one UNIQUE constraint per table.

When you declare a UNIQUE constraint, SQL Server creates a UNIQUE index to speed up the process of searching for duplicates. In this case the index defaults to NONCLUSTERED index, because you can have only one CLUSTERED index per table.

* The number of UNIQUE constraints per table is limited by the number of indexes on the table i.e 249 NONCLUSTERED index and one possible CLUSTERED index.

Contrary to PRIMARY key UNIQUE constraints can accept NULL but just once. If the constraint is defined in a combination of fields, then every field can accept NULL and can have some values on them, as long as the combination values is unique.

• What is a referential integrity constraint? What two keys does the referential integrity constraint usually include?

Referential integrity in a relational database is consistency between coupled tables. Referential integrity is usually enforced by the combination of a primary key or candidate key (alternate key) and a foreign key. For referential integrity to hold, any field in a table that is declared a foreign key can contain only values from a parent table’s primary key or a candidate key. For instance, deleting a record that contains a value referred to by a foreign key in another table would break referential integrity. The relational database management system (RDBMS) enforces referential integrity, normally either by deleting the foreign key rows as well to maintain integrity, or by returning an error and not performing the delete. Which method is used would be determined by the referential integrity constraint, as defined in the data dictionary.

• What is a foreign key?

FOREIGN KEY constraints identify the relationships between tables.
A foreign key in one table points to a candidate key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no candidate keys with that value. In the following sample, the order_part table establishes a foreign key referencing the part_sample table defined earlier. Usually, order_part would also have a foreign key against an order table, but this is a simple example.

CREATE TABLE order_part
(order_nmbr int,
part_nmbr int
FOREIGN KEY REFERENCES part_sample(part_nmbr)
ON DELETE NO ACTION,
qty_ordered int)
GO

You cannot insert a row with a foreign key value (except NULL) if there is no candidate key with that value. The ON DELETE clause controls what actions are taken if you attempt to delete a row to which existing foreign keys point. The ON DELETE clause has two options:

NO ACTION specifies that the deletion fails with an error.

CASCADE specifies that all the rows with foreign keys pointing to the deleted row are also deleted.
The ON UPDATE clause defines the actions that are taken if you attempt to update a candidate key value to which existing foreign keys point. It also supports the NO ACTION and CASCADE options.


• What does the ON DELETE CASCADE option do?

ON DELETE CASCADE
Specifies that if an attempt is made to delete a row with a key referenced by foreign keys in existing rows in other tables, all rows containing those foreign keys are also deleted. If cascading referential actions have also been defined on the target tables, the specified cascading actions are also taken for the rows deleted from those tables.

ON UPDATE CASCADE
Specifies that if an attempt is made to update a key value in a row, where the key value is referenced by foreign keys in existing rows in other tables, all of the foreign key values are also updated to the new value specified for the key. If cascading referential actions have also been defined on the target tables, the specified cascading actions are also taken for the key values updated in those tables.


• What does the ON UPDATE NO ACTION do?

ON DELETE NO ACTION
Specifies that if an attempt is made to delete a row with a key referenced by foreign keys in existing rows in other tables, an error is raised and the DELETE is rolled back.

ON UPDATE NO ACTION
Specifies that if an attempt is made to update a key value in a row whose key is referenced by foreign keys in existing rows in other tables, an error is raised and the UPDATE is rolled back.

• Can you use the ON DELETE and ON UPDATE in the same constraint?
Yes we can.
CREATE TABLE part_sample
(part_nmbr int PRIMARY KEY,
part_name char(30),
part_weight decimal(6,2),
part_color char(15) )

CREATE TABLE order_part
(order_nmbr int,
part_nmbr int
FOREIGN KEY REFERENCES part_sample(part_nmbr)
ON DELETE NO ACTION ON UPDATE NO ACTION,
qty_ordered int)
GO

Download SQL Server Interview Question