MY mENU


Sunday 17 February 2013

Custom Exception Development:


Custom Exception Development:
The new exception classes those are defined by developers are called user Defined Exception or custom exception.

These classes must be subclass of  either Throwable or any one of its subclass. It must be thrown based on condition failure.

According to the business requirements developers must write their own exception.
Its two steps process:
  1. Define public class deriving from java.lang.Exception.
  2. Define public no-arg and String parameter constructors with super() call.

For Example:
First Step:
NegativeNumberException.java

public class NegativeNumberException extends Exception
{
                public NegativeNumberException(){
                                super();
                }
                public NegativeNumberException(String msg){
                                super(msg);
                }

}

Using the above custome Exception in Our logic

Compute.java

public class Compute
{
                public int add(int n)throws NegativeNumberException
                {
                                if(n>0){
                                                return (n+10);
                                }
                                else
                                {
                                            throw new NegativeNumberException("Do Not Pass Number <=0");
                                }
                }
}

Example.java

class Example
{
                public static void main(String[] args)
                {
                                try{
                                                int n=Integer.parseInt(args[0]);
                                                Compute c=new Compute();
                                                int res=c.add(n);
                                                System.out.println("Result::"+res);
                                }
                                catch(ArrayIndexOutOfBoundsException aiobe){
                                System.out.println("Pleas pass ONE positive Integer number");
                                }
                                catch(NumberFormatException nfe){
                                System.out.println("Pleas pass only integer number");
                                }
                                catch(NegativeNumberException nne){
                                System.out.println(nne.getMessage());
                                }
                }
}

Saturday 16 February 2013

Marker Interface

Marker Interface: an interface that is used to check/mark/tag the given object is of a specific type to perform a special operations on that object, is called marker interface. Marker interface will not have methods, they are empty interfaces.

It is used to check whether we can perform some special operations on the passed object.

For example:
If class is deriving from java.io.Serializable, then that class object can be serializable else it cannot.

If class is deriving from java.lang.Clonable, then that class object can be cloned, else it cannot.

In side those particular methods, that method developer will check that the passed object is of type the given interface or not by using instanceof operator.

Write an empty interface and use in the method to check the passed object is of type the interface or not by using “instanceof” operator.

Is empty interface a marker interface?

Depends, if it is using in instanceof operator condition it called marker else it is call empty interface.

Predefined marker interface:

 1. Java.lang.Clonable

2. Java.io.Serializable

3. Java.util.RandomAccess

4. Java.rmi.Remote

5. Javax.servlet.SingleThreadModel

6. Java.util.EventListener

Friday 15 February 2013

Delete administrator Password

How to "Delete administrator Password" without any software

Method 1:
Boot up with DOS and delete the sam.exe and sam.log files from Windows\system32\config in your hard drive. Now when you boot up in NT the password on your built-in administrator account which will be blank (i.e No password). This solution works only if your hard drive is FAT kind.

Method 2:
Step 1. Put your hard disk of your computer in any other pc .
Step 2. Boot that computer and use your hard disk as a secondaryhard disk (D'nt boot as primary hard disk ).
Step 3. Then open that drive in which the victim’s window(or your window) is installed.
Step 4. Go to location windows->system ­32->config
Step 5. And delete SAM.exe and SAM.log
Step 6. Now remove hard disk andput in your computer.
Step 7. And boot your computer:-)

Wecome Note

It’s a simple trick to amaze your friends.When you Log On infront of them.
Yeah a trick to make your Computer Welcome you on StartUp.
Follow this tricks /b>
Open Notepad
Paste the bellow code.


Dim speaks, speech
speaks="Welcome Back, Netricks"
Set speech=CreateObject("sapi.spvoice")
speech.Speak speaks

step2:now,Replace Netricks withyour Name
Click Save As and rename as Welcome.vbs
Copy File Welcome.vbs and paste it in bellow address
Windows-7
C:Users/Netricks/AppData/Roaming/MicrosoftWindows/Start Menu/ProgramsStartup
Replace Netricks with your username and C: with your RootDrive
Windows-Xp
documents and SettingsAll UsersStart MenuProgramsStartup
Done Log Off and Log In Amazed?
Now Your Pc welcomes you.

Friday 8 February 2013

In Java, how does System.out.println() work?

In Java, how does System.out.println() work?


This question is an excellent example of how just some very basic knowledge of Java can lead you to the correct answer. Most interviewers would not expect you to know the answer to do this right away – but would like to see how you think and arrive at an answer.
Marcus Aurelius (a Roman emperor) once said: "Of each particular thing ask: what is it in itself? What is its nature?". This problem is an excellent example of how that sort of thinking can help one arrive at an answer with only some basic Java knowledge.
With that in mind, let’s break this down, starting with the dot operator. In Java, the dot operator can only be used to call methods and variables so we know that ‘out’ must be either a method or a variable. Now, how do we categorize ‘out’? Well, ‘out’ could not possibly be a method because of the fact that there are no parentheses – the ‘( )’ – after ‘out’, which means that out is clearly not a method that is being invoked. And, ‘out’ does not accept any arguments because only methods accept arguments – you will never see something like “System.out(2,3).println”. This means ‘out’ must be a variable.
We now know that ‘out’ is a variable, so we must now ask ourselves what kind of variable is it? There are two possibilities – it could be a static or an instance variable. Because ‘out’ is being called with the ‘System’ class name itself, and not an instance of a class (an object), then we know that ‘out’ must be a static variable, since only static variables can be called with just the class name itself. So now we know that ‘out’ is a static member variable belonging to the System class.

Breaking down the “out” in System.out.println

Noticing the fact that ‘println()’ is clearly a method, we can further classify ‘out’. We have already reasoned that ‘out’ is a static variable belonging to the class System. But now we can see that ‘out’ must be an instance of a class, because it is invoking the method ‘println()’.
The thought process that one should use to arrive at an answer is purposely illustrated above. Without knowing the exact answer beforehand, you can arrive at an approximate one by applying some basic knowledge of Java. Most interviewers wouldn’t expect you to know how System.out.println() works off the top of your head, but would rather see you use your basic Java knowledge to arrive at an answer that’s close to exact.

When and where is the “out” instantiated in System.out.println?

When the JVM is initialized, the method initializeSystemClass() is called that does exactly what it’s name says – it initializes the System class and sets the out variable. The initializeSystemClass() method actually calls another method to set the out variable – this method is called setOut().

The final answer to how system.out.println() works

The more exact answer to the original question is this: inside the System class is the declaration of ‘out’ that looks like: ‘public static final PrintStream out’, and inside the Prinstream class is a declaration of ‘println()’ that has a method signature that looks like: ‘public void println()’.
Here is what the different pieces of System.out.println() actually look like:
//the System class belongs to java.lang package
class System {
  public static final PrintStream out;
  //...
}

//the Prinstream class belongs to java.io package
class PrintStream{
public void println();
//...
}

Thursday 7 February 2013

secure Google Chrome with password.

We can protect our Google Chrome with Password. We can secure Saved Password, 

Important Bookmarks, etc... with this "Simple Password Startup" Extension. So let's see how to

secure Google Chrome with password.
|:|:|:|:|: Secure your Google Chrome with Password:|:|:|:|
Install the "Simple Password Startup" Extension in your Chrome
Click here to Install

Then go to "Tools" --> "Extension" --> "Simple Password Startup" --> "Option"

After that Enter a Password and Save it.

Now your Google Chrome is secured with Password.

Secure your Google Chrome with Password
If you want to open your Google Chrome, every time you have to type the password in home 
page. If you type a wrong password, Chrome will be closed. Without knowing the password we
can see only the "Home page" in chrome.

Secure your Google Chrome with Password

This is a very easiest way to protect your "Saved Password" and "Bookmarks" from unknown
persons.

Note: Don't forget your Startup password, if you forget the password, you can't recover it.