Wednesday, July 28, 2010

What is HTML color code notation?

It is the format to specify colors in HTML documents, and is hexadecimal notation.
Six characters from hexadecimal digits (0-F) are used with each pair from left to right representing Red, Green and Blue (RGB) color values.
Example:
For color "gray", the code is: #808080

Friday, April 23, 2010

Method Overloading In JAVA

In JAVA, it is legal to define two or more methods with the same name within the same class provided their parameters declarations are different. The methods are said to be overloaded, and the process is called method overloading.

By now, you must be thinking about “polymorphism”, isn’t it? That is one interface, but many methods.
Based on the parameter-type and number of parameters, the JAVA knows which method to invoke during a function call.
Here’s a sample program to demo method overloading:
//MethodOverloadingDemo
public class MethodOverloadDemo{
private void evaluate(){
//method with zero parameters
System.out.println(“evaluate: No parameters);
}
//overload evaluate with one integer parameter and return it.
private int evaluate(int oneParam){
//method with one  parameters
System.out.println(“evaluate: one int param: “ + oneParam);
return oneParam;
}
//Overload evaluate to add two integers and return their sum
private int evaluate(int param1, int param2){
//method with two parameters
System.out.println(“evaluate: (param1” + param1+ “ + param2” +param2+ “)=” + param1+ param2);
return (param1 + param2);
}
//Overload evaluate to multiply two doubles and return their product
private double evaluate(double param1, double param2){
//method with two parameters
System.out.println(“evaluate:  (param1” + param1+ “ * param2” +param2+ “)=” + param1* param2);
return (param1 * param2);
}
}
NOTE: As seen in above example, the return type of overloaded methods can also be different.
Let’s see above call in action.
public class TestOverloadedDemo{
                public static void main (String args[]){
                MethodOverloadDemo mod = new MethodOverloadDemo();
               
//test overloaded methods
                mod.evaluate();
                mod.evaluate(10);
                int intResult = mod(5 + 15);
                System.out.println(“Sum of two int params: ” + intResult);
                double doubleResult = mod(11.24 * 34.23);
                System.out.println(“Product of two double params: ” + doubleResult);
}
}

//output
evaluate: No parameters
evaluate: one int param: 10
evaluate: (5 + 15) = 20
Sum of two int params: 20
evaluate:  (11.24 * 34.23) = 384.7452
Product of two double params: 384.7452

Hope this simple explanation helps. Good Luck!


Wednesday, April 21, 2010

Ant task to check for OS before executing a batch (.bat) or shell (.sh) script

Suppose we have two scripts - one (.bat file) executes on windows os family, and other (.sh) thats runs on all non-windows platforms like unix, linux, etc. And, we need an ant task in build file, to call the appropriate scripts depending on the operating system.

Lets call this ant task "run.script", and this depends on whether OS family is windows or not windows.

<target depends="ifWindows, ifNotWindows" name="run.script"/>


This is no brainer - we are just saying that "run.script" task depends on tasks called "ifWindows" and "ifNotWindows". We then define these two tasks as below: 
   
<target name="ifWindows" if="is-windows">
   <antcall target="run.script.windows"/>
</target>


<target name="<b">"ifNotWindows" if="is-unix">
   <antcall target="run.script.unix"/>
</target>


As we see, ifWindows and ifNotWindows task are based on a condition, which if true calls the specific target.

If "is-windows" property, defind as -

<condition property=""is-windows">
    <os family="windows"/>
</condition>


returns true, than ant target "run.script.windows" is executed.

Else, ifNotWindows tested using "is-unix" property:

<condition property="is-unix">
    <not>
       <os family="windows"/>
   </not>
</condition>


If this condition returns true, then "run.script.unix" will be called.

Following is how you can define an ant task to execute a batch script on windows:

To execute a script , exec command is used wrapped inside you target definition:

<target name="run.script.windows">
    <exec dir="." executable="cmd" os="Windows Vista">
      <arg line="/c myScript.bat -p myScriptArg1 myScriptArg2"/>
   </exec>
</target>


Following is to run a shell script on unix using Ant task:

<target name=""run.script.unix">
    <exec dir="." executable="/bin/sh">
        <arg line="-c "myScript.bat -p myScriptArg1 myScriptArg2"">
</exec>
</target>



Note:
1. Note: The double-quotes are nested inside the single-quotes.
2. Using "arg line" we are passing the command and command-line parameters to be executed by the shell in one line itself. Alternatively, you may consider using "arg value" instead.

To sum up:
On systems running a Unix-type shell (for example, Cygwin on Windows) execute the (command) shell :
1. sh for shell scripts. Use -c switch to pass the shell script (.sh), any arguments to the script (as needed).
2. cmd for batch files. Use /c switch to pass the batch script (.bat), any arguments to the script (as needed).

Friday, December 18, 2009

Error 1606 during JDK 6 Update 17 installation on Vista !

Hitting error # 1606 on Vista???

P.S: I have my original post on other blog at wordpress.com.

Problem:

While installing JDK 6, update 17 ( installation package: jdk-6u17-windows-i586.exe), “error 1606: Could not find network location … %APPDATA%” is thrown. How do I resolve this issue?

Solution:

I encountered error 1606 (Could not find network location … %APPDATA%) while installing JDK 6 update 17 on Vista online. Research should that this may be caused due to incorrect registry key settings. Refer Microsoft’s Support to validate your settings.

Despite having correct registry key settings, I was running into this error. After hours of investigation, I could finally do successful installation .

Thanks to Grif Thomas’s reply to a posting in CNet forum who suggested deleting“Recent” registry key and restarting the machine.

Here’s what you need: (Note: Administrator privileges may be required for the following)

1. Run regedit.exe (Go to : Start -> Run; enter: regedit.exe) The registry settings will open in a pop up window.

2. Browse to HKEY_CURRENT_USER –> Software

3. Now click on : Microsoft –> Windows

4. Then select: Current Version –> Explorer –> User Shell Folders

5. Right Click on “Recent” key and select “delete”.

6. Restart/reboot the machine.

Remember only on restarting the machine will new registry changes become effective. So first reboot the system and then:

7. run jdk-6u17-windows-i586.exe

Installation should proceed smoothly.

Was this information useful?