Sunday, September 26, 2010

• Stream:

It is a communication channel between application and destination file

• Limit of Persistence stores:

1.      cannot maintain huge amount of data
2.      doesn’t provide security to the data
3.      no query language support like sql
4.      performing all kings of persistence operation is always complex process
5.      cannot store mixed contain based data
6.      merging and comparison of data is always complex operation to perform

• Presentation Logic

  • : the logic that we use to read input values for end user and to display business logic result for end user

• Business Logic

  • the main logic of an application that generates the result based on given input values   

Persistence Logic:

  • the logic develops in the application to interact with persistence stores and to perform persistence operation. It is always helps logic to business logic.
Java application use iostream based persistence logic to interact with files and to perform persistence operation on the files.
Java application can use JDBC code as persistence logic to interact with database software and to manipulates tables data

• CURD

in the industry level generally they use this term, which is nothing but create, update, read, delete operations. 

• Persistence Operation

performing insert, update, delete and select operation on persistence stores to manipulate the data. It is called as CURD operation

serialization types

  • Complete serialization: if entire data of an object is written to file through serialization
  • Selective serialization: if selected member variable values of an object are written to file through serialization when class contains transient member variable then all the object of that class supports only selective serialization

• java.io.Serializable interface

  • Java object becomes serializable object only when the class of that object implement marker interface

Distributed application

  • an application which provides the service over the global network with distribution network service to client

• Web based application

  • an application which provides the service for global network client

• Client server application

  • An application which consist  both client and server program which run in the LAN network

• Types of net based application

  • there are three types of net based application are there and they are client server, web based and distributed.

• Standalone vs. net based application

  • standalone application is execute in the local system whereas net based application executes over the network

• Net based application

  •  an application which we can access over the network.

• what is platform independent translation & platform independent prog lang:

  • The translator which translate, the source instructions to byte code instructions which is neutral for all platforms known as platform independent translation, the language which uses the kind of translator are known as platform independent prog lang.. Ex : Java

Saturday, September 25, 2010

What is platform dependent translation & Platform dependent program language

  • The translator which translates its source code instructions to direct platform native code instructions known as platform dependent translation/ translator? Like the language which uses platform dependent translator known as platform dependent prog language Ex : C/C++, VB, VC++ ..etc

• Translator

: it is a program which translates the source code instruction into platform native code instruction. Generally translator are divided into two level ie., high level (compiler and interpreter) and low level (assembly) translators

• What is Language, & responsibilities of language:

  • it is an application which allows the end-user to frame the set of instruction as programs to perform set of actions by the system like creating new account of customer and etc. every language have two responsibilities ie., allowing to write source program (combination of data and process) and translating source program to underlying operating system native code (machine code)

• What is platform native code:

operating system is a software application, consists set of instruction to interact with underlying hardware resources like processor, HDD, RAM and etc

• Java Objective/Theme of java

Java is high level programming language used to develop platform independent and net based application

• What is platform

  • It is the combination of operating system with underlying micro process
    Ex: Win + Intel processor is a platform ...etc, but any way OS plays key role to interact with the Hardware resources.

• Serialization vs Deserialization

  • In medium and large scale application like websites credit/debit card process application, banking application and etc., it is recommended to use database software persistence store as serialization and deserialization. In java based desktop application programmers prefer working serialization and deserialization concepts to perform persistence operation. The process of capturing object data – writing the data to a file is called serialization.


The process of constructing new object in java by using data of the file is called deserialization

• Persistence Store

it stores data permanently and manages. In small scale application like desktop games, mobile games use files as persistence store

• Persistence:

the process of storing data in permanent place and using its data  for multiple application

• Tag or marker interfaces

: this (ie, java.lang. Cloneable interface) interface is called Marker interface because these interface don’t contain methods and capable of implementation of class object. Other interface are java.io.Serializable, java.rmi.Remote, javax.servlet.SingleThreadModel

CloneDemo

class TestClone implements Cloneable {
int a;
double b;
// This method calls Object's clone().
TestClone cloneTest() {
try {
// call clone in Object.
return (TestClone) super. clone ();
}
catch(CloneNotSupportedException e) {
System.out.println ("Cloning not allowed.");
return this;
}
}
}
class CloneDemo {
public static void main(String args[]) {
TestClone x1 = new TestClone ();
TestClone x2;
x1.a = 10;
x1.b = 20.98;
x2 = x1.cloneTest(); // clone x1
System.out.println ("x1: " + x1.a + " " + x1.b);
System.out.println ("x2: " + x2.a + " " + x2.b);
}
}
Command prompt
C:\java\adv java>javac CloneDemo.java
C:\java\adv java>java CloneDemo
x1: 10 20.98
x2: 10 20.98

• Cloneable Object:

java object become Cloneable object only when the class of the object implementation of java.lang. Cloneable interface

• Cloning

the processor of creating new java object based on the class and behavior of the existing object  

• Ways to create object

  • here we can create object in 6 ways. They are
    1. by using new keyword
eg: test t=new test();
    1. by using factory method
eg: thread t= thread.currentthread();
    1. by using a method of java class that return other class object
eg: integer i=new integer(10);
      String s=i. toString ();
Here toString is the method of java.lang.Integer class, constructing or returning another java class object called string object
    1. by using cloning operator,
    2. by using newInstance() method
    3. by using deserialization

To get the object java.lang.Class

By using Class.forName (), we can get in three ways:
  1. Class.forName(“c. test”);
‘C’ object of java.lang.class representing the class test.
  1. By using getClass() of java.lang.Object
Test t=new test ();
Class c=t. getClass ();
Here c is the object java.lang.class representing class test
  1. By using .class keyword
Class c= String .class;
C represents java.lang.String class
Class c=test. Class
C represents java.lang test class

: to get member variable of java class

import java.lang.reflect.*;
public class app6
{
public static void main(String args[])
        {
                        printField (args[0]);
        }
        public static void printField(String name)
        {
                        try
                        {
                                        Class c=Class.forName (name);
                        Field [] f=c.getDeclaredFields ();    
                                        System.out.println ("declare of member variable belonging to  "+ name+ "class are");
                                        for (int i=0;i<f.length ;++i )
                                        {
                                                        String fname=f[i].getType ().getName ();
                                        int x=f[i].getModifiers();
                                        if (Modifier.isPublic(x))
                                                        System.out.println ("public");
                                        if (Modifier.isFinal(x))
                                                        System.out.println ("final");
                                        if (Modifier.isStatic(x))
                                                        System.out.println ("Static");
                                        if (Modifier.isPrivate(x))
                                                        System.out.println ("private");
                                        if(Modifier.isProtected(x))
                                                        System.out.println ("Protected");
                                        if(Modifier.isTransient(x))
                                                        System.out.println ("transient");
                        }
                        }
                        catch(ClassNotFoundException cnf)
                        {
                                        cnf.printStackTrace ();
                        }
                        catch(Exception e)
                        {
                                        e.printStackTrace ();
                       
}
                        }
                        }
Command prompt
C:\java\adv java>javac app6.java
C:\java\adv java>java app6 java.lang.String
declare of member variable belonging to  java.lang.String class are
final
private
final
private
final
private
private
final
Static
private
final
Static
private
public
final
Static

to get modifier of given java class

import java.lang.reflect.*;
public class app5
{
public static void main(String args[])
        {
                        listModifier (args[0]);
        }
        public static void listModifier(String name)
        {
                        try
                        {
                                        Class c=Class.forName (name);
                                        int x=c.getModifiers();
                                        System.out.println ("modifier of "+ name+ "class are");
                                        if(Modifier.isPublic(x))
                                                        System.out.println ("public");
                                        if(Modifier.isFinal(x))
                                                        System.out.println ("final");
                                        if(Modifier.isAbstract(x))
                                                        System.out.println ("abstract");
                        }
                        catch (ClassNotFoundException cnf)
                        {
                                        cnf.printStackTrace ();
                        }
        catch(Exception e)
                        {
                                        e.printStackTrace ();
}}}
Command prompt:
C:\java\adv java>javac app5.java
C:\java\adv java>java app5 java.lang.System
modifier of java.lang.Systemclass are
public
final
C:\java\adv java>java app5 java.lang.Integer
modifier of java.lang.Integerclass are
public
final
C:\java\adv java>java app5 java.awt.Button
modifier of java.awt.Buttonclass are
public
C:\java\adv java>java app5 java.lang.Number
modifier of java.lang.Number class are
public
abstract
C:\java\adv java>

to get all interface implement by that class

  • //app4.java
    public class app4
    {
    public static void main(String args[])
            {
            printInterface (args[0]);
            }
            public static void printInterface(String name)
            {
                            try
                            {
                                            Class c = Class.forName (name);
                                            Class i [] =c.getInterfaces ();
                                            System.out.println ("interface implemented by" + name +"class are");
                                            for (int x=0;x<i.length ;++x )
                                            {
                                            String iname=i[x].getName ();
                                            System.out.println ("\t\t"+ iname);
                                            }
                            }
                                            catch(ClassNotFoundException cnf)
                            {
                            cnf.printStackTrace ();
                            }
                            catch (Exception e)
                            {
                                            e.printStackTrace ();
                            }
    }
    }
    Command prompt
    C:\java\adv java>javac app4.java
    C:\java\adv java>java app4 java.lang.Integer
    Interface implemented by java.lang.Integerclass are
                    java.lang.Comparable
    C:\java\adv java>java app4 java.awt.Button
    Interface implemented by java.awt.Buttonclass are
                    javax.accessibility.Accessible
    C:\java\adv java>java app4 java.lang.String
    Interface implemented by java.lang.String class are
                    java.io.Serializable
                    java.lang.Comparable
                    java.lang.CharSequence

to get all the classes of inheritance hierarchy for a given class

//app3.java
public class app3
{
                public static void main(String args[])
                {
                                printhierachy (args[0]);
                }
                public static void printhierachy(String name)
                {
                                try
                                {
                                                Class c=Class.forName (name);
                                                Class sc=c.getSuperclass ();
                                                System.out.println ("inheritance hierarchy class of "+name +"classes are");
                                                while(sc!=null)
                                                {
                                                                System.out.println (""+sc.getName ());
                                                                c=sc;
                                                                sc=c.getSuperclass();
                                                }
                                }
                                catch (Exception e)
                                {
                                                e.printStackTrace ();
                                }
                }
}
Command prompt:
C:\java\adv java>javac app3.java
C:\java\adv java>java app3 java.lang.Integer
Inheritance hierarchy classes of java.lang.Integerclass are
java.lang.Number
java.lang.Object
C:\java\adv java>java app3 java.lang.Float
Inheritance hierarchy classes of java.lang.Floatclass are
java.lang.Number
java.lang.Object
C:\java\adv java>java app3 java.awt.Button
Inheritance hierarchy classes of java.awt.Buttonclass are
java.awt.Component
java.lang.Object
C:\java\adv java>

• java.lang.NullPointerException

  • when you call java method on a reference variable that points to null value, then application throws null pointer exception. Here the word pointer is no way related with c and c++ pointers just give dictionary meaning to it that says application is a calling method on a reference variable that points to null value.

: If object c represents java.lang.String Class, then ‘sc’ represents java.lang.Object Class

//app2.java
public class app2
{
                public static void main(String args[])
                {
                                printSuperclass (args[0]);
                }
                public static void printSuperclass(String name)
                {
                                try
                                {
                                                Class c=Class.forName (name);
                                                Class sc=c.getSuperclass ();
                                                System.out.println (c.getName () +"extends" + sc.getName ());
                                }
                                catch(Exception e)
                                {
                                                e.printStackTrace ();
                                }
                }
}
In command prompt:
C:\java\adv java>javac app2.java
C:\java\adv java>java app2 java.lang.String
java.lang.Stringextendsjava.lang.Object
C:\java\adv java>java app2 java.lang.Integer
java.lang.Integerextendsjava.lang.Number
C:\java\adv java>java app2 app2
app2extendsjava.lang.Object
C:\java\adv java>

Difference between toString () & printStackTrace ()

  • toString () gives name of the exception class when exception is raised and printStackTrace () gives the entry hierarchy of method execution that were there when exception is raised in the application.

• Checked vs. unchecked exception

  • The immediate subclass of java.lang.exception class is called checked exception class. This exception is quite serious exception to catch and handle. The sub classes of java.lang.Runtime exception class are called unchecked exception. If a java method throws checked exception we must catch and handle the exception by using try catch blocks or we must declare to exception to be throws by using throws statement while calling that method. If a java method throws unchecked exception catching and handling that exception or declaring the exception to be thrown is always optional work to do. No exception will come at compile time. The compile time error that comes related to checked exception are not exception they are compile time programmatic and syntactical error. It is always recommended to avoid throws class utilization in the process of dealing with exception because it cannot avoid abnormal program termination in application execution. It is always recommended to use try catch block to catch and handle the exception and to avoid abnormal termination of the application execution when exception is raised. While working with java statement which throws checked or unchecked exception it is recommended to catch and handle exception in the entire situation.

• Factory ():

  • a method of java class that is capable of constructing it own java class object. When class is having private constructor in order to create the class object outside of that class be generally use this method. We cannot execute object java.lang.class by using new keyword because this class is having only private constructor. To solve this problem use the factory method Class.forName ie, class c=Class.forName (---);  Other factory method are thread t=thread.currentthread(); and calendar cl= calendar.getInstance();

• Static ():

  • this is instance independent method. So we can call this method without object by using class name

• ClassNotFoundException

  • throws checked exception is calls when given class or interface is not able to load.

A program to now whether given input is class or interface name

//app1.java
public class app1
{
                public static void main(String args[])throws Exception
{
                Class c=Class.forName (args [0]);
                boolean b=c.isInterface();
                if(b)
                                System.out.println (args [0] +"is an interface");
                else
                                System.out.println (args [0] +" is a class");
}
}

In command prompt
C:\java\adv java>javac app1.java
C:\java\adv java>java app1 java.lang.System
java.lang.System is a class
C:\java\adv java>java app1 java.lang. Runnable
Java.lang. Runnable is an interface
C:\java\adv java>

• Class. forName(……):

  • (……): Every reflection API program should load given class or interface dynamically into application from memory at runtime in order to get internal details of that class or interface for this our reflection API program will use as predefined method. Eg:-Class c = Class.forName (“java.lang.system”);
When the above statement is executed class for name method loads java.lang.system class from the memory to java application and returns object of java.lang class ‘c’. This object represents or pointer the class that is loaded java.lang.system class. In the above system ‘c’ is not the object of loaded class called java.lang.system. It is the object of java.lang.class representing loaded class called java.lang.system. 
Class c= Class.forName (“java.lang.system”);
String s=”java.lang.system”;
When object of java.lang.class represents certain class we can use that object to gather internal details of that class. In the above statement we can use object ‘c’ to gather internal details of system class. When string variable represent class name we cannot use that string variable together internal details of that class. In the above statement variable‘s’ cannot be used to gather internal details of system class.