Dec 18

If you get the following error and not sure how to fix it then read on.


Caused by: javax.mail.MessagingException: 501 Syntax: HELO hostname
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
at javax.mail.Service.connect(Service.java:248)

This is typically caused by the system property “mail.smtp.localhost” not being set by your Java VM. This should be already set for you automatically if your runtime environment is configured properly.

From the javadoc:

Local host name used in the SMTP HELO or EHLO command. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly.

Hope this helps.

written by objects \\ tags: , , , , ,

Dec 15

The Runtime class has an availableProcessors method that returns the number of processors available to the JVM.

int processors = Runtime.getRuntime().availableProcessors();

The value may change during the execution of your application, so poll regularly if your application is dependant on the number of processors available.

written by objects \\ tags: , , ,

Dec 14

When you need to format a number as a percent you can use the ‘%’ symbol in your DecimalFormat string. The static helper method getPercentInstance() can also be used if you don’t need complete control over the format string.

When the % symbol is used the value is first multiplied by 100 before applying the format string. So 0.123 would become 12.3%.


NumberFormat format1 = new DecimalFormat("##.####%");
NumberFormat format2 = NumberFormat.getPercentInstance();

String formatted1 = format1.format(value);
String formatted2 = format2.format(value);

written by objects \\ tags: , , , , , ,