JDK1.5 - Painful bugs: SolvedAugust 29th, 2004 Defects in early release of jdk.5 which have been solved.
JDK 1.6 Compiler Optimization performance difference between IP address to long implementationsAugust 5th, 2009 Just to give all ya techies some food for real geeky thoughts, here is a kind of an eye opener of how much JDK 1.6 compiler has optimized itself over the years. Our developers were working on a project that needed IP addresses to get simplified and be represented by numbers.
Understanding Varargs in Java: 2 Minute Guide For Non-DummiesApril 30th, 2006 Varargs allows variable number of arguments in methods and constructors. Let's start with a simple example.
Fibonacci Series in 1-Line PHP / Java SoftwareOctober 22nd, 2005 No, I am not competing for obfuscated code context. I realized while showing it to someone that Fibonacci series can be written much more succintly using modern programming languages like c, java or php.
How To Debug Execution Path in PHP...Equivalent of printStackTrace() in JavaMarch 1st, 2007 While programming in PHP often you will find that a simple echo or log statement is not sufficient. You have found out where a problem is happening but you have no clue why it is executing that code in the first place.
Java EE 5 is Not Your Father's J2EEApril 10th, 2006 Java Platform Enterprise Edition (Java EE, formerly referred to as J2EE) Version 5 has arrived. Its streamlined features offer added convenience, improved performance, and reduced development time, all of which enable developers to bring products to market faster.
Java Quiz: Why StringBuilder Should be Used Instead of StringBuffer?August 23rd, 2008 First tell me what is the best way to concatenate large number of String objects? Is it a + b?
Most Java developers know not to use a + b (+ operator) because of huge performance problems, they use StringBuffer instead. In fact I did some tests in the past which confirms this folklore.
Guide To Simplified Java Logging using Java Core APIJanuary 17th, 2006 Java comes in with a handy logging package (java.util.logging) which eliminates the need to use external logging packages like Log4J. However it still requires some configuration which makes it cumbersome and repetitive to include in every class.
Java Tip: Basic Authentication with HttpURLConnectionJuly 6th, 2007 Java provides a super simple, yet hidden from plain view, way to do basic authentication of HttpURLConnection / URLConnection. Before making a connection add the following lines of code:
final String login ="...";
final String password ="...";
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (login, password.toCharArray());
}
});
This sets your default Authenticator which is called whenever authentication is required for any URLConnection.
Java Program: Compare two text filesApril 29th, 2009 Today while managing the comments, I got a request of this sort. HI,
I have a small question in java.
HSQLDB Tip: Case Insensitive LIKE Query in HSQLDB RDBMS & Space Crunched String ComparisonJuly 21st, 2007 I previously discussed how to extend HSQLDB relational database with simple Java functions. The example there actually implements case insensitive like query functionality for HSQLDB.
How To Enable/ Disable Auto Reconnect in MySQLJuly 20th, 2007 What is auto reconnect in MySQL?
The MySQL client library can perform an automatic reconnect to the server if it finds that the connection is down when you attempt to send a statement to the server to be executed. In this case, the library tries once to reconnect to the server and send the statement again.
Calculate PI To Arbitrary Precision (Sample Java Code)November 13th, 2007 Sample Java code to calculate PI to arbitrary precision. This uses Machin's formula: pi/4 = 4*arctan(1/5) - arctan(1/239).
HSQLDB Cached Table Versus Memory Table Performance & ConversionAugust 13th, 2007 In short in HSQLDB cached table sucks in terms of performance. To elaborate I was running a program which takes around 9 hours running on two medium sized cached tables (bigger one 163 MB).
How To Compare Strings With == in JavaFebruary 25th, 2006 Almost every java developer finds one fine morning that he cannot compare String with "==" as he has been doing with int or char. Then either he finds out or someone kindly tells him that objects cannot be compared with "==".
October 30th, 2005 at 2:53 am
x : 1 y : 2
x = x + y;
x : 3 y : 2
x = x - y;
x : 1 y : 2
y = x - y;
x : 1 y : -1
October 30th, 2005 at 3:04 am
x = x+y;
y = x-y;
x = x-y;
October 30th, 2005 at 8:36 am
Maybe
x = x + y;
y = x - y;
x = x - y;
October 30th, 2005 at 9:24 am
@Jack & Alexey
Oops!
Thanks for the catch. Corrected.
Just checking if you are attentive
October 30th, 2005 at 9:25 am
BTW: I actually asked this question today while interviewing candidates.
October 31st, 2005 at 8:15 am
The string sample will fail if the string x contains the string y. For example,
String x = “Hello World”;
String y = “Hello”;
Step 1: x = x + y;
x = “Hello WorldHello”
Step 2: y = x.substring(0, x.indexOf(y));
x.indexOf(y) = 0, so y = “”;
Step 3: x = x.substring(x.indexOf(y) + y.length());
x.indexOf(y) = 0 and y.length = 0, so x = “Hello WorldHello”
You can fix this by using lastIndexOf() method in String like
x = x + y;
y = x.substring(0, x.lastIndexOf(y));
x = x.substring(x.indexOf(y) + y.length());
or you could eliminate the indexOf() calculations altogether and just use the lengths of the strings
x = x + y;
y = x.substring(0, x.length() - y.length());
x = x.substring(y.length());
October 31st, 2005 at 8:53 am
@Robert
I like that. It looks cleaner.
November 9th, 2005 at 2:08 am
Unfortunately, the code to exchange integer values will fail for values that cause over- or underflow.
However, you can use exclusive-or (xor), which is like add without carry. The following unobvious code exchanges all int values.
x = x ^ y;y = x ^ y;
x = x ^ y;
September 28th, 2006 at 6:10 am
im coding a anagram word game to swap letters from one label to another (up to the down) by using a threeBottons class how should i use the string and char code? (the second character of label one should place to the second character of label two) i need that much help thanks
November 29th, 2007 at 8:30 am
import java.io.*;
class ab
{
public static void main(String arg[]) throws IOException
{
int x=6;
if(x=6)
{
System.out.println(”Hi…”);
}
}
}
the question is .. Is it possible to run this program with out changing if(x=6)
February 26th, 2008 at 4:34 am
if(x > y)
{
x = x- y;
y = y + x;
x = y - x;
}
else
{
y = y - x;
x = x + y;
y = x - y;
}