Question Related to Abstract Class

Q1: Must abstract classes contain at least one abstract method?
A: No, abstract classes are not required to have any abstract methods, they can simply be marked abstract for general design reasons. An abstract class may contain a full set of functional, integrated methods but have no practical use in its basic form, for example. In other words, they may require extension with additional methods to fulfil a range of different purposes. If the purpose is not specified by abstract method signatures, the range of potential applications for subclasses can be very broad.

Q2: How can an abstract method be inherited?
A: A subclass inherits all non-private fields and methods of its superclass whether the methods are abstract or have concrete implementations. If a subclass does not implement an abstract method, the subclass must be declared abstract itself. That means that an abstract method can be inherited through numerous abstract classes without any concrete implementation.
A common use of abstract methods is the template design pattern, where the common behaviour of a class hierarchy is defined in a set of concrete methods in an abstract superclass. Those core methods include calls to abstract template methods which must be implemented in concrete subclasses. This makes it relatively easy to implement subclasses and produce type-specific behaviour in each.
 
Q3: Why can't an abstract method be declared private?
A: The private and abstract method modifiers do not make sense in combination and the compiler should normally fail with a warning in this case. An abstract method must be overridden by any subclass, but subclasses do not have access to their superclass' private fields, so a private abstract method could never be fulfilled.

Q4: Why can't abstract methods be declared static?
A: The rule against static abstract methods is fundamentally a Java language design decision, which is not explained in the Java Language Specification. The abstract inheritance and implementation scheme is concerned with forming a structured collaboration of classes with deferred implementation of its abstract instance methods. This scheme can be verified at compile time to ensure it is safe at runtime.
Static methods must be concrete because they are attached to a specific host class and must be available to execute in a static context, when no object instance exists. It is not possible to assign an implementation to a static method at runtime, there is no mechanism to do that in Java.
It is also worth noting that static methods cannot be overridden by a subclass in Java. Static methods with the same signature effectively hide the superclass method. The concept of implementing a static method in a subclass would fail for the same reason, the concrete implementation would be attached to the “wrong” host.

Abstract Class In Java


Java Abstract classes are used to declare common characteristics of subclasses. An abstract class cannot be instantiated. It can only be used as a superclass for other classes that extend the abstract class. Abstract classes are declared with the abstract keyword. Abstract classes are used to provide a template or design for concrete subclasses down the inheritance tree.
Like any other class, an abstract class can contain fields that describe the characteristics and methods that describe the actions that a class can perform. An abstract class can include methods that contain no implementation. These are called abstract methods. The abstract method declaration must then end with a semicolon rather than a block. If a class has any abstract methods, whether declared or inherited, the entire class must be declared abstract. Abstract methods are used to provide a template for the classes that inherit the abstract methods.

Abstract classes cannot be instantiated; they must be subclassed, and actual implementations must be provided for the abstract methods. Any implementation specified can, of course, be overridden by additional subclasses. An object must have an implementation for all of its methods. You need to create a subclass that provides an implementation for the abstract method.
To declare that your class is an abstract class, use the keyword abstract before the class keyword in your class declaration:

abstract class Number {
. . .
}

If you attempt to instantiate an abstract class, the compiler displays an error similar to the following and refuses to compile your program:
AbstractTest.java:6: class AbstractTest is an abstract class.
It can't be instantiated.
new AbstractTest();
^
1 error

Points of abstract class :
1    Abstract class contains abstract methods.
2    Program can't instantiate an abstract class.
3    Abstract classes contain mixture of non-abstract and abstract methods.
4    If any class contains abstract methods then it must implements all the abstract methods of the abstract class.


Here is a simple example of a class with an abstract method, followed by a class which implements that method:
// A Simple demonstration of abstract.
abstract class A {
abstract void callme();
// concrete methods are still allowed in abstract classes
void callmetoo() {
System.out.println("This is a concrete method.");
}
}
class B extends A {
void callme() {
System.out.println("B's implementation of callme.");
}
}
class AbstractDemo {
public static void main(String args[]) {
B b = new B();
b.callme();
b.callmetoo();
}
}
Notice that no objects of class A are declared in the program. As mentioned, it is not possible to instantiate an abstract class. One other point: class A implements a concrete method called callmetoo( ). This is perfectly acceptable. Abstract classes can include as much implementation as they see fit.
 

Advantage of Abstract Classes

The advantage of using an abstract class is that you can group several related classes together as siblings. Grouping classes together is important in keeping a program organized and understandable. 

An Abstract class is a way to organize inheritance, sometimes it makes no since to implement every method in a class (i.e. a predator class), it may implement some to pass to its children but some methods cannot be implemented without knowing what the class will do (i.e. eat() in a Tiger class). Therefore, abstract classes are templates for future specific classes.

Disadvantage of Abstract Classes

A disadvantage is that abstract classes cannot be instantiated, but most of the time it is logical not to create a object of an abstract class.
 

Solution of Inconsistent Control File


Inconsistent error occur when Oracle detects an inconsistency between the multiplex copies of the control file. All copies of the control file must have the same internal sequence number Typical scenarios in which you may receive this inconsistencu error include:

1. You have restored the control file from backup, but you have forgot to copy it to other locations of the control file as listed in the "CONTROL_FILES" parameter in the initialization parameter.

2. You have moved one or more copies of the control file to a different location while the database was up and running.

3. You someone overwrote one of the copies of the control file with an old copy.

4. You are restoring a database backup that was improperly taken with the database up and running.


To get the solution of these problem start your database with single copy of the control file and then shut the database down and then copy of this good copy of control file to the other locations as listed in the control_files parameter.
Following these steps to solve this problem:

Step 1.  If database is still up, shutdown abort.

Step 2. If you use pfile then edit the CONTROL_FILES parameter from init.ora and modify it with one copy of control file.

If you use spfile then after startup nomount use show control_files to see existing controlfiles inside spfile and then you can use ALTER SYSTEM SET CONTROL_FILES=file_name; in order to point just one copy of control file.

Step 3. startup restrict

If instead you get ORA-1122, ORA-1110, and ORA-1207, go back to step 2 and try with another control file.

If you have already tried each and every one of the mirrored copies unsuccessfully, you must create a new control file for the database.

If you get ORA-1113 and ORA-1110 pointing to one of the datafiles, it means the copy of the control file you picked is good, but the referenced datafile must be recovered before the database can be opened.Then RECOVER DATBASE, apply the log it prompt and ALTER DATABASE OPEN.

Step 4.  Shutdown the database.
SQL>shutdown

Step 5. Copy this control file and locate to the different locations.

Step 6. Edit the init.ora file CONTROL_FILES parameter to include all location of the copy control files again.

Step 7. Startup  database.

User Managed Restore Procedure in Oracle

If someone has deleted datafile,there is user errors or disk is crushed then there is necessary to restore a datafile from backup. If you restore any datafile then just copy it to the location in the parameter specified in the control_files. If you restore any control file then copy in the destination which spfile or pfile points in control_files parameter.
In the following section you can know what you do if you choose user managed recovery:
 
1) If all copies of the control file have lost and you have backup of the control file then simply copy the backup of control file to the location as located in the control_files parameter in initialization parameter file pfile/spfile. After do this you have to open your database with resetlogs option. And if you don't have backup of the control file then you have to create new control file.

2) If you lose one or more datafiles then copy the datafiles to the location where it was. You can copy it to another location and point the control file to the new location by ALTER DATABASE RENAME FILE ' old' TO 'New '.

3) If you have backup of archived log then you can copy it to the location and perform recovery from there. But if the deleted archived log that is needed for media recovery and you have no backup then you must perform incomplete recovery (UNTIL SCN) and open the database with RESETLOGS open.

Recovering a Database in NOARCHIVELOG Mode

In NOARCHIVELOG mode the recovery is very simple. All you have to do is to restore the database files from your backup to the original location  and start the database. If one of your data file got corrupted. The time try to start the Oracle Instance, it will give you an error. In this case shutdown the database. Restore all the data files, redo log files and control file back to their original location from your last whole/complete cold backup.Then start the Oracle database again and then connecting as SYSDBA.There are some steps as following:

1) If the database is open then shutdown the database
Shutdown immediate

2) If possible, correct the media problem so that the backup database files can be
restored to their original locations.
3) Restore the most recent whole database backup. Restore all of the
datafiles and control files of the whole database backup, not just the damaged
files. The following example restores a whole database backup:
% cp /opt/luck1/BACKUP/tbs* /opt/luck # restores datafiles
% cp /opt/luck1/BACKUP/cf.f /opt/luck # restores control file
 
4) Because online redo logs are not backed up, you cannot restore them with the
datafiles and control files. In order to allow Oracle to reset the online redo logs,
you must have to do incomplete recovery:
RECOVER DATABASE UNTIL CANCEL
CANCEL
 
5) Open the database in RESETLOGS mode.
ALTER DATABASE OPEN RESETLOGS;

Difference Between Interface and Abstract Class

1) An Interface should contain only definitions but no implementation. where as an abstract class can contain abstract and non-abstract methods. 
2) Abstract class contains one or more abstract methods. where as Interface contains all abstract methods and final declarations
3) Abstract class contains the method defination of the some methods. but Interface contains only method declaration, no defination provided.
4) Interface must always have by default public and abstract methods.while abstract class can have non abstract methods
5) Abstract classes must be given by keyword abstract,where as in interface class with key word interface
6) By default what ever variables we declare in interface are public static final,where as in abstract class they can be default and instance variables also .
7) Abstract classes have constructors whereas interface do not have constructors.
8) Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
9) An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
10) In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.
11) Abstract classes are used only when there is a “is-a” type of relationship between the classes. Whereas Interfaces can be implemented by classes that are not related to one another.
12) You cannot extend more than one abstract class. While You can implement more than one interface. 

Is interface is Final in Java?


Is interface is Final in Java? 

Interfaces are 100% abstract and the only way to create an instance of an interface is to instantiate a class that implements it. Allowing interfaces to be final is completely pointless.
A final interface is one that cannot be extended by other interfaces .but it is senseless that we cannot implements or extends the inheritance.because to declare an interface means to implements its methods which we can't do if we mark interface as final.
So interface is never final in  java.
Lets take an example
 final interface Test{
}
Trying to declare an interface as final in Java results in a compilation error. This is a language design decision - Java interfaces are meant to be extendable.
final interface Test {}
$ javac Test.java
Test.java:1: illegal combination of modifiers: interface and final
final interface Test {}
 ^
1 error

What is marker Interface?when it is used?


What is marker Interface?when it is used?

Marker interface is that interface which has no members in it.Marker interface is used as a tag to inform a message to the java compiler so that it can add special behaviour to the class implementing it. It is also known as null interface.

Definition:
“An interface is called a marker interface when it is provided as a handle by java interpreter to mark a class so that it can provide special behaviour to it at runtime and they do not have any method declarations”. 

It is used in the following scenario:
Lets take the java.io.Serializable marker interface. It doesnot has any members defined it it. When a java class is to be serialized, you should intimate the java compiler in some way that there is a possibility of serializing this java class. In this scenario, marker interfaces are used. The java class which may be serialized has to implement the java.io.Serializable marker interface. In such way, we are intimating the java compiler. 
Java Marker Interface Examples
  • java.lang.Cloneable
  • java.io.Serializable
  • java.util.EventListener

Java Interfaces Advantages and Disadvantages

Advantages:
 
1) through interfaces we can implement multiple inheritance in java.

2) Interfaces function to break up the complex designs and clear the dependencies between objects.
3) Interfaces makes your application loosely coupled.
 

Disadvantages:
 
1) Java interfaces are slower and more limited than other ones.
2) Interface should be used multiple number of times else there is hardly any use of having them

Java Interfaces

An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. It is an interface through which multiple inheritance is implemented in Java. We can implements more than one interfaces in Java.
An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements.  
one thing to be notice:

Class implements interfaces and interfaces extends  interfaces.
Class implements more than one interface and interface extends more than one interface.
 
Declaring Interfaces:
The interface keyword is used to declare an interface. Here is a simple example to declare an interface:
interface Animal{
void eat();
void travel();
}
Interfaces have the following properties:
1.An interface is implicitly abstract. You do not need to use the abstract keyword when declaring an interface.
2.Each method in an interface is also implicitly abstract, so the abstract keyword is not needed
3.Methods in an interface are implicitly public.

Implementing Interfaces:
class Mammal implements Animal{
public void eat(){
 System.out.println("Mammal eats");
}
public void travel(){
System.out.println("Mammal travels");
}
public static void main(String args[]){
      Mammal m = new Mammal();
      m.eat();
      m.travel();
   }
}
Output:
Mammal eats
Mammal travels
The class which implements the interface is necessary to implements its all methods..
Another definition of interface is:
An interface is a list of methods that must be defined by any class which implements that interface.
 
Subinterfaces:
Interfaces can extend several other interfaces, using the same formula as described below. For example
public interface A extends B, C
{
//interface  body
}

Dropping Redo Log Group or Member

Dropping  Redo Log  Group:

To increase or decrease the size of online redo log groups you add or drop online redo log groups. To drop a redo log you must have the alter database system privilege.Use the alter database drop logfile group you can drop the redo log group.

Alter database drop logfile group 3;

But before drop a redo log group follow the following restrictions:
  • An insatnce requires at least two groups.
  • You cannot be dropped active or current group means a group can drop only if it is inactive.
  • Make sure a redo log group is archived.Whan an online redo log group is dropped the system files are not deleted.

     Dropping Redo Log Member:  

    If you want to drop any invalid online redo log member you can drop member by using alter database drop logfile member command:

    Alter Database drop logfile member'/opt/luck/redo03.log';

    When a redo log member is dropped from the database, the operating system file is not deleted from disk. The control files of the database are updated to drop the member from the database structure. But brfore drop a redo log member you have to follow the following restrictions:
    • If you want to drop a redo log member and that member is the last valid member of the group, you cannot drop that member.
    • If the group is current, you must force a log file switch before you can drop the member.
    • If the database is running in ARCHIVELOG mode and the log file group to which the member belongs is not archived, then the member cannot be dropped.
    • When an online redo log member is dropped, the operating system file is not deleted.

    Status Of Redo Log File

    To see the status of redo log file you have the following two dynamic views:
    1) V$LOG
    2) V$LOGFILE

    SQL>desc v$log
    This command will provide you information about GROUP#, THREAD#, SEQURNE#, BYTES, MEMBERS, STATUS, FIRST_TIME. You can see the status of redo log file by using STATUS column:

    SQL>select status from v$log;
     STATUS
    --------------
    UNUSED- Online redo log has never been written to. This is the state of a redo log that was just added, or just after a RESETLOGS, when it is not the current redo log.
    CURRENT- Current redo log. This implies that the redo log is active. The redo log could be open or closed.
    ACTIVE- Log is active but is not the current log. It is needed for crash recovery. It may be in use for block recovery. It may or may not be archived.
    CLEARING- Log is being re-created as an empty log after an ALTER DATABASE CLEAR LOGFILE statement. After the log is cleared, the status changes to UNUSED.
    CLEARING CURRENT-  Current log is being cleared of a closed thread. The log can stay in this status if there is some failure in the switch such as an I/O error writing the new log header.
    INACTIVE- Log is no longer needed for instance recovery. It may be in use for media recovery. It might or might not be archived.

    SQL>desc v$logfile
    V$LOGFILE will provide you information about GROUP#, STATUS, TYPE, MEMBER. You can see status of redo log file by using STATUS column:

    SQL> select status from v$logfile;
    STATUS
    --------------------
    INVALID- File is inaccessible 
    STALE- This redo log file member is new and has never been used.
    DELETED- File is no longer used
    Null- The redo log file is in use

    Difference between HibernateDaoSupport and HibernateTemplate

    The biggest difference I know of is that the HibernateTemplate created by HibernateDaoSupport is allowed to create Hibernate sessions (allow create) if no session is bound to the current thread. You can change the value through the allow Create property on HibernateTemplate though. HibernateTemplate (a Hibernate class) is a property of the HibernateDaoSupport class (a Spring class).

    Difference between APPLET and SERVELT

    Ques.IN JAVA WHAT IS DIFFERENCE BETWEEN APPLET AND SERVELT?
    Ans.1) Applet is client side application whereas Servlet is Server side application.
    2) An applet is a Java program that runs within a Web browser on the client machine whereas a servlet runs on the Web server.
    3) An applet can use the user interface classes like AWT or Swing while the servlet does not have a user interface.
    4) Servlet is a server, Applet is a browser.
    5) Applet is a downloadable small program which runs on the client side and executed by the client's java enabled browser or by the Apllet viewer. It doesn't need main() method to begin the execution,instead it begin's its lifecycle where the name of the class is passed to the Appletviewer.. The Applet's lifecycle have 4 methods.

    init()-Where it can initialise itself
    start()- It can start running
    stop()-stop running
    destroy()-Cleanup process happens

    Applets are treated as untrused and they have a limited permission to run in the client browser

    Servlet can be treated as Server-side applets.It runs in a servlet container which is deployed in the webserver. The lifecycle of the servlet have 3 methods.

    init()

    If an instance of the servlet does not exist, the Web container
    a. Loads the servlet class
    b. Creates the instance of the servlet class
    c. Initialise the servlet instance by calling the init() method

    service()-invokes this method by passing request and response object and a subsequent call to the same servlet is invoked as thread

    destroy()-If the servlet container decides to remove the servlet, it calls this method

    Difference between ArrayList and Vector

    Q.What are key difference between ArrayList vs Vector in Java?
    Ans.1) ArrayList is not thread safe where the Vector is i.e methods of vector are synchronized whereas ArrayList's methods are not.
    2) ArrayList is fast as compared to Vector.
    3) Vector and ArrayList both uses Array internally as data structure. They are dynamically resizable. Difference is in the way they are internally resized. By default, Vector doubles the size of its array when its size is increased. But, ArrayList increases by half of its size when its size is increased.
    4) ArrayList has no default size while vector has a default size of 10.
    5) In vector the data is retrieved using the elementAt() method while in ArrayList, it is done using the get() method. 

    Why multiple Inheritance is not allowed in Java?

    Q. Why multiple Inheritance is not allowed in Java?

    A. We always want to extend multiple classes so that we inherits the features of the multiple classes.
    For example:
    class C extends A,B
    { }
    but the above declaration is not valid in Java. In Java ,one class cannot extends from multiple classes. we can extend only from single class. But Java supports multilevel inheritance, means it will have multiple ancestors .For example

    class C extends B{}
    class B extends A{}

    Here,  C class inherits the features from the multiple ancestors (A and B).

    In C++ ,One can extend multiple classes simultaneously that is the declaration we have done for class A above is correct in case of C++.Capability of extending multiple classes is called as "Multiple Inheritance".Java creators thought a lot about to allow the multiple inheritance,but they were messed up after using the multiple inheritance. Like in this case ,if a class extended two classes and if both classes has methods in common then how the methods will be inherited and how we will come to know that which method is called of which class. That is why they excluded the multiple inheritance in Java. There is a famous problem which is faced during the multiple inheritance application called as "Deadly Diamond of Death".This is named so because the shape of class diagram which is formed after multiple inheritance implementation. The diamond is formed when classes B and C extend A ,and both B and C inherit methods from A. If class D extends both B and C,and both B and C have overridden the methods in class A,class D in theory has inherited the two different implementations of same method.


    There is an indirect way by which you can implement the multiple inheritance in Java and this is through extending a class and implementing an interface just like following:-

    class C extends B implements A{     //Here A is an interface
    // implements methods
    }

    In this way you can get methods from both class and interface and you can override them according to your use. Remember all methods of interface needs to be overridden in implementing class.

    this and super - Keywords

    The two keywords, this and super to help you explicitly name the field or method that you want. Using this and super you have full control on whether to call a method or field present in the same class or to call from the immediate superclass. This keyword is used as a reference to the current object which is an instance of the current class. The keyword super also references the current object, but as an instance of the current class’s super class.

    The this reference to the current object is useful in situations where a local variable hides, or shadows, a field with the same name. If a method needs to pass the current object to another method, it can do so using the this reference.Note that the this reference cannot be used in a static context, as static code is not executed in the context of any object.


    class Counter {

        int i = 0;
        Counter increment() {
            i++;
            return this;
        }
        void print() {
            System.out.println("i = " + i);
        }
    }

    public class CounterDemo extends Counter {

        public static void main(String[] args) {
            Counter x = new Counter();
            x.increment().increment().increment().print();
        }
    }

    Output

    Volume is : 1000.0
    width of MatchBox 1 is 10.0
    height of MatchBox 1 is 10.0
    depth of MatchBox 1 is 10.0
    weight of MatchBox 1 is 10.0

    Inheritance Advantages and Disadvantages

    Advantages:-
     
    One of the key benefits of inheritance is to minimize the amount of duplicate code in an application by sharing common  code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be  refactored to move the common code up to a mutual superclass. This also tends to result in a better organization of  code and smaller, simpler compilation units.

    Inheritance can also make application code more flexible to change because classes that inherit from a common  superclass can be used interchangeably. If the return type of a method is superclass

    Reusability -- facility to use public methods of base class without rewriting the same
    Extensibility -- extending the base class logic as per business logic of the derived class
    Data hiding -- base class can decide to keep some data private so that it cannot be altered by the derived class

    Overriding--With inheritance, we will be able to override the methods of the base class so that meaningful  implementation of the base class method can be designed in the derived class.
     
    Disadvantages:-
     
    1.One of the main disadvantages of inheritance in Java (the same in other object-oriented languages) is the increased  time/effort it takes the program to jump through all the levels of overloaded classes. If a given class has ten levels of  abstraction above it, then it will essentially take ten jumps to run through a function defined in each of those classes

    2.Main disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled.
    This means one cannot be used independent of each other.

    3. Also with time, during maintenance adding new features both base as well as derived classes are required to be  changed. If a method signature is changed then we will be affected in both cases (inheritance & composition)

    4. If a method is deleted in the "super class" or aggregate, then we will have to re-factor in case of using that  method.Here things can get a bit complicated in case of inheritance because our programs will still compile, but the  methods of the subclass will no longer be overriding superclass methods. These methods will become independent  methods in their own right.

    What is not possible using java class inheritance?

    What is not possible using java class Inheritance?
    1 Private members of the superclass are not inherited by the subclass and can only be indirectly accessed.
    2. Members that have default accessibility in the superclass are also not inherited by subclasses in other packages, as  these members are only accessible by their simple names in subclasses within the same package as the superclass.
    3. Since constructors and initializer blocks are not members of a class, they are not inherited by a subclass.
    4. A subclass can extend only one superclass

    Java Inheritance

    Java Inheritance defines an is-a relationship between a super class and its sub classes.This means that an object of a subclass can be used wherever an object of the superclass can be used. Class Inheritance in java mechanism is used to build new classes from existing classes. The inheritance relationship is transitive: if class x extends class y, then a class z, which extends class x, will also inherit from class y.
    For example a car class can inherit some properties from a general vehicle class. Here we find that the base class is the vehicle class and the subclass is the more specific car class. A subclass must use the extends clause to derive from a super class which must be written in the header of the subclass definition. The subclass inherits members of the super class and hence promotes code reuse. The subclass itself can add its own new behavior and properties. Object class is always at the top of any Class inheritance hierarchy.


    class Box {

        double width;
        double height;
        double depth;
        Box() {
        }
        Box(double w, double h, double d) {
            width = w;
            height = h;
            depth = d;
        }
        void getVolume() {
            System.out.println("Volume is : " + width * height * depth);
        }
    }

    public class MatchBox extends Box {

        double weight;
        MatchBox() {
        }
        MatchBox(double w, double h, double d, double m) {
            super(w, h, d);
            weight = m;
        }
        public static void main(String args[]) {
            MatchBox mb1 = new MatchBox(10, 10, 10, 10);
            mb1.getVolume();
            System.out.println("width of MatchBox 1 is " + mb1.width);
            System.out.println("height of MatchBox 1 is " + mb1.height);
            System.out.println("depth of MatchBox 1 is " + mb1.depth);
            System.out.println("weight of MatchBox 1 is " + mb1.weight);
        }
    }


    Output

    Volume is : 1000.0
    width of MatchBox 1 is 10.0
    height of MatchBox 1 is 10.0
    depth of MatchBox 1 is 10.0
    weight of MatchBox 1 is 10.0

    Multiplexing Redo log File

    Multiplex redo log by adding group:

    Redo log files are used to record changes made to the database. Redo log files are important for the recovery purpose.So thats why in some cases you might need to create additional log file groups. To create a new group of online redo log files use the following SQL command:
    Alter database add logfile group 3 ('/opt/luck/redo03_00.log',
                                                      '/opt/luck/redo03_01.log') size 10m;

    Multiplexing redo log by adding member:

    You can add new members to existing redo log file groups using the following ALTER DATABASE ADD LOGFILE MEMBER command:
    Alter database add member '/opt/luck/redo02.log' to group 1,
                                             '/opt/luck/redo02.log' to group 2,
                                             '/opt/luck/redo03.log' to group 3;

    Use the fully specified name of the log file members; otherwise the files are created in a default directory of the database server. If the file already exists, it must have the same size, and you must specify the REUSE option.

    How Redo Logs Work

    The online redo log of a database consists of two or more online redo log files. Oracle needs a minimum of two files to guarantee that one is always available for writing while the other is being archived.The Oracle server sequentially records all changes made to the database in the redo log buffer. The redo entries are written from the redo log buffer to one of the online redo log groups called the current online redo log group by the LGWR process. LGWR writes under the following situations:
    • When a transaction commits
    • When the redo log buffer becomes one-third full
    • When there is more than a megabyte of changed records in the redo log buffer
    • Before the DBWn writes modified blocks in the database buffer cache to the data files
      LGWR writes to online redo log files in a circular fashion.Each redo log file group is identified by a log sequence number that is overwritten when log is reused.LGWR writes on the online redo log files continueslly. When the current online redo log grooup is filled log writer starts writing to the next group. When the last online redo log file is filled, LGWR returns to the first online redo log group and starts writing again.

      Online Redo Log File

      Each transaction is recorded in the redo logs.Redo logs stroe all changes made to the database. In the oracle database every instance has online redo log to protect the database in any case of an instance failure.Every oracle database instance has its own online redo log group. 
      Online redo log files are filled with redo records are also called redo entry. If you change any value in a table then you generate a redo record that describe changes to the data segment block for the table and the transaction table of the rollback segments.Redo entries record all data that you can use to reconstruct all changes made to the database.Online redo log also protects rollback data, when you recover the database using redo data.



       In the above fig you can see a set of identical copies of online redo log files. DBA can set up the oracle database to maintain copies of online redo log files to avoid losing database information. The Log Writer LGWR background process writes the same information to all online redo log files in a group.So, Oracle server needs minimum two online rredo log file groups for the normal operation of database.In each group each online redo log file is known as member and each member in a group has Log Sequence Number.The current log sequence number is stored in the control file and in the header of all data files.
      Using the alert log,v$logfile, v$loghist, v$recovery_log, you can monitor redo logs.

      How To Create New Control File

      As you know control file records the information about the physical structure of the database.It is very crucial file it is veru small binary file, So thats why we create multiplexing of control file and we back up control file time to time.But sometime when all control file have been damaged then we need to create new control file as follow:
      CREATE CONTROLFILE
         SET DATABASE luck
         LOGFILE GROUP 1 ('/opt/luck/redo01.log',
                                        '/opt/luck/redo02.log'),
                 GROUP 2 ('/opt/luck/gro/redo01.log',
                                 '/u01/luck/gro/redo02.log'),         
         NORESETLOGS
         DATAFILE '/opt/luck/system.dbf' SIZE 3M,
                         '/opt/luck/sysaux.dbs' SIZE 5M,
                         '/opt/luck/user.dbs' SIZE 5M,
                         '/opt/luck/temp.dbs' SIZE 5M

         MAXLOGFILES 30
         MAXLOGMEMBERS 2
         MAXLOGHISTORY 200
         MAXDATAFILES 150
         MAXINSTANCES 6
         ARCHIVELOG;

      Here are some steps, how to create new control file or open your database when your all control files have been damaged :

      1) Make a list of all datafiles and online redo log files of the database. Execute the following statements which will provide you information about your datafiles and online redo log files:
      Select member from v$logfile;
      select name from v$datafile;
      Selecr value from v$parameter where name='CONTROL_FILES';

      2) Shutdown the database.

      3) Back up all datafiles and online redo log files of the databsae.

      4) Start up a new instance at nomount stage

      5) Create a new control file as we done above in this post.
      In above as you know we used NORESETLOGS in control file creation. When creating a new control file select RESETLOGS option if you lost any online redo log group and with this option you will need to recover of the redo logs. Otherwise, select the NORESETLOGS option.

      6) Store a backup of the new control file.

      7) Edit the control_files intialization parameter for the database to indicate control file now part of your database as created in step5

      8) Recover the database if you are using RESETLOGS option.

      9) Open the database
      Alter database open;

      Share

      Twitter Delicious Facebook Digg Stumbleupon Favorites More