- my webspace

- my webspace

Latest Comment

Allama Iqbal - Selective verse...
Yahoouj
Really good work about this website was done. Keep trying mo...
07/03/10 21:04 More...
By Roderick

Allama Iqbal - Selective verse...
Great Job
You have dont a great job of collecting these... Even I had ...
25/08/09 07:01 More...
By Sikandar

O ye who don't believe !
It's like Lehman Brothers :grin
11/10/08 16:31 More...
By anurag Chaturvedi

I Protest
@Sikku
Thanks Sikku for the feedback. I never intend to blame, a...
29/07/08 17:06 More...
By Aminur Rashid

I Protest
Great !!!
:zzz this is a wonderful story and very honest from the hea...
29/07/08 10:33 More...
By Jennifer Gallagher

Login






Lost Password?
No account yet? Register

Tell a Friend

Home arrow Java
How to detect proxy while connecting a url PDF Print E-mail
User Rating: / 0
Written by Aminur Rashid   
Wednesday, 01 April 2009


When I started learning Java (infact I still am) I was stuck in assignment to open the net connection, which was outside our institute firewall. The document at Sun's website explains in depth the traditional, as well as the latest way (Use of Proxy class/Proxy Selector)to use Proxies to connect to a network. To refresh what I used, here is the code using the traditional method.

Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (110) | Quote this article on your site | Views: 380 | E-mail

Read more...
 
Ctrl-shift-F1 in Swing Applications PDF Print E-mail
User Rating: / 0
Written by Aminur Rashid   
Thursday, 26 March 2009
To see the hierarchy of a components in a swing application, one nice way is to type ctrl-shift-F1. Typing ctrl-shift-F1 displays the GUI hierarchy shown below:

Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (76) | Quote this article on your site | Views: 319 | E-mail

Last Updated ( Tuesday, 07 April 2009 )
 
Prevent reflection to access private methods and members in java classes PDF Print E-mail
User Rating: / 1
Written by Aminur Rashid   
Thursday, 26 March 2009

Reflection is a nice evil. It can let you access private method/fields/constructor of a class.
import java.lang.reflect.Field;

public class UseReflection {
	public static void main(String args[]) {
		Object prey = new Prey();
		try {
			Field pf = prey.getClass().getDeclaredField("privateString");
			pf.setAccessible(true);
			pf.set(prey, "Aminur test");
			System.out.println(pf.get(prey));
		} catch (Exception e) {
			System.err.println("Caught exception " + e.toString());
		}

	}
}

class Prey {
	private String privateString = "privateValue";
}

Now in case you are wondering, that makes my class vulnerable to be modified, yes you are right. But then there is a way to prevent the caller from changing the modifier/changing the accessor. The easiest thing is to use the SecurityManager. Run the programme again using the default securitymanager provided by Java
 
java -Djava.security.manager UseReflection

For more on DefaultPolicy Implementation, you may want to read the document at sun.

Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (66) | Quote this article on your site | Views: 394 | E-mail

Last Updated ( Thursday, 26 March 2009 )
Read more...
 
JFormattedText Field with Date PDF Print E-mail
User Rating: / 1
Written by Aminur Rashid   
Wednesday, 25 March 2009


While trying JFormattedTextField, I had this requirement to show placeholder to the user to guide him providing the date input. There was also a need to pop up user with the error message, if the input is correct. (Yeah, I understand that many prefer inline error messages than the pop-ups but then requirements are requirements.) One way could be to provide a MaskFormat to the JFormattedTextField and use directly validates the date, yourself using the pattern. What I tried is used both the DateFormat and MastFormat with the JFormattedTextField. The code can be modified for individual needs but the idea is to provide an input verifier to the JFormattedTextField. Use the formatter set for JFormattedTextField to verify the inputs. Along with these, also install a mask formatter to show placeholders to user.

Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (54) | Quote this article on your site | Views: 376 | E-mail

Last Updated ( Tuesday, 07 April 2009 )
Read more...
 
<< Start < Prev 1 2 Next > End >>

Results 10 - 13 of 13
Aminur Rashid