Skip to main content

Posts

Every thing about ConcurrentHashMap

Why ConcurrentHashMap is better than Hashtable and just as good as a HashMap http://www.codercorp.com/blog/java/why-concurrenthashmap-is-better-than-hashtable-and-just-as-good-hashmap.html Why ConcurrentHashMap does not support null values http://anshuiitk.blogspot.com/2010/12/why-concurrenthashmap-does-not-support.html
Recent posts

Separate a string into separate "tokens"

Remember CSV files!!! It's common to have to separate a string into separate "tokens". These tokens can be words, numbers, commands, or whatever. Ways to parse separated using delimiter- http://leepoint.net/notes-java/data/strings/96string_examples/example_stringToArray.html A StringTokenizer class that handle empty tokens. http://geosoft.no/software/tokenizer/SmartTokenizer.java.html 

MySql Timediff and JDBC (ConnectorJ) - Bad format for Time 'hhh:mm:ss' in column x

MySQL Types to Java Types for ResultSet.getObject(). MySQL Type Name Return value of GetColumnClassName Retur TIME TIME java.sql.Time http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-type-conversions.html ResultSet.getTime() will fail with an SQLException: "Bad format for Time 'hhh:mm:ss' in column x" http://bugs.mysql.com/bug.php?id=11154 Surprisingly (Shockingly) ResultSet.getString() was also throwing the same exception "Bad format for Time". http://forums.sun.com/thread.jspa?threadID=5149261

New language features in java7

new features : * Language support for collections * Automatic Resource Management * Improved Type Inference for Generic Instance Creation (diamond) * Underscores in numeric literals * Strings in switch * Binary literals * Simplified Varargs Method Invocation Refer:- http://code.joejag.com/2009/new-language-features-in-java-7/

MySQL :: tinyInt1isBit

One can enter values apart from 0 and 1 (say 2,3,?100) in a field with tinyint(1) type in MySql. MySql doesn?t complain. Now if you want to read inserted data using PHP it will return value as it is, however this will not work with Java. Java will throw an exception while reading same MySql data. Java treats tinyint(1) as Boolean and returns only true or false. Two solution either we can make our column tinyint(something > 1), or can add the connection property 'tinyInt1isBit=false' to our JDBC URL. Adding connection property 'tinyInt1isBit=false' to JDBC URL is risky since it will affect entire database data while reading the same using Java. Refer : http://forums.mysql.com/read.php?39,10652,10669#msg-10669

Apache 2.o.x and ProxyTimeout

Apache documentation says that mod_proxy supports ProxyTimeout directive in Apache 2.0.x, however it doesn’t. Apache 2.0.x completely IGNORES ProxyTimeout directive. Click this to know more . Their release notes says that they tried to fix this bug in 2.0.61 version but that fix doesn’t work even. You would find correct implementation of this directive in Apache 2.2.X. No OTHER WAY. I tried following patches but they doesn’t work. http://marc.info/?l=apache-httpd-dev&m=120362209316755&w=2 http://svn.apache.org/viewvc/httpd/httpd/branches/2.0.x/modules/proxy/mod_proxy.c?r1=421178&r2=535853&pathrev=550514&diff_format=h http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/modules/proxy/proxy_util.c?r1=536291&r2=556972&pathrev=556972&diff_format=l So finally we used our RAMBAND and increased overall timeout of the Apache 2.0.53 server using Timeout directive

Class data sharing

CDS provides ability to share classes between Java virtual machines (JVMs). When classes are loaded by the JVM, they can be placed in a cache. When subsequent requests for that class are made, these requests are satisfied from the cache if possible rather than loading the class from a corresponding .jar file. Refer:- http://java.sun.com/j2se/1.5.0/docs/guide/vm/class-data-sharing.html

Y FreeBSD ?

Now I understood why we are using FreeBSD as an OS for our product Every smile matters see this http://people.freebsd.org/~murray/bsd_flier.html Most Impressive line about BSD I read "BSD is what you get when a bunch of Unix hackers sit down to try to port a Unix system to the PC. Linux is what you get when a bunch of PC hackers sit down and try to write a Unix system for the PC." More reading FreeBSD   vs. Linux vs. Windows 2000 http://people. freebsd .org/~ murray/bsd_flier.html http://www.over-yonder.net/~ fullermd/rants/bsd4linux/ bsd4linux2.php

Bypass 101.222.*.* in FireFox

Interestingly Firefox does not understand start (*) in bypass proxy "No Proxy for:" textbox. Somewhere I came to know the notation which works fine for FIREFOX! its not a great discovery and there is an example given below "No Proxy For:" 192.168.1.0/24 However sooo many pepole don't know what is the meaning of 192.168.1.0/24. So this how we can utilize that - 1. 101.222.*.* - means first two fields are fixed. 2 (First 2 fixed fields) x 8 = 16. So you can use 101.222.0.0/16 instead of 101.222.*.* 102.*.*.* - means first field is fixed. 1(First fixed field) x 8 = 8. You can use 102.0.0.0/8 instead of 102.*.*.* Simple! It just works Cheers,

Tomcat Optimization

Remove every unwanted installed application This will save you startup time, as well as memory used by preloaded servlets. Web-application which comes with tomcat are : jsp-examples balancer tomcat-docs webdav servlets-examples. manager host-manager ROOT Don't delete (if needed ) :- manager and host-manager :- one can utilize them to upload application dynamically without stopping tomcat server. We need to set autoDeploy to true to make use of manager applications. balancer :- it provides clustering and load balancing capabilities that are essential for deploying scalable and robust web applications. Changes in Server.XML Set the autodeploy attribute of the tag to false (unless you need any of the default Tomcat applications like Tomcat Manager). Setting autoDeploy and unpackWARS to false as we are not deploying and updating web applications dynamically. We are also not using the default Tomcat applications like Tomcat Manager for dynamically web application deployment. Changes

Java Web application and UTF-8

Java and UTF-8 Generally we can rely on Java as long as source strings are properly encoded. Please refer link: http://java.sun.com/docs/books/tutorial/i18n/text/convertintro.html, http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp Tomcat and UTF-8 JSP pages must include the header: <%@ page contentType="text/html; charset=UTF-8"%> Update the file $CATALINA_HOME/conf/server.xml : add attribute URIEncoding="UTF-8" in Connector tag Add filter as suggested in the link : http://wiki.apache.org/tomcat/Tomcat/UTF-8 Tomcat UTF-8 Problem with request.getParameter(), http://answers.google.com/answers/threadview?id=580467 useBodyEncodingForURI : http://tomcat.apache.org/tomcat-5.5-doc/config/ajp.html MySql and UTF-8 We need our databases and tables to be in utf8 character set : ALTER tables with an SQL statement like - ALTER DATABASE db_name CHARACTER SET utf8 COLLATE utf8_general_ci; Start mysql-demon using option "--character-set-se

Page Redirection Problem

Page Redirection Problem After performing a File Download? Suppose we have a page (php) which lists items with check boxes and drop down list for choosing the action (like download , delete) to be performed on the items selected. When one selects the action download we redirect the page to a php whose response content-type is "application/zip". This works fine and displays download file dialog. The problem is that after downloading the file, the user is still in the download page. What we would want to do is after the user downloads the file.. we would like to redirect him automatically to another page (Thank You Page, etc.) or back to the page listing the items. I have not found solution which exactly solve this problem, however we can find some alternative solutions here .

Java and “\u” ( blackslash u )

This article is related to escaping of “\u” backslash u [Unicode character] in Java Problem Statement: I have a string which consists of a DOS path something like "\sample\user_data\example".The “\u” (backslash u) in “\user_data” above gives “an invalid Unicode” JavaScript error in IE and hence my page isn’t displayed. I tried to replace “\u” (backslash u) in the string with something like "\ u"(backslash u) as I was not able to escape it. This also does not work . Java complier does not allow “\u” (backslash u) character and gives "Invalid unicode character sequence" error when I use it with replaceAll. Que 1: Can I escape the \u character some how in Java or JavaScript? Que 2: How can I replace all "\u" character in a string with something else like "\ u"? I have posted this query to some of the Java and JavaScript related groups. Here are the solutions I found Before going into the details about solution let us

Securing MySQL (Java / Php Developers)

This Article would be useful to the people those who are using MySQL on a server connected to the Internet and hosted a web application (Developed using Java or/and PHP) on same server. This would also allow users to avoid a common security mistakes and Java developer to understand an issue related to UNIX socket. Usually MySQL uses port 3306 by default. This port should not be accessible from un-trusted hosts and should be closed, unless you really have a good reason to keep it open . This can be done on Server’s firewall or router, however M ySql provides its own security options like 1. skip-networking 2. bind-address 1. skip_networking This option was added in MySQL 3.22.23 and is recommended for systems where only local clients are allowed.To enable this option, put “skip-networking” in the mysql configuration file (/etc/mysql/my.conf). If this option is ON the server allows only local (non-TCP/IP) connections. Any clients (even clients running on the same host) using the remote