Pages

Android application tutorials


This example shows how create ImageGallery in android.

Algorithm:

1.) Create a new project by File-> New -> Android Project name it ImageGalleryExample.
2.) Add some sample .png image files to res/drawables folder.

3.) Write following into main.xml file:

Hello world first Android application

Following is a step by step guide in creating your first "Hello World" Android application.It was created with the following setup:

  • Windows (I happen to be using Windows 7, but any flavor of windows will do)
  • Eclipse IDE for Java Developers (v3.5 Galileo)
  • Java Platform (JDK 6 Update 18)
  • Android SDK Tools, Revision 4
Let's get started...

Getting started with Android A step by step installation guide

Step 1:Preparing Your Development Computer

  • First You need to install JDK (Java Development Kit) in your computer.
  • You should check your hardware configuration as given check here
  • If you need eclipse then you can download it from here
    http://www.eclipse.org/

  • The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

    Step 2:Downloading SDK starter package.
    Step 3. Installing the ADT Plugin for Eclipse
    • Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment in which to build Android applications.
    • For that you need to download ADT plugins
    • http://dl.google.com/android/ADT-16.0.1.zip
    • For step-by-step installation instructions, then return here to continue the last step in setting up your Android SDK.
    • If you prefer to work in a otherIDE, you do not need to install Eclipse or ADT. But i personally suggest you to use Eclipse. (Eclipse Indigo
    • The Introduction to Android application development outlines the major steps that you need to complete when developing in Eclipse or other IDEs.
    Step 4. Adding Platforms and Other Components 
    • The last step in setting up your SDK is using the Android SDK and AVD Manager (a tool included in the SDK starter package) to download essential SDK components into your development environment.
    • The SDK uses a modular structure that separates the major parts of the SDK Android platform versions, add-ons, tools, samples, and documentation into a set of separately installable components. 
    • The SDK starter package, which you've already downloaded, includes only a single component: the latest version of the SDK Tools. To develop an Android application, you also need to download at least one Android platform and the associated platform tools. You can add other components and platforms as well, which is highly recommended.
    • If you used the Windows installer, when you complete the installation wizard, it will launch the Android SDK and AVD Manager with a default set of platforms and other components selected for you to install.
    • Simply click Install to accept the recommended set of components and install them. You can then skip to Step 5, but we recommend you first read the section about the Available Components to better understand the components available from the Android SDK and AVD Manager.
    • You can launch the Android SDK and AVD Manager in one of the following ways:
      • From within Eclipse, select Window > Android SDK and AVD Manager.
      • On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
      • On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute.
    • To download components, use the graphical UI of the Android SDK and AVD Manager to browse the SDK repository and select new or updated components (see figure 1). The Android SDK and AVD Manager installs the selected components in your SDK environment. For information about which components you should download, see Recommended Components. 

    C++ Variable : Declaration and Assignment


    What is variable ?

    Variable reserve space in memory to store the data. You can change the data you stored in the variable. Since the data could vary, it is called variable.
    When declaring variable you should specify what type of data it should store and how much memory it should reserve for it. The following table shows the type of data and size of memory it reserve for that data and also how many values you can store in that data type.


    Type Size Value
    bool 1 byte True or false
    unsigned short int 2 bytes 0 to 65535
    short int 2 bytes -32768 to 32767
    unsigned long int 4 bytes 0 to 4,294,967,295
    long int 4 bytes –2,147,483,648 to 2,147,483,647
    int (16 bit) 2 bytes –32,768 to 32,767
    int (32 bit) 4 bytes –2,147,483,648 to 2,147,483,647
    unsigned int (16 bit) 2 bytes 0 to 65,535
    unsigned int (32 bit) 4 bytes 0 to 4,294,967,295
    char 1 byte 256 character values
    float 4 bytes 1.2e–38 to 3.4e38
    double 8 bytes 2.2e–308 to 1.8e308

    Note : The size of some variable type will differ on 16-bit and 32-bit processor.
    Imp* : You can use "short" instead of "short int" and "long" instead of "long int".

    On the 32-bit processor the value of short ranges from –32,768 to 32,767 but if you declare unsigned short the value ranges from 0 to 65535. You cannot store negative value in unsigned. Never declare unsigned before variable type if there is any possibility to store a negative value.

    How to declare a variable ?

    To declare a variable first type the variable-type (also known as data type) followed by the variable name and then teminate it by semicolon.
    For example :
    int number;
    In the above example, int is the data type and number is name of variable. You can give any name to the variable except for name used for keywords. Variable name can contain letters, numbers or underscore. But the first character should always be either letter or underscore.

    How to assign value to a variable ?

    There are two ways to assign value to a variable :
    1) Assign the value directly in the program.
    2) Ask from user to input a value and then assign that value.

    A C++ program example that assign the value directly in the program.


    #include <iostream>

    int main ()
    {

        using std::cout;
        using std::endl;

        int a = 10, b = 20;
        int sum = a + b;

        cout << "Addition is : " << sum;

        return 0;
    }


    A C++ program example that ask the user to input a value then assign that value.


    #include <iostream>
    #include <iomanip>

    int main ()
    {

        using namespace std;

        int a, b, sum;

        cout << "Enter two number for addition." << endl;

        cout << "First" << setw (3) << ": ";
        cin >> a;

        cout << "Second" << setw (1) << ": ";
        cin >> b;

        sum = a + b;
        cout << "Addition is : " << sum;

        return 0;
    }


    A C++ program example that demonstrate the declaration and assignment of various data types.


    #include <iostream>
    #include <iomanip>

    int main ()
    {

        using namespace std;

        short myShort = 2000;
        int myInt = 200000;
        long myLong = 5000000;
        float myFloat = 1255.549;
        double myDouble = 78079.3;
        char myChar = 'a';
        char myString1[20] = "I love ";
        string myString2 = "C++ Programming";

        cout << "myChar" << setw (5) << ": " << myChar << endl;
        cout << "myShort" << setw (4) << ": " << myShort << endl;
        cout << "myInt" << setw (6) << ": " << myInt << endl;
        cout << "myLong" << setw (5) << ": " << myLong << endl;
        cout << "myFloat" << setw (4) << ": " << myFloat << endl;
        cout << "myDouble" << setw (3) << ": " << myDouble << endl;
        cout << "myString1" << setw (1) << ": " << myString1 << endl;
        cout << "myString2" << setw (1) << ": " << myString2 << endl;

        return 0;
    }


    C++ Notes:

    (1)As we know that in english language statement ends with dot (full-stop). In programming languages like C, C++ and Java, statement ends with semicolon.
    Thus, "int age;" is called statement in C++ and since it declares a variable, it is called declaration statement.
    (2)This "age=20;" too is a statement as it ends with semi-colon. This statement assigns value to the variable, hence it is called assignment statement.
    (3)This "int age=20;" statement does two job. It declares variable as well as assigns value to it. This is compound statement of both declaration as well as assignment statement.
    (4)In C++ (=) is called assignment operator and not equal to as in mathematics. It is use to assign the value. In C++ equality operator is (==).
    (5)As already discussed in earlier lesson that cout in C++ is used to displays output to the console. Similarly, cin is used to take the input (a value) from the user and then assign it to its variable. 

    List Of C++ Keywords


    Note: Do not use C++ Keywords as variable name.


    asm else new this
    auto enum operator throw
    bool explicit private true
    break export protected try
    case extern public typedef
    catch false register typeid
    char float reinterpret_cast typename
    class for return union
    const friend short unsigned
    const_cast goto signed using
    continue if sizeof virtual
    default inline static void
    delete int static_cast volatile
    do long struct wchar_t
    double mutable switch while
    dynamic_cast namespace template

    In addition, the following words are reserved :

    Note: Do not use reserved words as variable name.
    And bitor not_eq xor
    and_eq compl or xor_eq
    bitand not or_eq

    Increment And Decrement Operator in C++


    Increment And Decrement Operator in C++

    In C++ Programming Language, increasing a value by 1 is called incrementing and decreasing value by 1 is called decrementing. As 1 is the most common value used to add, subtract and to reassign into variable. Although we have short-hand assingnment operator but special operator are provided in c++ programming to increase or decrease value by 1. The increment operator(++) increases the variable's value by 1 and the decrement operator(--) decreases the value by 1.

    Nested if-else statements


    A c++ program example that takes input from user for username and password and then makes decision.


    // Program 1

    #include <iostream>
    #include <string>

    using namespace std;

    const string userName = "computergeek";
    const string passWord = "break_codes";


    int main ()
    {
        string name, pass;

        cout << "Username: ";
        cin >> name;

        cout << "Password: ";
        cin >> pass;

        if (name == userName)
        {
            if (pass == passWord)
                cout << "You are logged in!" << endl;
            else
                cout << "Incorrect username or password." << endl;
        }
        else
            cout << "Incorrect username or password." << endl;

        return 0;
    }


    /*A c++ program example that takes input from user for username and if username is correct then only asks for password and makes decision.*/


    // Program 2

    #include <iostream>
    #include <string>

    using namespace std;

    const string userName = "computergeek";
    const string passWord = "break_codes";

    int main ()
    {
        string name, pass;

        cout << "Username: ";
        cin >> name;

        if (name == userName)
        {
            cout << "Password: ";
            cin >> pass;

            if (pass == passWord)
                cout << "You are logged in!" << endl;
            else
                cout << "Incorrect password." << endl;
        }
        else
            cout << "Incorrect username." << endl;

        return 0;
    }

    Logical Operators: AND(&&) OR(||) NOT(!) in c++


    The three logical operators ( AND, OR and NOT ) are as follows:


    1) AND (&&) : Returns true only if both operand are true.
    2) OR (||) : Returns true if one of the operand is true.
    3) NOT (!) : Converts false to true and true to false.

    The switch statement source codes


    The switch statement in c++


    The program that we create should be readable. To increase the readability of the program we should use tools that is simple to read and understand. When possible use switch statement rather than if else statement, as it can be more readable than if else statement. But switch statement has limitation. It can't replace if else completely but can be helpful at certain situation. It can't do everything thing that if else statement can do. For example, switch statement can take only int or char datatype in c++. The following programs will help you to understand the switch statement.

    Input Validation Using While Loop and Do While Loop


    /* A c++ program example that uses while loop for input validation */


    // Program 1

    #include <iostream>

    using namespace std;

    Standard Deviation using Function


    #include<stdio.h>
    #include<conio.h>
    #include<math.h>

    Inserting Elements In An Array


    #include<stdio.h>
    #include<conio.h>
    void main()

    ATM C programing language Program code

    ATM C programing language Program code

     ‎/*Note Pin code is 1234*/
    #include<stdio.h>
    #include<conio.h>

    void main(void)
    { unsigned long amount=1000,deposit,withdr​aw;
    int choice,pin=0,k=0;
    char another='y';

    Find Maximum Value in Array


    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a[5],max,i;
    clrscr();
    printf(“enter elements for the array\n”);
    for(i=0;i<5;i++)
    scanf(%d”,&a[i]);
    max=a[0];
    for(i=1;i<5;i++)
    {
    if(max<a[i])
    max=a[i];
    }
    printf(“the maximum value is%d”,max);
    getch();
    }

    Area and Perimeter of Square


    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float s,a,p;
    clrscr();
    printf(“enter the s value:\n”);
    scanf(%f”,&s);
    a=s*s;
    p=4*s;
    printf(“area=%f\n perimeter=%f\n”,a,p);
    getch();
    }
    Output:
    enter the s value:
    5
    area=25.000000
    perimeter=20.000000 

    Free Turbo C software

    C Programming Tutorials


    About C
    As a programming language, C is rather like Pascal or Fortran. Values are stored in variables. Programs are structured by defining and calling functions. Program flow is controlled using loops, if statements and function calls. Input and output can be directed to the terminal or to files. Related data can be stored together in arrays or structures. Of the three languages, C allows the most precise control of input and output. C is also rather more terse than Fortran or Pascal. This can result in short efficient programs, where the programmer has made wise use of C's range of powerful operators. It also allows the programmer to produce programs which are impossible to understand. Programmers who are familiar with the use of pointers (or indirect addressing, to use the correct term) will welcome the ease of use compared with some other languages. Undisciplined use of pointers can lead to errors which are very hard to trace. This course only deals with the simplest applications of pointers. It is hoped that newcomers will find C a useful and friendly language. Care must be taken in using C. Many of the extra facilities which it offers can lead to extra types of programming error. You will have to learn to deal with these to successfully make the transition to being a C programmer.

    Find all the needs for C Programming, Tutorials, e-books and resources down here :

    C Programming e-books
    Click here for C Programming e -books

    Brian W. KernighanBell Laboratories, Murray Hill, N. J.
    Click here - Kernighan C Tutorial

    C-Library Reference Guide - by Eric HussClick here - Eric Huss Reference Guide

    UNIVERSITY OF LEICESTER
    Click here - Intro to C Programming by UNIVERSITY OF LEICESTER

    C Programming by Steve Holmes
    Click here - C Programming by Steve Holmes