Archive for March, 2006

Problem with applet in IE7

March 29, 2006

Had problems with loading a applet(that tries to connect using socket) in IE7 using JRE1.5. It used to work in IE6. Was getting the socketPermission error although the java.policy file in the user home had socketPermission for accept, connect, resolve. Then I added the same socketPermission entry in the java.policy file under the security folder of the JRE installed directory. It then worked. Thus, IE7 doesn’t check the java.policy file present in the user home. Instead it checks the same present in the JRe installed directory. Bug or enhancement in IE7?

In case of load balanced applications like tarantella, we can’t manually add socketpermission for individual servers. Hence, added the following line in

permission java.net.SocketPermission “*”, “accept, connect, listen, resolve”; in the grant{} block of java.policy present in the JRE installed security directory(C:\Program Files\Java\jre1.5.0_08\lib\security). This is more like granting security permission for all applets  downloaded from any server to accept, connect and resolve .  Don’t know how to restrict the grant options to a set of machines like *.us.oracle.com using the codebase option since the codebase option require a complete host machine address. Since in my case it will be a dynamic list of servers and I don’t want to add each and every dynamic server to my security file, I prefer granting this permission to all servers.

Java Tips

March 28, 2006

Cases when a closing curly brace is followed by semi-colon

  1. anonymous inner class
  2. array initialization using {}

Difference between Stored Procedure and Function

March 23, 2006

Stored Procedure :supports deffered name resoultion Example while writing a stored procedure that uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during creation but runtime throws error
Function wont support deffered name resolution. Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values(SQL Server).Stored Procedure is pre compiled exuction plan where as functions are not.

Bug in asList method of class Arrays – Java Tiger: Reply

March 22, 2006

Not a bug, but I agree it’s very surprising. Look at the declaration of asList():

public static <T> List<T> asList(T… a)

“T”, like all generic type parameters, has to be a reference type. If you pass an array of reference types, then T becomes the type of that reference, and the individual array elements become the arguments to the function.

But if you pass a primitive array to this function, “T” is assigned the primitive array type itself — int[], in your example — and the function sees a single argument of that type. It has to be so, because T can’t be assigned to type “int”. That “1″ is therefore indicating that the function saw the array as a single unit.

Making trace files available

March 17, 2006

There is an undocumented parameter _trace_files_public that if set to true changes the file permissions in the user_dump_dest directory when trace files are created to allow everyone to read them. This parameter can be checked with the following SQL. You can set this parameter by adding the following line to the init.ora file:
# allow trace files to be created with public permissions
_trace_files_public=true
SQL to check the value of this parameter:
SQL> select x.ksppinm name,y.ksppstvl value
from sys.x$ksppi x,sys.x$ksppcv y
where x.inst_id=userenv(‘Instance’)
and y.inst_id=userenv(‘Instance’)
and x.indx=y.indx
and x.ksppinm=’_trace_files_public’;

Who eats my Temp Space

March 15, 2006

Many a times we get the error : “TEMP SEGMENT MAXIMUM EXTENT EXCEEDED”. The following script will provide a list of users and which processes occupy space in the TEMP tablespace.

SET pagesize 10000;
    SET linesize 133;
    column tablespace format a15 heading 'Tablespace Name';
    column segfile# format 9,999 heading 'File|ID';
    column spid format 9,999 heading 'Unix|ID';
    column segblk# format 999,999,999 heading 'Block|ID';
    column size_mb format 999,999,990.00 heading "Mbytes|Used";
    column username format a15;
    column program format a15;
SELECT
    b.tablespace,
    b.segfile#,
    b.segblk#,
    round(((b.blocks*p.value)/1024/1024),2 ) size_mb ,
    a.sid,
    a.serial#,
    a.username,
    a.osuser,
    a.program,
    a.status
FROM v$session a ,
    v$sort_usage b ,
    v$process c ,
    v$parameter p
WHERE p.name='db_block_size'
    AND a.saddr = b.session_addr
    AND a.paddr=c.addr
ORDER BY b.tablespace,
    b.segfile#,
    b.segblk#,
    b.blocks
/

Confirmed my understanding

March 9, 2006

In the earlier blog, the character not being displayed properly by the browser is the browser issue and the code to deal with supplementary character is correct. The link http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=10177 shows the character that will be displayed in browser(which is the one present in xml file when opened by browser). So, to work with supplementary characters, create new String by passing character[] containing the low and high surrogate pairs or the byte[] specifying the encoding. The byte[] can for any code point can be obtained using the link :
Byte for codepoint

Some code to illustrate the unicode support by Character class

March 9, 2006

public class UnicodeTest{
public static void main(String… args) throws IOException
{
System.out.println(“is valid codepoint : ” + Character.isValidCodePoint(0×10FFFF));
System.out.println(“is valid codepoint : ” + Character.isValidCodePoint(0×20FFFF));
int cp = 0×10177;
System.out.println(“is valid codepoint : ” + Character.isValidCodePoint(cp));
char[] ch = new char[2];
ch = Character.toChars(cp);
int low = ch[0];
int high = ch[1];
System.out.println(“Low Surrogate Pair : ” + low + ” Hexadecimal : ” + Integer.toHexString(low) + ” Binary String : ” + Integer.toBinaryString(low));
System.out.println(“High Surrogate Pair : ” + high + ” Hexadecimal : ” + Integer.toHexString(high) + ” Binary String : ” + Integer.toBinaryString(high));
String st = new String(ch);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(“krishna.xml”), “UTF-8″));
out.write(“”);
out.write(“”);
out.write(st);
out.write(“”);
out.close();

}
}

In the above case, the supplementary character written in xml was not the one it is intended to be. Don’t know whether it is the limitation of browser to display the supplementary characters or anything wrong in the way a supplementary character be handled in java code.

Some more understandings on java unicode support

March 9, 2006

From the start, java had used UTF-16 encoding for encoding the characters. Thus, in the earlier stages when the unicode character set was limited to 16 bits and hence was given full support by java character which was using the utf-16 encoding. Once the unicode was extended to support till the range U+10FFFF, the earlier UTF-16 encoded characters cannot represent characters more than U+FFFF. Hence, in J2se5, support was provided through the Character class. So, the primitive char still supports only the characters till code point: UTF+FFFF. The Java 2 platform uses the UTF-16 representation in char arrays and in the String and StringBuffer classes. In this representation, supplementary characters are represented as a pair of char values, the first from the high-surrogates range, (\uD800-\uDBFF), the second from the low-surrogates range (\uDC00-\uDFFF).

A char value, therefore, represents Basic Multilingual Plane (BMP) code points, including the surrogate code points, or code units of the UTF-16 encoding. An int value represents all Unicode code points, including supplementary code points. The lower (least significant) 21 bits of int are used to represent Unicode code points and the upper (most significant) 11 bits must be zero. Unless otherwise specified, the behavior with respect to supplementary characters and surrogate char values is as follows:

* The methods that only accept a char value cannot support supplementary characters. They treat char values from the surrogate ranges as undefined characters. For example, Character.isLetter(‘\uD840′) returns false, even though this specific value if followed by any low-surrogate value in a string would represent a letter.
* The methods that accept an int value support all Unicode characters, including supplementary characters. For example, Character.isLetter(0×2F81A) returns true because the code point value represents a letter (a CJK ideograph).

Back to Unicode support in java

March 9, 2006

Again got confused in unicode. Some of the terms used are:
1. Coded Character Set
A character Set(collection of characters) where each character has been assigned a unique number. E.g., Unicode character set, where every character is assigned a hexadecimal number.
2. Code Points
The numbers that can be used in a coded character set. Valid code points for Unicode character set is : U+0000 to U+10FFFF (Unicode :4 standard)
3. Supplementary Characters
Characters that could not be represented in the original 16-bit design of Unicode. U+0000 to U+FFFF are referred to as Base Multilingual Plane(BMP) and the others are supplementary characters.
4. Character Encoding Scheme
Mapping from the numbers of one or more coded character sets to sequences of one or more fixed-width code units. e.g., UTF-32, UTF-16, and UTF-8
4. Character Encoding
Mapping from a set of characters to sequences of code units. e.g., UTF-8, ISO-8859-1, GB18030, Shift_JIS.

UTF-16
UTF-16 uses sequences of one or two unsigned 16-bit code units to encode Unicode code points. Values U+0000 to U+FFFF are encoded in one 16-bit unit with the same value. Supplementary characters are encoded in two code units, the first from the high-surrogates range (U+D800 to U+DBFF), the second from the low-surrogates range (U+DC00 to U+DFFF). This may seem similar in concept to multi-byte encodings, but there is an important difference: The values U+D800 to U+DFFF are reserved for use in UTF-16; no characters are assigned to them as code points. This means, software can tell for each individual code unit in a string whether it represents a one-unit character or whether it is the first or second unit of a two-unit character. This is a significant improvement over some traditional multi-byte character encodings, where the byte value 0×41 could mean the letter “A” or be the second byte of a two-byte character.