04 July 2013

Right to Equality..


Consider following code:



First two lines print the output as:

a==b : true
c==d : false



Since primitives are checked for value rather than the address, first check returns true as expected. Similarly, since two different objects are compared in line 2, the outcome is expected.

But what about remaining lines ?
The outcome is:
true  // line 3
false // line 4 

false // line 5

Why ?
The reason is that Java internally caches the int values between -128 and +127 as a preloaded array.
So if the argument of valueOf function is between -128 and +127 (both inclusive), then an int value from cache array is auto-boxed and returned.  Else a new Integer object is created and is returned. This is internally managed by a nested class IntegerCache's cache array. 

User can specify the cache size by setting property java.lang.Integer.IntegerCache.high during the JVM startup. However, the value set must be more than 127 since the code in Integer class takes the max value between 127 and the value of this property.

For example, if above code is run by adding this property:

java -Djava.lang.Integer.IntegerCache.high=400 IntegerTest

Output is true for lines 3 and 4 and is false for line 5.


18 May 2010

Sorting data using xsl:sort

In SOA 11g, there is a new XSL-Construct for sorting the input nodes. This is a basic XSLT construct (element) which was missing earlier.
As the w3 standard defines, this construct cannot be used independently, but can be used along with xsl:for-each(or xsl:apply-templates)
It is used to sort the input data based upon some id or text(called as sort-key).
This can be very useful functionality in scenarios where one needs to process some data in a specific sequence.

To use this construct inside a transform activity, add a for-each construct first. Do the required mapping.
Then right-click the for-each and select sort




A dialogue box will open. Add the details like sort-order, data-type for sorting. Click OK.




The construct still shows a big red balloon. To complete the things, just map the appropriate source element to this construct.
Note that one sort construct adds only one parameter. To have sort on basis of more than one parameter, additional sort constructs need to be added.
The source code will show entry of the sort similar to :

<xsl:sort select="tns:age" order="descending" data-type="number"/>

Test and verify.  In the example below, I have added two sort statements first for age (descending) and then for id (ascending) :





Note that xsl:sort supports 5 attributes which are :
1. select : Specifies the string which can be used as sort-key
2. lang : Specifies the language for the sort key
3. data-key : Specifies the data type to be used while sorting. Possible values are text, number or a qualified name (either a prefixed name or unprefixed name)
4. order : Specifies the order of sorting. Possible values are ascending, descending
5. case-order : Used in case of data-key="text". Possible values are lower-first or upper-first

Changing password for a user

To change password for a user in Oracle Weblogic server :
1. Login to Weblogic administration console (http://<hostname>:<port>/console)
2. Navigate to Security Realms. Select the default realm. This will be myRealm unless there are more than one realms created.
3. In the Settings page, go to Users and Groups > Users
4. Select the user for which you want to change the password.
5. Go to passwords tab. Type new password, confirm it and save.