Thursday, September 19, 2013

What are the domains we do projects on (BFSI)?

BFSI: 

       Banking, Financial services and Insurance (BFSI) is an industry term for companies that provide a range of such financial products/services such as universal banks.
       Banking may include core banking, retail, private, corporate, investment, cards and the like. Financial Services may include stock-broking, payment gateways, mutual funds etc. Insurance covers both life and non-life.
       This term is commonly used by information technology (IT)/Information technology enabled services (ITES)/business process outsourcing (BPO) companies and technical/professional services firms that manage data processing, application testing and software development activities in this domain.

Monday, September 16, 2013

Data conversions among Primitive, Wrapper, String..

Data type conversions:

Generally, We have huge usage of Primitives, Wrappers and Strings usage in any JAVA project.

So, In this post I am writing most important data conversion techniques which are used mostly in all projects.
And most of the people have confusion on these conversions that what API they have to use for what data type .


Our Requirement:  (String, Wrapper, Primitive)

1) String to Wrapper
2) String to Primitive
3) Wrapper to String
4) Wrapper to Primitive
5) Primitive to String
6) Primitive to Wrapper

The above conversions used extensively.


---------------------------------------------------------------------------------------------------------------

1) String to Wrapper conversion:

-For this we have Wrapper class API, valueOf() method in each and every Wrapper class which takes String as parameter and converts into Wrapper ( Integer, Float,...etc)

static IntegervalueOf(String s)
          Returns an Integer object holding the value of the specified String.

like wise we have methods for all primitives

example usage:
                Integer iStr33=Integer.valueOf("33");
System.out.println(iStr33);

---------------------------------------------------------------------------------------------------------------

2) String to Primitive conversion: 
-For this, we have Wrapper API, parseXXX() method in each and every Wrapper class which takes String as parameter and converts into primitives ( int, float,...etc).

static intparseInt(String s)
          Parses the string argument as a signed decimal integer.

like wise we have methods in all Wrapper classes.

example usage:
                int i=Integer.parseInt("33");
System.out.println(i);

---------------------------------------------------------------------------------------------------------------

3) Wrapper to String conversion:
-For this we have toString() method in each and every Wrapper class.

static StringtoString(int i)
          Returns a String object representing the specified integer.

like wise we have this method in all Wrapper classes.

example usage:
                        String strI=Integer.toString(10);
System.out.println(strI);

---------------------------------------------------------------------------------------------------------------

4) Wrapper to Primitive conversion:
- For this we have xxxValue() method in each and every wrapper class.

 intintValue()
          Returns the value of this Integer as an int.

like wise we have floatValue, doubleValue....etc in all wrapper classes.

example usage:
                        Integer iW=new Integer(22);
int i=iW.intValue();
System.out.println(i);

---------------------------------------------------------------------------------------------------------------

5) Primitive to String conversion:  

- For this conversion we have String API, And this String class has many Overloaded methods.
- And also we have Wrapper class API,

Below table shows you how to convert any primitive to String.

String API:
static StringvalueOf(boolean b)
          Returns the string representation of the boolean argument.
static StringvalueOf(char c)
          Returns the string representation of the char argument.
static StringvalueOf(char[] data)
          Returns the string representation of the char array argument.
static StringvalueOf(char[] data, int offset, int count)
          Returns the string representation of a specific subarray of the char array argument.
static StringvalueOf(double d)
          Returns the string representation of the double argument.
static StringvalueOf(float f)
          Returns the string representation of the float argument.
static StringvalueOf(int i)
          Returns the string representation of the int argument.
static StringvalueOf(long l)
          Returns the string representation of the long argument.
static StringvalueOf(Object obj)
          Returns the string representation of the Object argument.

Wrapper API Integer class:
static StringtoString(int i)
          Returns a String object representing the specified integer.

example usage:

           1)  int x=10;
String strX=String.valueOf(x);
System.out.println(strX); 
               
           2)  String iI = Integer.toString(22);
System.out.println(iI);

---------------------------------------------------------------------------------------------------------------

6) Primitive to Wrapper conversion:
-For this we have valuOf() method in all wrapper classes.
-And also we can create directly using constructor.

type1:
static FloatvalueOf(float f)
          Returns a Float instance representing the specified float value.

type2:
Float(float value) 
          Constructs a newly allocated Float object that represents the primitive float argument.


like wise we have this type of method in all wrapper classes.

example usage:
                        Integer i=new Integer(34);
Integer j=Integer.valueOf(44);

---------------------------------------------------------------------------------------------------------------



The above are some of the techniques we use them mostly in every java project.

Please let me know any mistakes are in this post, Send your feedback at nagarjuna.lingala@gmail.com  or javaojavablog@googlegroups.com

sources :
http://docs.oracle.com/javase/6/docs/api/java/lang/String.html
http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html

Sunday, September 15, 2013

The Best Example ever on Runtime Polimorphism ...with JDBC code...

Hi,

I would like to explain you about runtime polymorphism with better example.

Here I am taking JDBC code to explain.


public static void main(String[] args) throws ClassNotFoundException,
            InstantiationException, IllegalAccessException, SQLException {
      
        //
preparing parameters
        String username = "root";
        String password = "root";
        String url = "jdbc:mysql://localhost/nag";// here in the url nag
                                                    // indicates database name
 

        // writing jdbc
        //DriverManager.registerDriver( new com.mysql.jdbc.Driver());


        Class.forName("com.mysql.jdbc.Driver");//
Loading of class at runtime
        Connection conn = DriverManager.getConnection(url, username, password);
        Statement statement = conn.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from emptest");
        while (resultSet.next()) {
            //
            System.out.println("employee number is :" + resultSet.getInt("eno"));
            System.out.println("employee name is:" + resultSet.getString("ename"));
            System.out.println("employee salary is :"+ resultSet.getInt("esal"));
            System.out.println();
            //
        }
    }
//end method



The above concept is known as Dynamic method Dispatching ( calling implemented class / child class objects method using it's super / interface reference ).

In the above code Driver is loaded using Class.forName() method, this method loads the Driver class dynamically. Till now it is ok.

What about next line, getting Connection object using DriverManger.getConnection() method, the method getConnection() is available in DriverManager class and  the method createStatement() is available in Connection interface.

It means we are calling a method using interface instance,

       Statement statement = conn.createStatement();

Then how this method is calling even though it is of Connection interface (abstract method), It is able to call that method.

This technique is called as Dynamic method Dispatching.

Writing the above code using Class.forName() is the correct example for Dynamic method Dispatching, Because the compiler doesn't know what Driver class will be loaded.

The decision of calling a method will be taken at runtime by JVM, not compiler.

But  writing the above code using DriverManager.registerDriver() is not the exact example for Dynamic method Dispatching, Because the compiler knows what Driver class will be loaded and checks for compilation.

The decision of calling a method will be taken at compile-time,,, :P

Please let me know any mistakes are in this post, Send your feedback at javaojavablog@googlegroups.com  or  nagarjuna.lingala@gmail.com


Note:
- If you use DriverManager.registerDriver(), compiler checks for the Driver class in the classpath, if that class Does not exist in the classpath then compiler will throw an exception.

- If you use Class.forName(), compiler won't check for the specified Driver class in the classpath, and it throws ClassNotFoundException, this exception is checked exception, If the Driver class does not exist in the classpath at application running time then jvm will throw runtime exception only.

How many JVM's will be created in any Operating System, If we run multiple java applications?

JVM Inernals :

Hi All,

In this post I would like to tell you how many jvm's are created for multiple java applications.

Take an Example that you have a class with the Name ReadText.java

this java file has below code in it,

public class ReadText {

    public static void main(String[] args) {

        Scanner s=new Scanner(System.in);
        System.out.println("Enter any text:");
        s.next();
    }
}//end class


compile the above code " javac ReadText.java" -- > ReadText.class


now see

when you type jps, you will see number of jvm processes are running in the current OS.

Then open two terminals and run the above .class  "java ReadText" from two Terminals , and don't enter any text, just wait and type jps again in the third terminal.


Now you will see number of java processes running currently in this OS.
693, 709 are two java PS are running and in each jvm same ReadText app is running, Observe ReadText apps are waiting for user input , It means those two jvms are waiting for user input,.

Once user enter's any text and press Enter Button, then the jvm PS will automatically closed.

For example , let us enter any text in the left terminal and press Enter button.


See above picture, process number 693 is executed and closed successfully. and another jvm at right terminal is still waiting for user input. so we have 709 PS.

If you enter any text in the right terminal, that PS also will be closed successfully.



Note:

1) Here don't think PS number 8491, because eclipse is running in the back ground, and that is also another JVM PS. And similarly PS numbers 31530, 4080 are JVM Processes which runs jps command, jps closes automatically once execution is completed.
2) According to Operating System also these JVM PSs are different processes and OS assigns separate process ID for each.


Please let me know if any mistakes are here in this post, give your feedback at nagarjuna.lingala@gmail.com or javaojavablog@googlegroups.com