Wednesday, 30 September 2015

Starting Another Activity


To start an activity from one activity we need Intent object and startActivity() method.

Intent:
  • An Intent provides a facility for performing late runtime binding between the code in different applications
  • Its most significant use is in the launching of activities, where it can be thought of as the glue between activities
  • It is basically a passive data structure holding an abstract description of an action to be performed.


Example :

Intent intent = new Intent(FirstActivity.this,SecondActivity.class);

startActivity() ­ Method:

Launch a new activity:

Parameter

  Intent         The description of the activity to start.

This method throws ActivityNotFoundException if there was no Activity found to run the given Intent

Example :

Intent intent = new Intent (FirstActivity.this,SecondActivity.class);
startActivity(intent);


Finish() ­ Method:

Call this when your activity is done and should be closed.
  • If this method called from oncreate method then onDestroy method called immediately.
  • If this method called from onStart method then onStop wil be called and then it will go to onDestroy.



Tuesday, 29 September 2015

Introduction to android

Introduction to android
  •     Android provides a rich application framework that allows you to build    innovative apps and games for mobile devices in a Java language environment.
  •     One of the most widely used mobile OS these days is ANDROID.
  •     Android is a software bunch comprising not only operating system but also middleware and key applications.
  •     Android Inc was founded in Palo Alto of California, U.S. by Andy Rubin in 2003.
  •     Later Android Inc. was acquired by Google in 2005.
What is Android?
    It most commonly comes installed on a variety of smartphones and tablets from a host of manufacturers  offering users access to Google’s own services like Search, YouTube, Maps, Gmail and more.
What can an Android phone do?


    Android phones are highly customisable and as such can be altered to suit your tastes and needs with wallpapers, themes and launchers which completely change the look of your device's interface.


    You can download applications to do all sorts of things like check your Facebook and Twitter feeds, manage your bank account, order pizza and play games. You can plan events on from your phone's calendar and see them on your computer or browse websites on your desktop and pick them up on your phone.


What apps can I get on an Android phone?

  •     There are hundreds of thousands of apps and games available to download from the Google Play store (formerly the Android Market).
  •     There are camera apps that allow you to take pictures with artistic effects and filters on them and music players which allow you to stream music from the web or create playlists.
  •     You can customise the appearance of your Android handset with a number of wallpapers based on pictures you’ve taken yourself or downloaded from the internet too.

Android Updates

  •     Google is constantly working on new versions of the Android software. These releases are infrequent; at the moment they normally come out every six months or so, but Google is looking to slow this down to once a year.
  •     Versions usually come with a numerical code and a name that’s so far been themed after sweets and desserts, running in alphabetical order.
    Android 1.5 Cupcake - APR 2009

    Android 1.6 Donut - SEP 2009


    Android 2.1 Eclair - OCT 2009


    Android 2.2 Froyo - MAY 2010


    Android 2.3 Gingerbread - DEC 2010


    Android 3.2 Honeycomb - MAY 2011 - The first OS design specifically for a tablets, launching on the Motorola Xoom


    Android 4.0 Ice Cream Sandwich- OCT 2011 - The first OS to run on      smartphones and tablets, ending the 2.X naming convention


   Android 4.1 Jelly Bean- DEC 2011 - Launched on the Google Nexus 7 tablet by Asus

    Android 4.2 Jelly Bean: Arrived on the LG Nexus 4


    Android 4.3 Jelly Bean


    Android 4.4 KitKat  - OCT 2013 - Launched on the LG Nexus 5


    Android 5.0 Lollipop - NOV 2014 -  Launched on the Motorola Nexus 6 and HTC Nexus 9\


    Android 6.0 Marshmallow - AUG 2015 - DEV PREVIEW


Monday, 28 September 2015

JVM

Java Virtual Machine

History

Basics

Data Types

JVM Runtimes


History:

  •     Java platform was initially developed to address the problem of building s/w for n/w consumer devices.
  •     To meet requirements , compiled code has to transport across the networks ,works on any client and assure that the client that it was safe to run.
  •     WWW got popularized , but web HTML format was too limited . So the answer is extensibility in the way of HOTJAVA BROWSER.


  •     Hot Java Browser implements the java language and platform embedded into HTML webpages.Like HTML pages , compiled programs are n/w and host independent. The programs works the same way regardless of what machine they run on and where they come from.   

Basics-JVM:

  •     Cornerstone of the Java platform.
  •     is an abstract computing machine . It has its own instruction set and manipulates memory at runtime.
  •     Component of technology responsible for its h/w and os independence , a small class file of compiled code and ability to protect users from malicious programs
  •     Knows nothing of Java programming language only a binary format ie.., class file format. Class file format consists of
    JVM instructions (Byte code )

    Symbol table (key - value pair)

    Ancillary informations(Support info)

  •     Class file format is H/w and Os independent binary format   

Data Types:        

  •     VM operates on 2 kinds of Data Types
     1.Primitive types 2. Reference Types (class types , array types & interface types).
  •     These are the values actually that can be stored in a variable , passed as an argument and a value returned by methods.
  •     Jvm expects all type checking is done prior to the runtime , typically by a compiler .
  •     Explicit support for objects. An object is either dynamically allocated class instance or an array.
  •      reference to an object is considered to have a JVM reference types.
  •     Values of type references can be thought of as a pointer to objects. More than one pointers for an object can exist. Objects are operated via type references.

JVM Runime Areas:




 


PC Register:

  •     Each Jvm Thread has its own PC register
  •     Contains current executing method    
  •     Pc register holds any one of the follwing values
                   if method is not native , PC holds address of JVM instruction

                     if method is native , PC hold either undefined or return addresses(pointer to OPCODES of jvm)

JVM Stacks:

  •     Per thread
  •     Stores frames(data , partial results , dynamic linking,return method values , dispatch exceptions)
  •     Contains local variables , partial results and plays part in method invocation and return  

Heap:

  •     Common for all java threads
  •     Memory for all class instances and arrays are allocated
  •     Created on JVM startup
  •     Heap storage for objects is reclaimed by automatic management system(gc) , objects are never explicitly deallocated
  •     If your computation requires more memory than heap , then OUTOFMEMORYERROR

Method Area:

  •     Common to all Threads
  •     Contains per-class structures , runtime constant pool , field , method data , code for constructors & methods , instances and interface initialization
  •     Logically is a part of heap
  •     VM doesnot mandate location of method area or policies used to manage compiled code  

Run Time Constant Pool:

  •     Per Class/per Interface representation in .Class file
  •     Contains constants , ranging from numeric literals known at compile time to method/fields resolved at runtime
  •     Simillar to symbol table
  •     Allocated from the method area
  •     Pool for class/interface is constructed when class/interface is created by JVM

Native Method Stacks:

  •     Thread based not JVM based
  •     Stacks which assists in interpreting the language other than Java
  •     JVM cannot load native method stacks

                                                        


   





   





   

   

   

    







   

       

        

   





   

   

Introduction to Java

Introduction to Java Programming

Java is a powerful object-oriented programming language introduced by Sun Micro systems in 1995, which has built-in support to create programs with a graphical user interface (GUI), utilize the Internet, create client-server solutions, and much more. Programs written in Java can run, without change, on any of the common computer operating systems Windows 95/NT, Macintosh, and Unix. A variant of Java programs called applets can be embedded inside a web page and execute on the computer that is viewing the page, automatically and in a secure environment.

As a language, Java is closely related to C++, which is also object-oriented but retains a lot of idiosyncrasies inherited from its predecessor language C. Java has removed the inconsistent elements from C++, is exclusively object-oriented, and can be considered a modern version of C++ Because of its logical structure Java has quickly become a popular choice as a teaching language, and because of its extensive Internet support and the promise of writing programs once and using them on every operating system Java is becoming more and more accepted in industry.


Basic Java Programming Guidelines

Every Java program must follow these guidelines:

    Java is case sensitive, i.e. the word Program is different from program.
    Curly brackets { and } are used to group statements together.
    An executable Java program must contain at least the following lines as a framework:

    package com.sample;

    public class MainClass {

    public static void main(String args[]){

     }

    }


           Every statement whose next statement is not a separate group must end in a semicolon.
    A Java program containing the above framework must be saved using the file name MainClass.java, where MainClass (including correct upper and lower cases) is the word that follows the keywords public class and the file extension is .java.



Source Code

A Java source code file is a text file that contains programming code written according to the Java language specifications, resembling a mixture of mathematical language and English. A computer cannot execute source code, but humans can read and understand it.

Java source code files should be saved as Name.java, where Name is the name that appears in the first line of the program: public class Name. That Name is referred to as the name of the class, or program. By convention its first letter is capitalized.


      package com.sample;

      public class Test {

           public static void main(String args[]) {

           System.out.println("Hi this is my first program");
       
    }

}

Output:

Hi this is my first program


This program, or class, is called Test and must be saved under the file name Test.java.


Compiling a Java Program or Class

A source code file, which is more or less readable in plain English, needs to be transformed into another format before the computer can act upon it. That translation process is called compiling and is accomplished using the Java compiler javac from the Java Developer's Kit (JDK), which could be invoked by an IDE such as BlueJ.

Definition For Compiling

Compiling is the process of transforming the source code file into a format that the computer can understand and process. The resulting file is called the byte-code, or class, file. The name of the class file is the same as the name of the program plus the extension .class. The program javac from the Java Developer's Kit is used to transform a source code file into a class file.

If a source code contains any errors, they are flagged by the compiler. You need to fix them and re-compile until there are no further errors.

Tip: In case of an error, the javac compiler shows the line number and position of where it thinks the error occurred in your source code.

    If the compiler points out an error, then there is an error at or before the indicated position.
    If the compiler reports a certain number of errors, than this is the least amount of errors.
    If one error is fixed, other errors may automatically disappear or new ones may appear.


Executing a Java Program or Class

The Java compiler does not produce an executable file, so Java programs can not execute under the operating system of your machine. Instead they execute inside a Java Virtual Machine, which is invoked using the java program of the JDK.

Definition For Executing a Class File

To execute a Java program the Java Developer's Kit provides a program called java. When executing that program with your class file as parameter the following happens:

    the Java Virtual Machine (JVM) is created inside your computer
    the JVM locates and reads your class files
    the JVM inspects your class file for any security violations
    the JVM executes, or interprets, your class file according to its instructions if possible


Default Program Entry Point

The default program entry point is that part of a class (or program) where execution begins. For every Java class (or program), the standard program entry point consists of the line:

   public static void main(String args[])


If that line is not present in your source code, the JVM can not execute your program and displays an error message.

At this point, we need to explain what the Java Virtual Machine is and how it relates to the operating system and to Java class files.


Java Virtual Machine (JVM)

The Java Virtual Machine (JVM) is a platform-independent engine used to run Java applets and applications. The JVM knows nothing of the Java programming language, but it does understand the particular file format of the platform and implementation independent class file produced by a Java compiler. Therefore, class files produced by a Java compiler on one system can execute without change on any system that can invoke a Java Virtual Machine.

When invoked with a particular class file, the JVM loads the file, goes through a verification process to ensure system security, and executes the instructions in that class file.