• Tuesday, September 30, 2014

    6. Java - Variables

    Syed Masoom Rizvi
    Java Variable
    A variable is a named memory location where we can store different types of values.
    The value of a variable may be changed during the execution of the program.
    Variables are of different types for storing different values.

    Types of Value            Keword                  Example
    Integer Valuesintint m=5;
    Character Typecharchar a='v'
    String ValuesStringString myStr="test"
    Double Valuesdoubledouble myDbl=2.564
    Boolean(true or false)BooleanmyBool=true;

    Following program clear the concept of the variable:

    Thursday, September 25, 2014

    Java, Android - Set time out while connecting using Socket with IP Address

    Syed Masoom Rizvi

    How to set time while connecting  using socket with provided IP Address

    Import these files:

    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.net.ServerSocket;


    public void connect(String IPAddress,int port,int timeOut) throws Exception
    SocketAddress sa=InetSocketAddress(IPAddress,port);
    Socket s=new Socket();

    GET ALL LOCAL IP ADDRESS in Java, Android

    Syed Masoom Rizvi

    How to get all connected local ip address.

    String myIP=Inet4Address.getLocalHost().getHostAddress();

    for(int i=1;i<=255;i++)
    int pos=myIP.lastIndexOf(".");
    String temp=myIP.substring(0,pos) + "." + i;
    System.out.println("IP Address: " +temp);

    Tuesday, September 16, 2014

    Java - Converting Character to String

    Syed Masoom Rizvi

    How to convert a character to string.

    In Java, character is a data type which use char keyword to make a variable char type, but this character cant by directly type casted to String. Because String is a class.

    To convert character to string, we use Character.toString(char) method.


    char myChar='c';
    String myString="";

    Example 2:

    Monday, September 15, 2014

    Java - Converting String to Integer or Integer to String.

    Syed Masoom Rizvi

    How to convert String to integer or integer to String in Java

    In Java, String is a predefined class in Java which can hold String Value(array of Characters.).
    If any string contain number such as "53", "21" , "110" and you want to use of Integer. It is not directly possible.

    You can convert it by using Integer.parseInt(myStringNumber).

    Example 1:

    Winsock For Microsoft Visual Basic 2008,2010 (.NET) as same as in Visual Basic 6.0

    Syed Masoom Rizvi
    In Viusal Basic 6.0, there is control named "Winsock" which is used to easily create connection with server or opens connection for client.

    But in Viusal Basic NET(2008,2010,2012) this features excluded.
    There is a Winsock as same as in VB6 for latest Visual Basic which behave as same as WinSock.

    Download WinSock For Latest Version

    Java Exception Handling

    Syed Masoom Rizvi
    Exceptions are special types of error which occurred at run time and leads to abnormal termination of the program.
    These exceptions are handled by the programmer.

    Some types of exception are:
    1. Math Error( such as division by zero)

    2. Memory Error(such as memory full, index out of bound)

    3. File system error(such as read/write error, file not found error)

    4. Network Error( such as host not found, port already in use)

    To handle this types of error java provides Exception class. These error handles as follow:

       //my code that may generate errors.
    catch(Exception e)
       // code to be executed if error occurs.

    SQL Database - Select a random row from table in MySQL, PostgreSQL, Oracle, Microsoft SQLServer

    Syed Masoom Rizvi
    For MySQL:

    SELECT * FROM table_name ORDER BY RAND() LIMIT 1

    You can also use below code to make query faster:

    SELECT * FROM table_name WHERE RAND() > 0.9 ORDER BY RAND()

    For PostgreSQL:

    Java - The Four Object Oriented Programming(OOP) Principles

    Syed Masoom Rizvi
    For implementing object oriented model, Java provide three  mechanism :

    1. Encapsulation
    2. Inheritance
    3. Polymorphism
    4. Abstraction
    1. Encapsulation: It is a mechanism of hiding data. It hide the visiblity of fields and field can be changed by using public methods so that the code can be protect from unauthorized access by outer world.

    Sunday, September 14, 2014

    Java - Local Class and Anonymous Class

    Syed Masoom Rizvi

    Local Class and Anonymous Class

    Local Class: If we declare an inner class within a method such class is known as local class.
    Use it if you need to create more than one instance of a class and access its constructor, or introduce a new, named type.

    Android - WebView with custom and local data

    Syed Masoom Rizvi

    How to display custom text, html and local store images on Andoid Webview

    public void viewData()
    WebView w=(WebView)findViewById(R.id.webView1);


    myData= "<html><body><img src='file:///android-res/raw/myfile.jpg' />This is test webpage</body></html>";



    Wednesday, September 10, 2014

    Java - Overloading Method

    Syed Masoom Rizvi
    A class have two or more method with same name but different parameter. This is called overloading method in Java.

    class OverloadingTest
    public void add(String s1, String s2)
    String s3=s1 + s2;
    System.out.println("Addition of two string is: " + s3);

    public void add(int i1, int i2)

    Java - Thread Runnable

    Syed Masoom Rizvi

    Java Thread and Runnable

    Runnable (java.lang.Runnable): Runnable is basically a interface which is used to create a task(runnable code) which can run in Thread. Before reading Runnable you must learn Thread first.

    Runnable define a method run() which must override

    Tuesday, September 9, 2014

    Java - Thread

    Syed Masoom Rizvi

    Thread in Java

    What is Thread?

    Thread is a class, an independent path of execution within a program. A thread execute the provided code(Task) in new process, so the thread run concurrently with your program. 
    Usually thread is use for connectivity(i.e. Networking, Internet, Bluetooth), timer, i/o operation.

    Thursday, September 4, 2014

    1. Install and Setup Java Environment on Windows, Linux

    Syed Masoom Rizvi
    Basic step for installing and setting up environment.

    1. Download Latest Version of Java From Here: JAvA WEBSITE.
    2. Install the Java.
    3. Setting up Environment Variables:

      For Windows XP

    5. Java Creating Objects

    Syed Masoom Rizvi

    How to create object in Java & what its benifit.

    As i said in early lesson that objects is a instance of a class. Each instance have its own unique attribute.

    In this lesson we make two classes. First for the main method and another for a object car.
    Car have the following property:
    Its name in string. Example: "Alto", "Scorpio", " Tavera", "Audi" etc.....
    Its fuel in double. Example: 34.4 , 12.0. 839.343 etc....
    Its fuelLimit in double. Example 100.00 etc...

    It have one method which give the available fuel in that car.

    Let's begin.