Sunday, 27 January 2013

The Android Stack


Do you want to know the secrets of Android Mobile Programming and Development and use it for the advancement of your career in IT? Do you have problems in your thesis or research about Mobile apps or games? Here is an instant solution for your problem. Avail the Android Mobile Programming and Development Training package of Prof Erwin Globio and get free tips about Android Mobile Platform Secrets. 



For more free information about Android and Android Training visit the following sites:
http://erwinglobio.sulit.com.ph/
http://erwinglobio.multiply.com/
 http://erwinglobio.wordpress.com/.
You may contact the Android Trainer at 09393741359 or 09323956678. Call now and be one of the Android Experts

Setting Up a PATH to Tools



The Android SDK has a folder that contains all its major tools. Since we’re going to use
these tools from the command line, it is very helpful to add your ~/android-sdk/tools/
and your ~/android-skd/platform-tools/ directories to your system PATH variable. This
will make it easier to access your tools without having to navigate to their specific
location every single time.
Details for setting up the PATH variable depend on the platform; see step 2 of the docu-
ment “Installing Android SDK”.

Portability of Linux


Portability


Linux is a portable platform that is relatively easy to compile on various hardware
architectures. What Linux brings to Android is a level of hardware abstractions. By
basing Android on Linux, we don’t have to worry too much about underlying hardware
features. Most low-level parts of Linux have been written in fairly portable C code,
which allows for third parties to port Android to a variety of devices.

Graphical User Interface (GUI) Components



Input and output dialog boxes can be used to input data into a program and show the output of a program.  The methods showInputDialog and showMessageDialog found in the class JOptionPane of package javax.swing could be used to perform this task.  These methods however have only displayed one dialog box at a time.  A program that will display all input and output in one dialog box is called a Graphical User Interface (GUI).  With a GUI, a user can see inputs and outputs simultaneously, as well as change input values to recalculate output values.

In a Java GUI, the areas used to get input and show results are called JTextFields.  The labels for these text fields are called JLabels, the buttons that calculate output or close the GUI are called JButtons, and the window containing all these components is called JFrame.

The GUI components are places in an area called the content pane of the window.  When a button in the content pane is clicked an event has occurred. The Java system is very prompt in listening for the events generated by a program and then reacting to those events.

Getting Access to the Content Pane


The class JFrame has the method getContentPane that can be used to access the content pane of the window. However, the class JFrame does not have the necessary tools to manage the components of the content pane. The components of the content pane are managed by declaring a reference variable of the Container type and then using the method getContentPane.  This can be done as follows:

Container pane = getContentPane();

The class Container is in the package java.awt.  Some methods of the class are:

public void add(Object obj)
public void setLayout(Object obj)

The method setLayout is used to set the layout of the content pane. To set the layout of the container to a grid, you use the class GridLayout. Consider the following statement:

pane.setLayout(new GridLayout(5, 2));

This statement creates an object belonging to the class GridLayout and assigns that object as the layout of the content pane, pane, by invoking the setLayout method.

If you do not specify a layout, Java uses a default layout. If you specify a layout, you must set the layout before adding any components.

Teaching Tip

Java provides many layout managers. A tutorial on layout managers for Java can be found at:

The Stack




















This is the 9,000-foot overview of the Android platform. Although you’re concerned
primarily with writing Android applications, understanding the layout of the system
will help shape your understanding about what you can or cannot do easily with
Android.
By the end of this chapter, you’ll understand how the whole system works, at least from
the high level.

Application Distribution


One way in which Android is quite different from other platforms is the distribution
of its apps. On most other platforms, such as iPhone, a single vendor holds a monopoly
over the distribution of applications. On Android, there are many different stores, or
markets. Each market has its own set of policies with respect to what is allowed, how
the revenue is split, and so on. As such, Android is much more of a free market space
in which vendors compete for business.

In practice, the biggest market currently is Android Market, run by Google. It is unclear
whether Google means to just seed the market space while other stores develop or plans
to make it a profitable venture.
Applications can also be distributed via the Web. When you download an APK file
from a website through the browser, the application represented by the APK file is
installed automatically on your phone.
What about viruses, malware, spyware, and other bad things?
With its decentralized application distribution system, it is certainly possible for an
unsuspecting user to download a malicious app that consequently does bad things. For
example, there have been reports of phishing attacks via fake banking apps.
So, Android leaves it to the marketplace to sort it out. Eventually, there will be stores
that are more reputable and those that are less so, at least in theory. Google relies on
user reports for policing its Android Market, but other stores may choose to do more
proactive testing and raise the bar on what gets into the store in the first place.

Do you want to know the secrets of Android Mobile Programming and Development and use it for the advancement of your career in IT? Do you have problems in your thesis or research about Mobile apps or games? Here is an instant solution for your problem. Avail the Android Mobile Programming and Development Training package of Prof Erwin Globio and get free tips about Android Mobile Platform Secrets. For more free information about Android and Android Training visit the following sites: http://erwinglobio.sulit.com.ph/http://erwinglobio.multiply.com/ http://erwinglobio.wordpress.com/. You may contact the Android Trainer at 09393741359 or 09323956678. Call now and be one of the Android Experts

Stack Overview






The Android operating system is like a cake consisting of various layers. Each layer has
its own characteristics and purpose. The layers are not cleanly separated but often seep
into each other.

When you read through this chapter, keep in mind that I am concerned only with the
big picture of the entire system and will get into the nitty-gritty details later on. Figure 2-1 shows the parts of the Android stack.

Android and Java


In Java, you write your Java source file, compile it into a Java byte code using the Java
compiler, and then run this byte code on the Java VM. In Android, things are different.
You still write the Java source file, and you still compile it to Java byte code using the
same Java compiler. But at that point, you recompile it once again using the Dalvik
compiler to Dalvik byte code. It is this Dalvik byte code that is then executed on the
Dalvik VM. Figure 2-2 illustrates this comparison between standard Java (on the left)
in Android using Dalvik (on the right).


It might sound like you have to do a lot more work with Android when
it comes to Java. However, all these compilation steps are automated
by tools such as Eclipse or Ant, and you never notice the additional
steps.

You may wonder, why not compile straight from Java into the Dalvik byte code? There
are a couple of good reasons for the extra steps. Back in 2005, when work on Dalvik
started, the Java language was going through frequent changes, but the Java byte code
was more or less set in stone. So, the Android team chose to base Dalvik on Java byte
code instead of Java source code.
A side effect of this is that in theory you could write Android applications in any other
language that compiles down to Java byte code. For example, you could use Python or
Ruby. I say “in theory” because in practice the appropriate libraries that are part of the
SDK would need to be available. But it is likely that the open source community will
come up with a solution to that in the future.

Another thing to keep in mind is that Android Java is a nonstandard collection of Java
classes. Java typically ships in:

Java Standard Edition
    Used for development on basic desktop-type applications
Java Enterprise Edition (aka J2EE or JavaEE)
    Used for development of enterprise applications
Java Micro Edition (aka J2ME or JavaME)
    Java for mobile applications

Android’s Java set of libraries is closest to Java Standard Edition. The major difference
is that Java user interface libraries (AWT and Swing) have been taken out and replaced
with Android-specific user interface libraries. Android also adds quite a few new fea-
tures to standard Java while supporting most of Java’s standard features. So, you have
most of your favorite Java libraries at your disposal, plus many new ones.

Creating a Window


GUI components such as windows and labels are, in fact, objects. JFrame is a class and the GUI component window can be created by using a JFrame object. Various attributes are associated with a window. For example:

  • Every window has a title.

  • Every window has width and height.

JFrame


The class JFrame provides various methods to control the attributes of a window. The methods provided by the class JFrame are:

public JFrame()
public JFrame(String s)
public void setSize(int w, int h)
public void setTitle(String s)
public void setVisible(Boolean b)
public void setDefaultCloseOperation(int operation)
public void addWindowListener(WindowEvent e)

Teaching Tip

Descriptions of these methods can be found in Table 6-1 in the text.  A more detailed description of JFrame’s methods can be found at:

One way to create a window you can declare an object of the type JFrame, instantiate the object, and then use the various methods listed above to manipulate the window. In this case, the object created can use the various applicable methods of the class.

Another way is to create the class containing the application program by extending the definition of the class JFrame; to build the class containing the application program “on top of” the class JFrame, utilizes the mechanism ofinheritance. Inheritance means that a new class can be derived from or based on an already existing class. 


When using inheritance, the class containing your application program has more than one method. In addition to the method main, it has at least one other method that will be used to create a window object containing the required GUI components (labels, text fields, etc). This additional method is called aconstructor; it is a method of a class that is automatically executed when an object of the class is created. Typically, it is used to initialize an object and its name is always the same as the name of the class.  Because inheritance is an important concept in programming languages such as Java, we the second way of creating a window is described in detail in this chapter. The definition of the class JFrame is extended by using the modifier and reserved word extends

Teaching Tip

Chapter 11 discusses the principles of inheritance in detail. Constructors are covered in detail in Chapter 8.

The class JFrame is contained in the package javax.swing. An important property of inheritance is that the class (subclass) that extends the definition of an existing class—called a superclass—inherits all the properties of the superclass.  The methods setTitle, setSize, setVisible, and setDefaultCloseOperation are methods of the class JFrame, and these methods can be inherited by its subclasses.

A Simplified OOD Methodology


A simplified OOD methodology can be expressed in the following steps:

1.      Write down a detailed description of the problem.

2.      Identify all (relevant) nouns and verbs.

3.      From the list of nouns, select objects. Identify data components of each object.

4.      From the list of verbs, select the operations.

In order to create objects you first need to create classes. To know what type of classes to create, you need to know what an object stores and what operations are needed to manipulate an object’s data.  Because an object consists of data and operations on data in a single unit, in Java we use the mechanism of classes to combine data and its operations in a single unit. In OOD methodology, classes, data members of classes (known as fields), and operations are identified.

Teaching Tip

More information on Object-Oriented Design can be found at:


Implementing Classes and Operations

Once the relevant classes, data members of each class, and relevant operations for each class are identified, the next step is to implement these things in Java. 

In Java, to implement operations we write algorithms. Since there is usually more than one operation on an object, each algorithm is implemented with the help of Java’s methods.  However, Java does not provide all the methods that you will ever need. Therefore, to learn how to design and implement classes, you first must learn how to construct and implement your own methods.

Object-Oriented Design (OOD)


The aim of OOD is to build software from components called classes so that if someone wants to use a class, all they need to know is the various methods provided by that class. 

An object combines data and operations on that data in a single unit, a feature called encapsulation.  In OOD, the object is identified first, then the relevant data is identified, and finally the operations needed to manipulate the object are identified.

The aim of OOD is to build software from components called classes so that if someone wants to use a class, all they need to know is the various methods provided by that class. 

An object combines data and operations on that data in a single unit, a feature called encapsulation.  In OOD, the object is identified first, then the relevant data is identified, and finally the operations needed to manipulate the object are identified.

JButton: Handling an Event


When you click a JButton an event is created, known as an action event, which sends a message to another object, known as an action listener. When the listener receives the message, it performs some action. Sending a message or an event to a listener object simply means that some method in the listener object is invoked with the event as the argument. This invocation happens automatically; you will not see the code corresponding to the method invocation. However, you must specify two things:

  • For each JButton, you must specify the corresponding listener object. In Java, this is known as registering the listener.

  • You must define the methods that will be invoked when the event is sent to the listener. Normally, you will write these methods and you will never write the code for invocation.

Java provides various classes to handle different kinds of events. The action event is handled by the class ActionListener.  The class ActionListener contains the method actionPerformed, which includes the code the system is to execute when an action event is generated.

The class ActionListener that handles the action event is a special type of class called an interface.  An interface contains only the methods headings; each methods heading is terminated with a semicolon.

Because the method actionPerformed does not contain a body, you cannot instantiate an object of the type ActionListener.  One way to register an action listener with an object is to create a class on top of ActionListener so that the required object can be instantiated. The class created must provide the necessary code for the method actionPerformed.  The interface ActionListener is contained in the package java.awt.event.

Teaching Tip

Tutorials regarding how to write various types of listeners, including ActionListeners, can be found at:

JButton


To create a button, Java provides the class JButton and the following methods:

public JButton(Icon ic)
public JButton(String str)
public JButton(String str, Icon ic)
public void setText(String str)
public String getText()
public void setEditable(Boolean b)
public void addActionListener(ActionListener obj)

The add method can then be used to add buttons to the content pane.

Teaching Tip

Components such as JButton, JTextField, and JLabel are part of Java’s Swing framework.  A tutorial on creating GUI interfaces with Swing can be found at:

JTextField


Text fields are objects belonging to the class JTextField. Therefore, you can create a text field by declaring a reference variable of the type JTextField followed by an instantiation of the object.  Some methods of the class JTextField are:

public JTextField(int columns)
public JTextField(String str)
public JTextField(String str, int columns)
public void setLayout(String str)
public String getText()
public void setEditable(Boolean b)
public void addActionListener(ActionListener obj)

JLabel



To create labels, you instantiate objects of the type JLabel. The class JLabel is also contained in the package javax.swing. There are various attributes associated with a label. Every label has a title, width, and a height. The class JLabel contains various methods to control the display of labels.  Some of the constructors for JLabels are:

public JLabel(String str)
public JLabel(String str, int align)
public JLabel(String t, Icon icon, int align)
public JLabel(Icon icon)

Labels are then added to the content pane using the add method.

Hello World in J2ME : From Development to Deployment


Scope of Article
This article is intended for J2ME beginners and steps through every process of developing a MIDP compatible MIDlet. It is assumed that the reader has sufficient knowledge of general Java development using J2SE.




Java’s Original Promise
In the beginning Java was intended as a programming language that would power devices ranging from toasters to servers. This did not happen at first, but nearly a decade later Java found its way onto the mobile phones of millions of people and proved for the most part its ability to allow developers to “Write Once Run Anywhere”.
With this solid footing Java continues attempting to make inroads into other problem domains.

Drawing Hello World :: The Rendering Process (in plain English)


Below are the steps required to draw “Hello World” on screen.
1. Set the current color to black
2. Fill the entire screen (using the current color)
3. Set the current color to white
4. Print “Hello World!” (using the current color and font)
So that Hello World’s font’s color is different from that of the screen we explicitly set both prior to filling the screen and printing our text. 

The structure of a Completed MIDlet: The JAD file


The JAD file


A JAD file is a lightweight proprties file in the which is offered to the target device prior to commiting to the full JAR download. It informs the device of the size of the MIDlet and any expectations and requirements it has of the device.
As the JAR files size must be mentioned and since it always changes during development it is advised to use JammedUp to automate this process with each build.
HelloWorld.jadMIDlet-Name: HelloWorld
MIDlet-Version: 1.0
MIDlet-Vendor: VENDOR-NAME-HERE
MIDlet-Jar-URL: HelloWorld.jar
MIDlet-Jar-Size: 1523
MIDlet-1: HelloWorld,,HelloWorld
MicroEdition-Profile: MIDP-2.0
MicroEdition-Configuration: CLDC-1.1
MIDlet-Data-Size: 0
build: 1
Last-Modified: 2007-04-09 08:17:25

The structure of a Completed MIDlet: The Manifest



The Manifest


All MIDP compatible MIDlets must include a MANIFEST.MF file residing in the META-INF directory of the JAR file. This file reasserts some of the basic settings found in the JAD file for validation purposes and is provided in the properties file format.
MANIFEST.MF
MIDlet-Name: HelloWorld
MIDlet-Version: 1.0
MIDlet-Vendor: VENDOR-NAME-HERE
MicroEdition-Profile: MIDP-2.0
MicroEdition-Configuration: CLDC-1.1
MIDlet-1: HelloWorld,,HelloWorld
At this point you don’t need to worry too much about the contents of the JAD and manifest files. I’ll be devoting an article to their maintenance in the near future. For the purposes of this article you need only know that they are essential files for running any MIDlet.

Saturday, 26 January 2013

Java Core Training

Do you want to know the secrets of Java Programming and use it for the advancement of your career in IT? Do you have problems in your Java course? Here is an instant solution for your problem. Avail the Java training package of Prof Erwin Globio and get free tips about JavaProgramming Secrets. 


For more free information about Java and Java Training visit the following sites: http://erwinglobio.sulit.com.ph/ http://erwinglobio.multiply.com/http://erwinglobio.wordpress.com/. You may contact the Java Trainer at 09393741359 or 09323956678. Call now and be one of the Java Experts.

Computer Program


A computer program, or a program, is a sequence of statements whose objective is to accomplish a task. Programming is a process of planning and creating a program.  Learning a programming language requires direct interaction with the tools. You must have a fundamental knowledge of the language, and you must test your programs on the computer to make sure that each program does what it is supposed to do.