Thursday, July 24, 2014

Including Java Documentation in Eclipse projects


1- Create an Eclipse project
1-a. On "File" menu of Eclipse menu bar, select "New" menu item, and then select "Other...".
1-b. In the "New" window, open the "Java" folder from the list, and select "Java Project" within it. Click on "Next" button.
1-c. In the "New Java Project" window fill the "Project name" text field, e.g. "UtilityLibrary", and click on "Finish".
1-d. In the "Package Explorer", right click on the project name, select "New" and then, "Package".
1-e. In the "New Java Packge" window fill the "Name" text box, e.g. "domain.app.libraries.utilities". Click on "Finish" button.
1-f. In the "Package Explorer", right click on the package name, select "New" and then, "Class".
1-g. In the "New Java Class" window fill the "Name" text box, e.g. "Utility". Select "Generate comments" check box. Click on "Finish" button.
1-h. In the "Utility.java" file complete the following code:
/**
 * Utility.java
 *  Author name 24/7/2014
 */
package domain.app.libraries.utilities;
/**
 * Utility class.
 * @author Author name
 */
public class Utility {
/**
* This method return a customized phrase.
* @param name The name.
* @return Customized phrase.
*/
public static String getPhrase(String name) {
return "Welcome back, " + name + "!";
}
}
2- Generate Javadoc and export the  project
2-a. From "Project" menu, select "Generate Javadoc...".
2-b. In the "Generate Javadoc" window, accept the default options by clicking "Finish". (A "doc" folder is generated in the project, with the Java documentation of this library.)
2-c. In the "Package Explorer", right click on the project name, select "Export...".
2-d. In the "Export" window, open "Java" folder from the list, select "JAR file" and click "Next" button.
2-e. In the "JAR Export" window, fill the "JAR file" text box with the appropiate path, e.g. "\home\username\Development\lib\utilitylibrary.jar", and click "Finish".

3- Library usage
3-a. On "File" menu of Eclipse menu bar, select "New" menu item, and then select "Other...".
3-b. In the "New" window, open the "Java" folder from the list, and select "Java Project" within it. Click on "Next" button.
3-c. In the "New Java Project" window fill the "Project name" text field, e.g. "Program", and click on "Finish".
3-d. In the "Package Explorer", right click on the project name, select "New" and then, "Package".
3-e. In the "New Java Packge" window fill the "Name" text box, e.g. "domain.app.console.program". Click on "Finish" button.
3-f. In the "Package Explorer", right click on the package name, select "New" and then, "Class".
3-g. In the "New Java Class" window fill the "Name" text box, e.g. "Program". Select "public static void main(String[] args)" and "Generate comments" check boxes. Click on "Finish" button.
3-h. In the "Package Explorer", right click on the project name, select "Build Path" and then, "Configure Build Path...".
3-i. In the "Properties for Program" window, select "Libraries" tab and click on "Add External JARs" button.
3-j. In the "JAR Selection" window, browse to the location where you saved the JAR file in step 2.e ("\home\username\Development\lib\") and select it ("utilitylibrary.jar").
3-k. Open the newly added JAR file from the list, select "Javadoc location: (None)" and click on the "Edit..." button.
3-l. In the "Javadoc For 'utilitylibrary.jar'" window select "Javadoc in archive" and "External file" and fill the "Archive path" text field with the JAR file's location ("\home\username\Development\lib\utilitylibrary.jar"). Also, fill the "Path within archive" text box with "doc". Then, click "OK" button.
3-m. Click "OK" button in the "Properties for Program" window.
3-n. Now, you can write code in the "Program" class with the help of the Javadoc generated in "UtilityLibrary" project. Complete the following code in the "Program" class of the "Program" project:
(Please, observe the help as you write the code.)
/**
 * Program.java
 *  Adrián E. Córdoba 24/7/2014
 */
package domain.app.console.program;
import domain.app.libraries.utilities.Utility;
/**
 * Main class that use a JAR file as library.
 * @author Adrián E. Córdoba
 */
public class Program {
/**
* Main method that prints a statement obtained from the Utility class library.
* @param args Not used.
*/
public static void main(String[] args) {
String phrase = Utility.getPhrase("Adrián Córdoba");
System.out.println(phrase);
}
}

Monday, July 21, 2014

Eclipse installation on Linux platforms


1. Download the appropiate Eclipse IDE for Java EE Developers version for your architecture (32 or 64 bits) from http://www.eclipse.org/downloads/.
     For this explanation, I suppose the file is downloaded to "Downloads" directory of the "username" home directory ("/home/username/Downloads/").
2. As a root user, extract the archived files from downloaded file in step 1.
 $ su
Password: <Type the root password>
# cd /usr/local/
# mv /home/username/Downloads/eclipse-jee-luna-R-linux-gtk-<version>.tar.gz .
# tar -zxvf eclipse-jee-luna-R-linux-gtk-<version>.tar.gz
     In this step, Eclipse Luna was installed on "/usr/local/" directory. Now you can remove the downloaded file:
# rm eclipse-jee-luna-R-linux-gtk-<version>.tar.gz
3. In order to run Eclipse from the graphic interface, create a link to Eclipse in your desktop. As normal user, enter in a terminal:
$ cd /home/username/Desktop
$ ln -s /usr/local/eclipse/eclipse Eclipse



Android SDK installation on Linux platforms

1- Installing Android SDK

1-a. Download the stand-alone Android SDK tools from http://developer.android.com/sdk/index.html#download, by clicking on "GET THE SDK FOR AN EXISTING IDE" and accepting the terms and conditions of Android.
1-b. Unpack ".tgz" file in the desired location, as normal user.
$ mkdir /home/username/Development
$ cd /home/username/Development
$ mv /home/username/Downloads/android-sdk_<version>-linux.tgz .
$ tar -zxvf android-sdk_<version>-linux.tgz
     Android SDK files have been unpacked in a "android-sdk-linux_x86" directory. Now, you can remove the downloaded file:
$ rm android-sdk_<version>-linux.tgz

2- Getting the latest Android SDK tools

2-a. Start the Android SDK Manager.
$ cd /home/username/Development/android-sdk-linux_x86/tools/
$ ./android
2-b. In the Android SDK Manager window, select the latest SDK tools:
     In Tools directory select: - Android SDK Tools
                                           - Android SDK Paltform-tools
                                           - Android SDK Build-tools (the highest version)
     In Android first directory (latest version) select: - SDK Platform
                                                                            - ARM EABI v7a System Image
     In Extras directory select: - Android Support Repository
                                            - Android Support Library
                                            - Google Repository
                                            - Google Play services
2-c. Click "Install 7 packages".
2-d. In the next window, accept the license agreement for each package, and click "Install".

Saturday, July 19, 2014

Successful installation of Java Development Kit on Linux platforms

This procedure install Java SE Development Kit in openSUSE Linux, but it can be applied for any other Linux distribution. (Please, consult your distribution documentation.)

1. Download the Java SE Development Kit from http://www.oracle.com/technetwork/java/javase/downloads/index.html. Select the tarball (".tar.gz" file extension) for the appropiate architecture (32 or 64 bits).
     For this explanation, I suppose the file is downloaded to "Downloads" directory of the "username" home directory ("/home/username/Downloads/").

2. As a root user, move the downloaded file to the installation directory and unpack the tarball.
$ su
Password: <Type the root password>
# mkdir /usr/java/
# cd /usr/java/
# mv /home/username/Downloads/jdk-<version>-linux-<arch>.tar.gz .
# tar -zxvf jdk-<version>-linux-<arch>.tar.gz
     In this step, Java was unpacked on "/usr/java/" directory. Now, you can remove the downloaded file:
# rm jdk-<version>-linux-<arch>.tar.gz
3. Create a symbolic link to the JDK installation directory.
# ln -s /usr/java/jdk<version> default
4. Set the "JAVA_HOME" environment variable.
# cd /etc/profile.d/
# cat >> java.sh
export JAVA_HOME=/usr/java/default
<CTRL + C>
#
5. Set the JDK tools in "PATH" environment variable.
# cd /etc/
# cat >> bash.bashrc.local
PATH=$JAVA_HOME/bin:$PATH
export PATH
<CTRL + C>
#