Wednesday, February 26, 2014

Features of Android



Features of Android

  • Beautiful UI


Android OS basic screen provides a beautiful and intuitive user interface.

  • Connectivity


GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC and WiMAX.

  • Storage


SQLite, a lightweight relational database, is used for data storage purposes.

  • Media support


H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP

  • Messaging


SMS and MMS

  • Web browser


Based on the open-source WebKit layout engine, coupled with Chrome's V8 JavaScript engine supporting HTML5 and CSS3.

  • Multi-touch


Android has native support for multi-touch which was initially made available in handsets such as the HTC Hero.

  • Multi-tasking


User can jump from one task to another and same time various application can run simultaneously.

  • Resizable widgets


Widgets are resizable, so users can expand them to show more content or shrink them to save space

  • Multi-Language


Supports single direction and bi-directional text.

  • GCM


Google Cloud Messaging (GCM) is a service that lets developers send short message data to their users on Android devices, without needing a proprietary sync solution.

  • Wi-Fi Direct


A technology that lets apps discover and pair directly, over a high-bandwidth peer-to-peer connection.

  • Android Beam


A popular NFC-based technology that lets users instantly share, just by touching two NFC-enabled phones together.


Inheritance in Java

Inheritance in Java

The idea behind inheritance is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you reuse (or inherit) methods and fields, and you add new methods and fields to adapt your new class.

// A simple example of inheritance.
// Create a superclass.
class A {
int i, j;
void showij() {
System.out.println("i and j: " + i + " " + j);
}
}
// Create a subclass by extending class A.
class B extends A {
int k;
void showk() {
System.out.println("k: " + k);
}
void sum() {
System.out.println("i+j+k: " + (i+j+k));
}
}
class SimpleInheritance {
public static void main(String args[]) {
A superOb = new A();
B subOb = new B();
// The superclass may be used by itself.
superOb.i = 10;
superOb.j = 20;
System.out.println("Contents of superOb: ");
superOb.showij();
System.out.println();
/* The subclass has access to all public members of
its superclass. */
subOb.i = 7;
subOb.j = 8;
subOb.k = 9;
System.out.println("Contents of subOb: ");
subOb.showij();
subOb.showk();
System.out.println();
System.out.println("Sum of i, j and k in subOb:");
subOb.sum();
}

}

Tuesday, February 25, 2014

Java Classes

Java Classes

A class is declared by use of the class keyword. A simplified general form of a class definition is shown here:

Syntax
class classname {
type instance-variable1;
type instance-variable2;
// ...
type instance-variableN;
type methodname1(parameter-list) {
// body of method
}
type methodname2(parameter-list) {
// body of method
}
// ...
type methodnameN(parameter-list) {
// body of method
}
}

A Simple Class
class Box {
double width;
double height;
double depth;
}
// This class declares an object of type Box.
class BoxDemo {
public static void main(String args[]) {
Box mybox = new Box();
double vol;
// assign values to mybox's instance variables
mybox.width = 10;
mybox.height = 20;
mybox.depth = 15;
// compute volume of box
vol = mybox.width * mybox.height * mybox.depth;
System.out.println("Volume is " + vol);
}
}

Java Variables

Java Variables

Variables

The variable is the basic unit of storage in a Java program. A variable is defined by the combination of an identifier, a type, and an optional initializer. In addition, all variables have a scope, which defines their visibility, and a lifetime.

Declaring a Variable In Java 

All variables must be declared before they can be used. The basic form of a variable declaration is shown here:

Syntax

type identifier [ = value];


Sample Code 1

class Example1
{
public static void main(String args[])
{
int a = 10;
System.out.println("Value of variable is: " + a);
}
}

Sample Code 2

class Example2
{
public static void main(String args[])
{
int a, b, sum;
a = 7;
b = 5;
sum = a + b;
System.out.println("Addition of variable is: " + sum);
}
}

Java Data Types

Java Data Types

Java defines eight types of data: byte, short, int, long, char, float, double, and boolean.
These data types can be put in four groups:
  • Integers This group includes byte, short, int, and long, which are for whole-valued signed numbers.
  • Floating-point numbers This group includes float and double, which represent numbers with fractional precision.
  • Characters This group includes char, which represents symbols in a character set, like letters and numbers.
  • Boolean This group includes boolean, which is a special type for representing true/false values

Integer








 Floating-Point Types 

 

 

 

 Characters

In Java, the data type used to store characters is char. However, C/C++ programmers beware:

char in Java is not the same as char in C or C++. In C/C++, char is 8 bits wide. This is not the
case in Java, it requires 16 bits. Thus, in Java char is a 16-bit type. The range of a char is 0 to 65,536. There are no negative chars.
  

Booleans

 Java has a primitive type, called boolean, for logical values. It can have only one of two possible values, true or false. This is the type returned by all relational operators, as in the case of a < b. boolean is also the type required by the conditional expressions that govern the control statements such as if and for.

Java Identifiers

Java Identifiers

Legal identifiers must be composed of only Unicode characters, numbers, currency symbols, and connecting characters (like underscores).
  • Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
  • After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
  • In practice, there is no limit to the number of characters an identifier can contain.
  • Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.
Examples some legal identifiers:
int _a;
int $c;
int ______2_w;
int _$;
int this_is_a_very_detailed_name_for_an_identifier;
The following are illegal identifiers
int :b;
int -d;
int e#;
int .f;
int 7g;

Java Code Conventions


Java Code Conventions

Sun has created a set of coding standards for Java, and published those standards in a document titled "Java Code Conventions".
  • Classes and interfaces:

The first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase (a format is called as "camelCase").
For example:
Dog (Class)
Account
(Class)
PrintWriter (Class)
Runnable (interface)
Serializable
(interface)

  • Methods

 The first letter should be lowercase, and then normal camelCase rules should be used.
 For example:
getBalance
doCalculation
setCustomerName

  • Variables

 Like methods, the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names.
For example:
buttonWidth
accountBalance
myString

  • Constants

 Java constants are created by marking variables static and final. They should be named using uppercase letters with underscore characters as separators.
For example:
MIN_HEIGHT
MAX_HEIGHT

Complete List of Java Keywords


Complete List of Java Keywords 

There are 50 keywords in Java 6, which reserved by the Java.
(assert added in 1.4, enum added in 1.5)
 
abstract
boolean
break
byte
case
catch
char
class
const
continue
default
do
double
else
extends
final
finally
float
for
goto
if
implements
import
instanceof
int
interface
long
native
new
package
private
protected
public
return
short
static
strictfp
super
switch
synchronized
this
throw
throws
transient
try
void
volatile
while
assert
enum