JC Web Concepts

Java Hello World

Well I have decided to jump back into Java programming due to some recent events. I went out and bought Sams Teach Yourself Java in 24 Hours to help me in this journey. So to help me grasp the material I wanted to create blog posts/tutorials to help me and to help others who might be on this same goal.

Oh and the two things that you will not see the void main for is applets and servlets. Here is the source code of the file I created

class HelloWorld {
  public static void main(String[] args) {
      String sayHello = "Hello, World!";
      String myName = "John Costanzo";
      int myAge = 28;
      boolean theTruth = false;
      System.out.println(sayHello + " My name is " + myName);
      System.out.println("Is my age " + myAge + "?\nThe answer is " + theTruth);
  }
}

VIM Tutorial

When I first started working with Linux one of the tools I disregarded was VIM. I felt it to be too confusing and believed it was not worth it at all. I was so use too notepad, nano, pico, etc… Then a programmer finally convinced me one day to make a switch. I am so glad I did. So the first thing you have to get use to is that there are two modes to be in. One is command mode and the other is in insert mode. When in command mode you can save or do other things like find and replace. In insert mode you do like you normally do. You type away. I know it sounds confusing now but wait and I will show you what I mean.

VIM can be found in Mac, Linux, Unix, and or Windows. To start a file you bring up your terminal or if in Windows you open the application in your start menu. In the terminal type the following:

vim whateverfilename

Command Mode

Ok so lets get into some of the things you can do in command mode. So lets say you have to edit a document for work and you have to change the word Bob with the word John. hit ESC to make sure you are in command mode and hit the following:

:% s/Bob/John/g

The g at the end will make sure it goes thru the whole document. To search for some text is not that hard to do. So lets say we want to find all instance of the word happy. You will do the following:

/happy

When you find the first result you can hit n on your keyboard to go to the next instance that it finds the work happy. If there is none it will tell you that there is none. Now I am sure you are asking how do I search for multiple words? Well let me show you how to search for Happy Birthday

/Happy Birthday

As you can see you I did the same thing as above. VIM knew that you were looking for multiple words. Before you ask if there is a term in the document called Birthday of Happy, it will not bring that up as a result. The next thing I want to show you is if you need to get to line 10000 in a file all you have to do is the following:

:10000

Yep that is it. To wrap up this first tutorial on VIM I will show you how to quit without saving, saving but not exiting, and saving and exit. Here they are in order.

:q!

The q stands for quit. If you forget the ! you would be prompted about saving before quiting

:w

The w tells VIM that you want to save the changes

:wq

As you see we combined the w and the q to save the changes then quit. Now before you ask, if you would do :qw that would fail. Cause vim reads the commands from left to right. Well I think that is enough for now. If you have any questions about vim please post a comment. Below is a video on what I basically explained above.

Web Server Ubuntu 9.10

So I thought I would write up a tutorial on how to install a web server that will support Apache, PHP, and MySQL. I will go over some configuration file adjustments as well. So lets get into this and lets open up your terminal and do the following:

john@jcwebconcepts.net:~$ sudo taskel install lamp-server

Now during this process you will be asked a few things. You will be asked for a MySQL password. The password you will set will be your root users password. When it is installing PHP it might ask you what type of module do you want to install for. You will want to select Apache2. This will take a few minutes to install. Once done you can open up your web browser and put in the address bar the IP address of your web server. Now lets edit the default file for your website.

john@jcwebconcepts.net:~$ sudo vim /etc/apache2/sites-available/default

        # If this is going to be internal only then you can leave this alone
        ServerAdmin webmaster@localhost
        # Now you need to add the following line. If this will be internal then put internal
        # IP. If this will be external then you would either put domain name or outside IP
        ServerName 192.168.2.110
        # Because you server will support PHP we need to setup a directory index
        DirectoryIndex index.php index.htm index.html
        DocumentRoot /var/www
                Options FollowSymLinks
                AllowOverride None
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        ErrorLog /var/log/apache2/error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
    Alias /doc/ "/usr/share/doc/"
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128

The directory index basically tells the server what files to look for in one is not specified. For example if I do http://www.jcwebconcepts.net/ the server will look in the server root directory for the following files: index.php index.htm index.html. If they do not exist you will get an error. And that is it for setting up your own web server in Ubuntu 9.04. I have tried this in the alpha 9.10 and it works as well.

iPhone Ringtones

I was looking around and I thru bits of pieces of pages I found out how to make your own ringtones to use for your iPhone. Now I am not sure this is illegal cause you own the music. At least I hope you are not stealing. So open up iTunes and lets begin.

  • Find the song you want to use for a ringtone.
  • Listen to the song and find 30 seconds of it that you want to use. Write down the start and end time.
  • Right click on the song and click on get info.
  • Click on the Options tab and check the start and stop time boxes. Enter the time you wrote down and click ok.
  • Now right click on the song again and click on Create AAC Version. You should see a new song with a 30 second time.
  • Right click on the 30 second one and click delete. You should get a prompt about keep file or delete it. Move to trash if you are on a Mac. Do not move it to the trash.
  • Now locate the song. If you are on a Mac it will be in your iTunes folder under your username. Windows users it should be in My Documents I believe.
  • You should see the filename with an ext of .m4a you need to change that to .m4r In Windows world you will need to enable to see file extensions before you will see the m4a.
  • After you renamed the extenstion you just double click it and iTunes will import it into the Ringtones Library instead of the Music Library.
  • Now go back to Get Info of the full song in the Music Library and uncheck the start and stop times.

And that is all to making your own ringtones for your iPhone. Below is a video of the process cause I realize it might be easier to see it than read it.

Now I found this cool site that has some pre-made ringtones. Take look at the site http://iphone.audiko.net/#