Though i have been handling error/exceptions on JAVA for about 5 years now from the day i started “Hello World!!!”, I never knew that there is a limit in JAVA for size of the method. And I never got into a situation like “Code too large to compile” which is not a simple message rather its a compilation error in Java when you exceed the size limit of the method. Glad to read the link , it added more on my knowledge in Java.
Java has a 64k limit on the size of methods.
I bet this is the least faced error/exception by any Java programmer. But though we face it or not IMHO this is a good point that Java put limit on the size of the method because if a single method would go beyond 64K limit then there would be minimal difference between a procedural and OO language and hence hard to maintain. Methods need to be very specific and solving only some dedicated tasks and you can imagine when it’s size goes beyond 64K, it goes towards generic concept. It’s my opinion but if you want to add your opinion then you are most welcome.
You may be wondering how to encode plain text password and save it on DB so that if somebody authorized person(like manager, admin) wants to see your password from his/her account or even directly on DB then that person shouldn’t get any username’s password then you can use following techniques to encrypt/encode password using MD5/SHA in Java. This is just a once way encoding technique. For comparing the user’s password again you need to encode the password submitted by user and compare it with the value stored in Database and can authenticate the user.
import java.security.*;
public class MD5
{
public static void main(String[] args) throws Exception
{
String password= md5("useThisAsASalt" + args[0]);
System.out.println(password);
}
public static String md5(String str) throws Exception
{
StringBuilder sb = new StringBuilder();
for (byte b : md5(str.getBytes()))
sb.append(Integer.toHexString(0x100 + (b & 0xff)).substring(1));
return sb.toString();
}
public static byte[] md5(byte[] data) throws Exception
{
//MessageDigest md5 = MessageDigest.getInstance("MD5");
//md5.update(data);
//return md5.digest();
MessageDigest sha = MessageDigest.getInstance("SHA");
sha.update(data);
return sha.digest();
}
}
In the above code, i have also used the concept of salt (i saw it being implemented in spring-security). The concept of salt is to reduce password guessing as we will be having hard-coded string appended with the password, which reduces the chances of password guessing.
Hope this helps you in doing some encoding in Java for passwords.
Keep up the good works!!!!!.
If we want to run independent sites for different domains, we can make use of a concept called “Virtual Hosting”. A servlet container is able to serve different applications depending on the requested domain.
== Configure Tomcat to serve multiple sites ==
* Create a folder called "sites" in Tomcat (so "sites" and "webapps" are contained within the same directory in the root of your Tomcat-installation).
* Create a subfolder "yourdomain.org" in sites.
* Copy a fresh (or already customized).war from a your application distributable to "sites/yourdomain.org"
* Now edit Tomcat/conf/server.xml and add a second entry for a new virtual host right below the definition for the default host (which is the first entry below):
<pre>...
<!-- This entry is already contained in server.xml -->
<!-- This entry adds a virtual host for yourdomain.org -->
...</pre>
* Now restart Tomcat.
* From now on Tomcat serves all requests for http://yourdomain.org/ from the ROOT-application contained in "sites/yourdomain.org".
== Configure Jetty to serve multiple sites ==
* Create a new folder called '''"sites"''' in the root directory of your Jetty installtion.
* Create a new folder '''jetty/sites/yourdomain.org/'''
* Copy your.war to '''jetty/sites/yourdomain.org/'''
* Create a file with the following content to '''jetty/conf/yourdomain.xml:'''
<pre>
/
/sites/yourdomain.org/your.war
www.yourdomain.org</pre>
* Now restart Jetty.
== Configure Apache as proxy for a servlet container ==
If you're running Apache in front of your servlet container, you'll need to configure Apache as proxy server for your servlet container as follows:
<pre>
Order Allow,Deny
Allow from all
ServerName yourdomain.org
ServerAlias www.yourdomain.org
ProxyPass / http://www.yourdomain.org:8080/
ProxyPassReverse / http://www.yourdomain.org:8080/</pre>
This way you can easily add additional sites as well. That’s easy, isn’t it?