Saturday, October 26, 2013

Android Tutorial

android-logo
Android, an open source operating system for mobile devices (Smartphone and tablet), led by Google. The Android SDK provides a set of tools and APIs to develop Android applications, using Java. So, if you know Java, Android programming is easy :)
In this series of tutorials, we show you the list of basic tutorials to get you start program Android easily.
Note
All Android tutorials are developed in Eclipse 3.7, and tested with Android 2.3.3.
P.S This is just the initial version of Android tutorials, will keep publishing more in future.

1. Quick Start

Get you start in Android programming.

2. Fundamentals

Some Android basic stuffs.

3. User Interface Controls

Play with Android UI controls.

4. Layouts

Play with Android layout controls.

5. FAQs

Some common asked questions in Android.

Java - Library Classes

Java - Library Classes

This tutorial would cover package java.lang, which provides classes that are fundamental to the design of the Java programming language. The most important classes are Object, which is the root of the class hierarchy, and Class, instances of which represent classes at run time.
Here is the list of classes of package java.lang. These classes are very important to know for a Java programmer. Click a class link to know more detail about that class. For a further drill, you can refer standard Java documentation.
SNMethods with Description
1Boolean
Boolean
2Byte
The Byte class wraps a value of primitive type byte in an object.
3Character
The Character class wraps a value of the primitive type char in an object.
4Class
Instances of the class Class represent classes and interfaces in a running Java application.
5ClassLoader
A class loader is an object that is responsible for loading classes.
6Compiler
The Compiler class is provided to support Java-to-native-code compilers and related services.
7Double
The Double class wraps a value of the primitive type double in an object.
8Float
The Float class wraps a value of primitive type float in an object.
9Integer
The Integer class wraps a value of the primitive type int in an object.
10Long
The Long class wraps a value of the primitive type long in an object.
11Math
The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
12Number
The abstract class Number is the superclass of classes BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short.
13Object
Class Object is the root of the class hierarchy.
14Package
Package objects contain version information about the implementation and specification of a Java package.
15Process
The Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it.
16Runtime
Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running.
17RuntimePermission
This class is for runtime permissions.
18SecurityManager
The security manager is a class that allows applications to implement a security policy.
19Short
The Short class wraps a value of primitive type short in an object.
20StackTraceElement
An element in a stack trace, as returned by Throwable.getStackTrace().
21StrictMath
The class StrictMath contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
22String
The String class represents character strings.
23StringBuffer
A string buffer implements a mutable sequence of characters.
24System
The System class contains several useful class fields and methods.
25Thread
A thread is a thread of execution in a program.
26ThreadGroup
A thread group represents a set of threads.
27ThreadLocal
This class provides thread-local variables.
28Throwable
The Throwable class is the superclass of all errors and exceptions in the Java language.
29Void
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.

Java Documentation Comments

Java Documentation Comments

Java supports three types of comments. The first two are the // and the /* */. The third type is called a documentation comment. It begins with the character sequence /** and it ends with */.
Documentation comments allow you to embed information about your program into the program itself. You can then use the javadoc utility program to extract the information and put it into an HTML file.
Documentation comments make it convenient to document your programs.

The javadoc Tags:

The javadoc utility recognizes the following tags:
TagDescriptionExample
@authorIdentifies the author of a class.@author description
@deprecatedSpecifies that a class or member is deprecated.@deprecated description
{@docRoot}Specifies the path to the root directory of the current documentationDirectory Path
@exceptionIdentifies an exception thrown by a method.@exception exception-name explanation
{@inheritDoc}Inherits a comment from the immediate superclass.Inherits a comment from the immediate surperclass.
{@link}Inserts an in-line link to another topic.{@link name text}
{@linkplain}Inserts an in-line link to another topic, but the link is displayed in a plain-text font.Inserts an in-line link to another topic.
@paramDocuments a method's parameter.@param parameter-name explanation
@returnDocuments a method's return value.@return explanation
@seeSpecifies a link to another topic.@see anchor
@serialDocuments a default serializable field.@serial description
@serialDataDocuments the data written by the writeObject( ) or writeExternal( ) methods@serialData description
@serialFieldDocuments an ObjectStreamField component.@serialField name type description
@sinceStates the release when a specific change was introduced.@since release
@throwsSame as @exception.The @throws tag has the same meaning as the @exception tag.
{@value}Displays the value of a constant, which must be a static field.Displays the value of a constant, which must be a static field.
@versionSpecifies the version of a class.@version info

Documentation Comment:

After the beginning /**, the first line or lines become the main description of your class, variable, or method.
After that, you can include one or more of the various @ tags. Each @ tag must start at the beginning of a new line or follow an asterisk (*) that is at the start of a line.
Multiple tags of the same type should be grouped together. For example, if you have three @see tags, put them one after the other.
Here is an example of a documentation comment for a class:
/**
* This class draws a bar chart.
* @author Zara Ali
* @version 1.2
*/

What javadoc Outputs?

The javadoc program takes as input your Java program's source file and outputs several HTML files that contain the program's documentation.
Information about each class will be in its own HTML file. Java utility javadoc will also output an index and a hierarchy tree. Other HTML files can be generated.
Since different implementations of javadoc may work differently, you will need to check the instructions that accompany your Java development system for details specific to your version.

Example:

Following is a sample program that uses documentation comments. Notice the way each comment immediately precedes the item that it describes.
After being processed by javadoc, the documentation about the SquareNum class will be found in SquareNum.html.
import java.io.*;

/**
* This class demonstrates documentation comments.
* @author Ayan Amhed 
* @version 1.2
*/
public class SquareNum {
   /**
   * This method returns the square of num.
   * This is a multiline description. You can use
   * as many lines as you like.
   * @param num The value to be squared.
   * @return num squared.
   */
   public double square(double num) {
      return num * num;
   }
   /**
   * This method inputs a number from the user.
   * @return The value input as a double.
   * @exception IOException On input error.
   * @see IOException
   */
   public double getNumber() throws IOException {
      InputStreamReader isr = new InputStreamReader(System.in);
      BufferedReader inData = new BufferedReader(isr);
      String str;
      str = inData.readLine();
      return (new Double(str)).doubleValue();
   }
   /**
   * This method demonstrates square().
   * @param args Unused.
   * @return Nothing.
   * @exception IOException On input error.
   * @see IOException
   */
   public static void main(String args[]) throws IOException
   {
      SquareNum ob = new SquareNum();
      double val;
      System.out.println("Enter value to be squared: ");
      val = ob.getNumber();
      val = ob.square(val);
      System.out.println("Squared value is " + val);
   }
}
Now, process above SquareNum.java file using javadoc utility as follows:
$ javadoc SquareNum.java
Loading source file SquareNum.java...
Constructing Javadoc information...
Standard Doclet version 1.5.0_13
Building tree for all the packages and classes...
Generating SquareNum.html...
SquareNum.java:39: warning - @return tag cannot be used\
                      in method with void return type.
Generating package-frame.html...
Generating package-summary.html...
Generating package-tree.html...
Generating constant-values.html...
Building index for all the packages and classes...
Generating overview-tree.html...
Generating index-all.html...
Generating deprecated-list.html...
Building index for all classes...
Generating allclasses-frame.html...
Generating allclasses-noframe.html...
Generating index.html...
Generating help-doc.html...
Generating stylesheet.css...
1 warning
$
You can check all the generated documentation here: SquareNum.