
Download PDF

Download E-Books
JAVA GEEKS ZONE

[Source: bigdownload.blogspot.com]
Say x & y are the integer variables. The challenge is to swap them without using a temporary variable.
The solution is as simple as the problem itself:
x = x + y;
y = x - y;
x = x - y;
Update 1: Jack and Alexey pointed out a typo in my solution which has since been corrected. Please see their comments below.
The simplicity of the solution appeals to me. It clearly demonstrates the meaning of assignment operator ( "=" ).
What if they are Strings?
Note: You can use String methods in Java API.
Here is the solution:
x = x + y;
y = x.substring(0, x.indexOf(y));
x = x.substring(x.indexOf(y) + y.length());
Can you see the similarity?
Can you provide a simpler solution to either of the above?
Update 2: Robert just did (see his comment below). He pointed out that the String solution doesn't work when one string is contained in another. His solution is:
x = x + y;
y = x.substring(0, x.length() - y.length());
x = x.substring(y.length());
Replace *.html with file name(s) and directories you want to update. This requires JDK 1.5 or later.
import java.io.File;
/** Super-fast file / directory(recursive) touch.
* It doesn't ask for confirmation.
* Arguments: File / Directories to touch to current time.
*/
public class Touch {
public static void main(String ... args) {
long time = System.currentTimeMillis();
for(String fileName:args) touch(new File(fileName), time);
}
/** Recursively touch file and directories.
* @param File (file or directory) for touching.
*/
public static void touch(File file, long time) {
if(file.isDirectory()) for(File childFile:file.listFiles()) touch(childFile, time);
file.setLastModified(time);
}
}
/** Super-fast file / directory(recursive) touch.
* It doesn't ask for confirmation.
* Arguments: File / Directories to touch to current time.
*/
public class Touch {
public static void main(String ... args) {
long time = System.currentTimeMillis();
for(String fileName:args) touch(new File(fileName), time);
}
/** Recursively touch file and directories.
* @param File (file or directory) for touching.
*/
public static void touch(File file, long time) {
if(file.isDirectory()) for(File childFile:file.listFiles()) touch(childFile, time);
file.setLastModified(time);
}
}
/** Super-fast file / directory(recursive) touch.
* It doesn't ask for confirmation.
* Arguments: File / Directories to touch to current time.
*/
public class Touch {
public static void main(String ... args) {
long time = System.currentTimeMillis();
for(String fileName:args) touch(new File(fileName), time);
}
/** Recursively touch file and directories.
* @param File (file or directory) for touching.
*/
public static void touch(File file, long time) {
if(file.isDirectory()) for(File childFile:file.listFiles()) touch(childFile, time);
file.setLastModified(time);
}
}
/** Super-fast file / directory(recursive) touch.
* It doesn't ask for confirmation.
* Arguments: File / Directories to touch to current time.
*/
public class Touch {
public static void main(String ... args) {
long time = System.currentTimeMillis();
for(String fileName:args) touch(new File(fileName), time);
}
/** Recursively touch file and directories.
* @param File (file or directory) for touching.
*/
public static void touch(File file, long time) {
if(file.isDirectory()) for(File childFile:file.listFiles()) touch(childFile, time);
file.setLastModified(time);
}
}
String[] poList = pos.split("\r\n|\r|\n");
What did I do?
I am splitting the String based on a regular expression which looks for carriage return (\r) or line feed (\n) or carriage return immediately followed by line feed. These takes care of all types of newlines you may encounter. It returns, as you can see, a String array of results. Trailing empty strings are not included in the resulting array.
What's interesting?
The following will include a whole bunch of empty Strings in the result.String[] poList = pos.split("\r|\n|\r\n");
Can you tell why?
How many alternatives can you tell like using StringTokenizer for example?
This old but still golden article is an excellent guide to using Runtime.exec(). The key points he discusses are:
1. You need to drain the input stream to prevent because failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
2. Use waitFor() instead of exitValue() when you want to wait for the process to finish.
3. Runtime.exec() wouldn't directly execute shell commands like dir / ls, copy / cp etc. You need to invoke the shell cmd.exe / bash / sh and pass the shell commands. For example in windows your command array to execute dir would be as follows:
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "dir";
Personally I have successfully used Runtime.exec() on several occasions. Any C programmer should quickly find equivalence with fork and system calls in C language. As always RTFM.

The files are added to a queue first and then uploaded. The live file upload status and statistics are shown. The extension is pretty stable and usable. You can see a demo here. It is based on high quality Ext framework and hence is cross browser compatible.
The server side of the code is not provided. So it is for you to explore and find. A sample server side implementation say in PHP or Java is what is missing from this otherwise excellent piece of work.
Details here.
While debugging code Java programmers often use System.out.println(). It is important to write separate message in each System.out.println() so you can understand from the output where the problem lies.
Now it is time-consuming and somewhat tedious to invent new message for each System.out.println() debug message. What if you could call methods which allows you to print the current file name and line number?
That would automatically ensure unique message in every System.out.println(). Also it will help you to immediately pinpoint the offending code. You can copy-paste something like this anywhere in your code (embellish it with more topical information as needed) and be able to pinpoint its location:
System.out.println(getFileName() + ":" + getClassName() + ":" + getMethodName() + ":" + getLineNumber());
I will show the implementation of getLineNumber() below and leave the rest as an exercise:
/** Get the current line number.
* @return int - Current line number.
*/
public static int getLineNumber() {
return Thread.currentThread().getStackTrace()[2].getLineNumber();
}
Have you noticed the magic number - 2? Can you explain it?
The best way to suppress unchecked or other warnings is to fix the cause of the warning. However in some rare cases, the warning is incorrect and there is no logical way to solve it without compromising the intended functionality. For such cases there is a simple solution:
Add the following just before the method definition:
@SuppressWarnings("unchecked")
This stops any unchecked warnings from the code within the method.
15 Google Search Features You Must Know

Registry Editing Has Been Disabled By Your Administrator
if yes then you need not to worry. There are two solutions for this.
This is a very simple trick.
REG add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableRegistryTools /t REG_DWORD /d 0 /f 
Do you want to change Windows name to yours. Then follow the trick. This trick will enable you to show your name in the Windows Information page. Whatever you put, will be seen as the properties section of My Computer. Surprise your friends and others with this one.
[General]
Manufacturer=Your Name Here
Model=Your Model Here
[Support Information]
Line1=Your Name
Line2=Your Address
Line3=Your Email Address
Ex: Line4=Your Working Hours
There have been times when we needed a PDF file to edit. So we have converted that to a word document with the help of hundreds of free software across the internet. But what if you need a word document to be converted to PDF? If you love to read through the computer screen then PDF is always the best option. So is it for print-outs. Here are 5 easy ways to let you convert a word document to a PDF file format.
1. Using Open Office
1. Download OpenOffice from openoffice.org
2. Install it to your computer.
3. Open the Word document you want to convert.
4. From the main menu select File > Export as PDF (There is also an export to PDF button right on the main taskbar.)
5. Choose a filename for your PDF.
6. Choose the options you want, or just hit save/ok.
2. Using Online Converter
1. Go to ExpressPDF
2. Click 'browse' and select the file on your computer.
3. Click 'Convert to PDF' and wait for it to process.
4. They will send the link to your PDF file to your e-mail inbox.
5. There are also printpdf.com and doc2pdf.net. You can try them too. But I chose it only because its fast, secure and more importantly supports upto 20 MB of file size to convert to PDF which others don't.
3. Using Google Docs
1. Backup your file
2. Go to docs.google.com
3. Click upload
4. Click browse
5. Select the file you would like to convert
6. Click the upload button
7. Under the file menu; on the far left, under the Google logo select save as PDF. Though there have been complaints that the saved file differs from the actual. The conversion is not centpercent error free.
4. Using Media Convert
1. Go to media-convert.com
2. Click 'browse' and find the file you want to change to a PDF.
3. Leave the input as auto detect.
4. Go down to output and select PDF.
5. Click Convert and wait for it to process.
6. Download your freshly created PDF.
5. Use a Utility like PDF995
1. There are 2 little files to download and install, a printer driver and the converter.
2. Download from pdf995.com/download.html
3. Save to your favorite downloads location, such as c:/downloads
4. Double click on each zip file to uncompress and install
5. To use it, you open any document, and choose PDF995 as the printer.
6. So, in Word, do File> Print. then change the printer to PDF995.
7. This will actually print to a file, so choose the save location.
So here are 5 extremely easy ways to convert a doc to a PDF. Did you like it? Do you have more to share? Please feel free to do so.
So you got the lost or forgotten product key, right? Keep it safe.

Do you find it annoying enough to hunt down the audio recorder every time from the Start Menu?
-Well don't worry. You have used Windows+E to launch the explorer, now you will do it for all the appications too. Here is a very simple trick which will allow you to launch any Windows application at the touch of a button.
Setting up a keyboard shortcut for any application in your start menu is fast and simple. Steps below explain how to create program shortcuts in Windows:

Now, whenever you want to quickly launch Calculator, just hit Ctrl-Alt-C (or whatever key you chose). I use application launch shortcut keys all the time for Calculator and Notepad. You can use it for those programs you constantly use and are sick of navigating through the Start menu to launch.
[Source: stupidsite.org]
Use software restriction policy in group policy. This one can only be used in WINXP Pro and Vista Permium and the higher. You can restrict the access of all the programs or executable files in USB pendrive through this policy.
When you want to access the executable files you are sure of no harm, you can turn off the restriction. This is a wonderful way to protect your pen drive from viruses.
Use the "Force Folder" feature in Sandboxie. This feature will make all the program / executable files in the folder you have chosen to run in Sandbox. For example, the drive of your USB pendrive in your computer is F:. Then you can set F: as force folder, and all the programs in F drive will be run in Sandbox. To know more about Sandboxie, please pay them a visit.
[Source: greatskills.blogspot.com]
Do you want to recover the MySQL root password. its by no means, easy. But its quite simple if you follow the procedure. You will have to follow this step-by-step processes.
Here are the commands you need to type for each step (log in as the root user):
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld.
# mysqld_safe --skip-grant-tables &
Output:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
# mysql -u root
Output:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-logType 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended[1]+ Done mysqld_safe –skip-grant-tables
Now Start the MySQL server and test it:
# /etc/init.d/mysql start
# mysql -u root -p
[MySQL command sources: howtoforge.com, Million thanks to them]
To begin with I had my 4GB USB 2.0 reformatted to FAT 32.
The next step was to copy the contents of the Windows 7 Beta ISO image to the memory stick using
xcopy
(e:was my DVD drive and f: the removable drive )
The installation was not just easy but as quick that I could have clocked the time. It was much faster than those DVD installations on Desktops.
I must add, with Windows 7 it was a better netbook experience than previous operating systems.

It is the most effective way of hiding email id, but it requires a new account, If you have some larger communities and want safety, then follow this method:
So enjoy a clean and spam free orkut account. tell us if it worked for you and if you have any other suggestion.
[Source: itecharena.blogspot.com]


I know Microsoft Word is the most reliable document creator for most of us. Be it office work or personal attachments, using MS word is inevitable. However, all work and no play makes anyone dull. So why don't we try this cool trick to insert sound clips to a MS word document. may be you can impress your boss with a light hearted presentation or your friends with this cool trick.
Its just so simple.
1. Go to Run, Type regedit, press enter.
2. Navigate to [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer].
3. At right panel, look for an entry called NoFolderOptions. Right click on it and Delete.
4. Navigate to [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer].
5. Repeat step 3 to delete NoFolderOptions entry.

Apple has an incredibly useful app for its iPhone i.e. MobileMe which keeps the former in sync with your desktop as your email, contacts, and calendar stay the same wherever you check them, no matter what device you use. But the pain is it costs you $ 0.99.
Google has a GoogleSync running for iPhone but the problem is, quite uncharacteristically Googlesync has some bugs inside it. So we don't recommend it as yet fully. If you insist, make sure to take a backup before you use it.
Microsoft® My Phone syncs information between your mobile phone and the web, enabling you to:
My question: Then what is it worth?
This may just be the beginining of Microsoft's realization of moving towards more freebies and approach an Open Source Desktop Strategy. Considering its Microsoft, we can not expect much and most certainly with so many features not included in the list, MyPhone is supposedly not going to create any storm yet. But we will see how Microsoft takes this FREE product service and as far as Open Source is concerned, I don't think Microsoft will ever think that they are ready. Anyway, free will do for now.