Loop Asterisk Exercise Program

Hi, I know that a lot of students enrolled at basic programming course are searching for codes to display different layouts of asterisks using the “for loop” statement. I created a program for them to study it.

Click here to view the java source code.
http://pastie.org/1072278

Below is the sample output.

    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********

    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

             *
            **
           ***
          ****
         *****
        ******
       *******
      ********
     *********
    **********

    **********
     *********
      ********
       *******
        ******
         *****
          ****
           ***	
            **
             *

You can use this guide for your quizzes and exams..

Cheers

Installing Java and Tomcat 5.5 on Ubuntu Jaunty

If you want to try JSP with Tomcat then follow the steps:

1. Go to Applications -> Accessories – > Terminal

sudo apt-get install sun-java5-sdk tomcat5.5 tomcat5.5-admin tomcat5.5-webapps

2. After successfully installing all of the above packages, apt will prompt you for an error message. This is because of the java 5 documentation. Just follow the link that will be prompted by apt and download the files to /tmp. Then execute

apt-get install

3. Your web root will be at /usr/share/tomcat5.5-webapps/ROOT. This is where you will put your web applications or pages.

4. By default, tomcat runs on port 8180. If you want to change it to 8080 or just 80, edit the server.xml

pico /etc/tomcat5.5/server.xml

5. Search for this

<Connector port=”8180″ maxHttpHeaderSize=”8192″
maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″
enableLookups=”false” redirectPort=”8443″ acceptCount=”100″
connectionTimeout=”20000″ disableUploadTimeout=”true” />

and change 8180 to 8080 or if you want just 80.

6. Restart your tomcat

sudo /etc/init.d/tomcat5.5 restart

7. Open a browser and type,

http://localhost:8080

if you choose 8080 on server.xml, and

http://localhost

if you choose 80 on server.xml

Enjoy!

Running JBoss5 on Port 80

The default port of JBOSS is 8080. Clients having to access it will place something like this in the URL
http://xxx.xxx.xxx.xxx:8080 or http://somedomain:8080
Assuming you want it to eliminate the 8080 in the URL, you have to change the server setting of JBoss

You have to edit the file $JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml
where $JBOSS_HOME is the directory where your JBoss is, in FreeBSD it is /usr/local/jboss5 (installed via ports)

1. Look for the line
<Connector protocol="HTTP/1.1" port="80" address="${jboss.bind.address}"
connectionTimeout="20000" redirectPort="8443" >

2. change 8080 to 80

3. Restart your JBOSS server

Then you can access it without the :8080 on the URL

Getting the first letter of every word in a String using Java

This is a sample code on getting the first letter of every word in a String using Java. This may be helpful if you want to get the middle initial out of a middle name. If you have a middlename String with “de la Hoya” value and you want to have “dlH” then you use the code below

public class Test {
   public static String generateInitials ( String original ){
       String initial = "";
       String[] split = original.split(" ");

       for(String value : split){
            initial += value.substring(0,1);
        }

        return initial;
    }

    public static void main(String[] arg){
        System.out.println( generateInitials("de la Hoya") );
    }
}

Compiling and runnning the code will output dlH in your command line