Tuesday, April 19, 2011

AQT : Processing error at sql_setvars


After installing AQT in my PC I was not able to run it. After login to DB2 server whenever I used to press SQL to open an SQL window, I used to get below mentioned error. 



Error :
  
Processing error at sql_setvars
Component 'TABCTL32.OCX' or one of its dependencies not correctly registered: a file is missing or invalid

What I did is I downloaded the file TABCTL32.OCX from the below mentioned URL



And added the file TABCTL32.OCX to the path C:\WINXP\system32\TABCTL32.OCX

and run the bat file C:\Program Files\Advanced Query Tool\ocx_register_v8.bat

and after restarting AQT, it was working fine. I wanted to share this issue with you If anyone else faced this kind of similar issue, hope it may helped you.

Friday, April 15, 2011

Java : Methods with Variable Argument Lists (var-args)

Methods with Variable Argument Lists (var-args)

As of 5.0, Java allows you to create methods that can take a variable number of arguments. Depending on where you look, you might hear this capability referred to as "variable-length argument lists," "variable arguments," "var-args," "varargs, "variable arity parameter". They're all the same thing.

As a bit of background,to use the terms "argument" and "parameter".

arguments The things you specify between the parentheses when you'reinvoking a method:

doStuff("a", 2);   // invoking doStuff, so a & 2 are arguments

parameters The things in the method's signature that indicate what the method must receive when it's invoked:

void doStuff(String s, int a) { } // we're expecting two
                                            // parameters: String and int

The declaration rules for var-args:

Var-arg type When you declare a var-arg parameter, you must specify the type of the argument(s) this parameter of your method can receive. (This can be a primitive type or an object type.)

Basic syntax To declare a method using a var-arg parameter, you follow the type with an ellipsis (...), a space, and then the name of the array that will hold the parameters received.

Other parameters It's legal to have other parameters in a method that uses a var-arg.

Var-args limits The var-arg must be the last parameter in the method's signature, and you can have only one var-arg in a method.

Let's look at some legal and illegal var-arg declarations:

Legal:
void doStuff(int... x) { }  // expects from 0 to many ints
                                    // as parameters
void doStuff2(char c, int... x) { }  // expects first a char,
                                                 // then 0 to many ints
void doStuff3(Animal... animal) { }  // 0 to many Animals

Illegal:
void doStuff4(int x...) { } // bad syntax
void doStuff5(int... x, char... y) { } // too many var-args
void doStuff6(String... s, byte b) { } // var-arg must be last

Conclusion 

As of Java 5, methods can declare a parameter that accepts from zero to many arguments, a so-called var-arg method.

A var-arg parameter is declared with the syntax type... name; 

for instance: 
doStuff(int... x) { }

A var-arg method can have only one var-arg parameter.

In methods with normal parameters and a var-arg, the var-arg must come last. 



Thursday, April 14, 2011

My Eclipse 9 : Failed to create Java Virtual Machine

When I installed latest version of My Eclipse ie My Eclipse 9 initially it worked fine for few days latter suddenly it started giving me error Failed to create Java Virtual Machine.



Here is the solution

It gives Failed to create Java Virtual Machine error because while starting eclipse it created JVM of its own. It require enough free cache memory to do so hence if there is not enough memory it give the Failed to create Java Virtual Machine error.

Go to installation directory

Eg :  C:\Program Files\MyEclipse\MyEclipse 9

You will find a file myeclipse.ini

Eg : C:\Program Files\MyEclipse\MyEclipse 9\myeclipse.ini

You need to provide the existing JVM which is already present and need to require recreating. Remove the VM from file myeclipse.ini and add your custom existing JVM

-vm
C:/Program Files/Java/jdk1.6.0_21/jre/bin/javaw.exe

And now when you restart eclipse it will work and wont give Failed to create Java Virtual Machine error.

Wednesday, April 13, 2011

Javascript Print Preview

It was required to print a page with different domain. Where my javascript failed to communicate cross domain using frames. I got below mentioned print preview code when i searched on net. It solved my prblem however it only worked for IE. It didnt worked for Mozilla Firefox.

Below mentioned code works only for IE.

<html>
<head>
<title> print preview </title>
<script type="text/javascript">
function showPrintPreview()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1;// 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);

WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = '';
}

</script>
</head>

<body>
<h1>print preview</h1>
<h2>print preview</h2>
<h3>print preview</h3>
<a href="#" onclick="showPrintPreview()">print preview</a>
</body>
</html>

I then searched how to get the same functionality in mozilla. I tried the below mentioned codes but it didn't worked any

nsiwebbrowserprint::print();
nsiwebbrowserprint::getglobalprintsettings();
nsiwebbrowserprint::printpreview();
nsiwebbrowserprint::printpreviewnavigate();
nsiwebbrowserprint::exitprintpreview();

Hope any one gets this solution.


Thursday, February 17, 2011

Java : Basics of Inner Class

Inner Classes
q A "regular" inner class is declared inside the curly braces of another class, but
outside any method or other code block.
q An inner class is a full-fledged member of the enclosing (outer) class, so it
can be marked with an access modifier as well as the abstract or final
modifiers. (Never both abstract and final together— remember that
abstract must be subclassed, whereas final cannot be subclassed).
q An inner class instance shares a special relationship with an instance of the
enclosing class. This relationship gives the inner class access to all of the
outer class's members, including those marked private.
q To instantiate an inner class, you must have a reference to an instance of the
outer class.
q From code within the enclosing class, you can instantiate the inner class
using only the name of the inner class, as follows:
MyInner mi = new MyInner();
q From code outside the enclosing class's instance methods, you can
instantiate the inner class only by using both the inner and outer class names,
and a reference to the outer class as follows:
MyOuter mo = new MyOuter();
MyOuter.MyInner inner = mo.new MyInner();
q From code within the inner class, the keyword this holds a reference to
the inner class instance. To reference the outer this (in other words, the
instance of the outer class that this inner instance is tied to) precede the
keyword this with the outer class name as follows: MyOuter.this;

Method-Local Inner Classes
q A method-local inner class is defined within a method of the enclosing class.
q For the inner class to be used, you must instantiate it, and that instantiation
must happen within the same method, but after the class definition code.
q A method-local inner class cannot use variables declared within the method
(including parameters) unless those variables are marked final.
q The only modifiers you can apply to a method-local inner class are abstract
and final. (Never both at the same time, though.)

Anonymous Inner Classes
q Anonymous inner classes have no name, and their type must be either a
subclass of the named type or an implementer of the named interface.
q An anonymous inner class is always created as part of a statement; don't
forget to close the statement after the class definition with a curly brace. This
is a rare case in Java, a curly brace followed by a semicolon.
q Because of polymorphism, the only methods you can call on an anonymous
inner class reference are those defined in the reference variable class (or
interface), even though the anonymous class is really a subclass or implementer
of the reference variable type.
q An anonymous inner class can extend one subclass or implement one
interface. Unlike non-anonymous classes (inner or otherwise), an anonymous
inner class cannot do both. In other words, it cannot both extend a class and
implement an interface, nor can it implement more than one interface.
q An argument-local inner class is declared, defined, and automatically
instantiated as part of a method invocation. The key to remember is that the
class is being defined within a method argument, so the syntax will end the
class definition with a curly brace, followed by a closing parenthesis to end
the method call, followed by a semicolon to end the statement: });

Static Nested Classes
q Static nested classes are inner classes marked with the static modifier.
q A static nested class is not an inner class, it's a top-level nested class.
q Because the nested class is static, it does not share any special relationship
with an instance of the outer class. In fact, you don't need an instance of the
outer class to instantiate a static nested class.
q Instantiating a static nested class requires using both the outer and nested
class names as follows:
BigOuter.Nested n = new BigOuter.Nested();
q A static nested class cannot access non-static members of the outer class,
since it does not have an implicit reference to any outer instance (in other
words, the nested class instance does not get an outer this reference).