Tuesday, May 1, 2012

Many-to-Many table relation with Join table and extra column implementation with JPA

The many to many relation in the domain modelling can be done with the extra class that has association with the many to many class. The domain modelling follow the same as in the relational model. Here is an example.

For example we have two table called "Employee" and "Project". Each Employee can work on one to many Projects and one Project can have one to many Employee. Here is the database tables

EMPLOYEE
- EMPLOYEE_ID
- EMPLOYEE_NAME
- EMPLOYEE_TYPE

PROJECT
- PROJECT_ID
- PROJECT_TITLE
- PROJECT_DURATION

EMPLOYEE_PROJECT (Join Table)
- EMPLOYEE_ID
- PROJECT_ID
- DATE-ADDED (Extra field)

Domain Modelling

Project.java
 public class Project implements Serializable{  
      private static final long serialVersionUID = 2703915705484865029L;  
      private String projectId;  
      private String projectTitle;  
      private String projectDuration;  
      private List<ProjectEmployee> employees;  
     //getters and setters  
      public void addEmployee(Employee employee, Date dateAdded) {  
           ProjectEmployee association = new ProjectEmployee();  
           association.setEmployee(employee);  
           association.setProject(this);  
           association.setEmployeeId(employee.getEmployeeId());  
           association.setProjectId(this.getProjectId());  
           association.setDateAdded(dateAdded);  
           this.employees.add(association);  
           employee.getProjects().add(association);  
      }  
 }  

Employee.java
 public class Employee implements Serializable{  
      private static final long serialVersionUID = -8821659676348395539L;  
      private String employeeId;  
      private String employeeName;  
      private String employeeType;  
      private List<ProjectEmployee> projects;  
 }  

ProjectEmployee.java
 public class ProjectEmployee implements Serializable{  
      private static final long serialVersionUID = -2691690907714316448L;  
      private String employeeId;  
      private String projectId;  
      private Date dateAdded;  
      private Employee employee;  
      private Project project;  
      //getters and setters  
 }  

And ProjectEmployeeId.java
 public class ProjectEmployeeId implements Serializable{  
      private static final long serialVersionUID = 3284051729103828873L;  
      private String employeeId;  
      private String projectId;  
      public String getEmployeeId() {  
           return employeeId;  
      }  
      public void setEmployeeId(String employeeId) {  
           this.employeeId = employeeId;  
      }  
      public String getProjectId() {  
           return projectId;  
      }  
      public void setProjectId(String projectId) {  
           this.projectId = projectId;  
      }  
      public int hashCode() {  
           return (int) (employeeId.hashCode() + projectId.hashCode());  
      }  
      public boolean equals(Object object) {  
           if (object instanceof ProjectEmployeeId) {  
                ProjectEmployeeId otherId = (ProjectEmployeeId) object;  
                return (otherId.getEmployeeId() == this.getEmployeeId())  
                          && (otherId.getProjectId() == this.getProjectId());  
           }  
           return false;  
      }  
 }  

The persistence-mapping.xml file looks like:
 <?xml version="1.0" encoding="UTF-8" ?>  
 <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm   
                              http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"  
      version="2.0">  
      <entity class="Employee"  
           access="FIELD">  
           <table name="EMPLOYEE" />  
           <attributes>  
                <id name="employeeId">  
                     <column name="EMPLOYEE_ID" />  
                </id>  
                <basic name="employeeName">  
                     <column name="EMPLOYEE_NAME" />  
                </basic>  
                <basic name="employeeType">  
                     <column name="EMPLOYEE_TYPE" />  
                </basic>  
                <one-to-many name="projects" fetch="LAZY" mapped-by="employee">  
                     <cascade>  
                          <cascade-all />  
                     </cascade>  
                </one-to-many>  
           </attributes>  
      </entity>  
      <entity class="Project"  
           access="FIELD">  
           <table name="PROJECT" />  
           <attributes>  
                <id name="projectId">  
                     <column name="PROJECT_ID" />  
                </id>  
                <basic name="projectTitle">  
                     <column name="PROJECT_TITLE" />  
                </basic>  
                <basic name="projectDuration">  
                     <column name="PROJECT_DURATION" />  
                </basic>  
                <one-to-many name="employees" fetch="LAZY" mapped-by="project">  
                     <cascade>  
                          <cascade-all />  
                     </cascade>  
                </one-to-many>  
           </attributes>  
      </entity>  
      <entity class="ProjectEmployee">  
           <table name="EMPLOYEE_PROJECT" />  
           <id-class class="ProjectEmployeeId"/>  
           <attributes>  
                <id name="employeeId">  
                     <column name="EMPLOYEE_ID"/>  
                </id>  
                <id name="projectId">  
                     <column name="PROJECT_ID"/>  
                </id>  
                <basic name="dateAdded">  
                     <column name="DATE_ADDED" />  
                </basic>  
                <many-to-one name="employee" id="true">  
                     <join-column name="EMPLOYEE_ID" updatable="false" insertable="false"/>  
                </many-to-one>  
                <many-to-one name="project" id="true">  
                     <join-column name="PROJECT_ID" updatable="false" insertable="false"/>  
                </many-to-one>  
           </attributes>  
      </entity>  
 </entity-mappings>  

Now Create Persistence.xml file and add these:
 <?xml version="1.0" encoding="UTF-8" ?>  
 <persistence version="2.0"  
    xmlns="http://java.sun.com/xml/ns/persistence"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence  
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">  
   <persistence-unit name="example" transaction-type="RESOURCE_LOCAL">  
     <mapping-file>META-INF/persistence-mapping.xml</mapping-file>  
     <mapping-file>META-INF/persistence-query.xml</mapping-file>  
     <class>Employee</class>  
     <class>Project</class>  
     <class>ProjectEmployee</class>  
     <class>ProjectEmployeeId</class>  
     <properties>  
          <property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>  
       <property name="hibernate.max_fetch_depth" value="3"/>  
       <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>  
       <property name="hibernate.query.substitutions" value="true 1, false 0"/>  
       <property name="hibernate.show_sql" value="true"/>  
       <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect"/>  
       <property name="hibernate.hbm2ddl.auto" value="validate"/>  
     </properties>  
   </persistence-unit>  
 </persistence>  

And persistence-query.xml as :
 <?xml version="1.0" encoding="UTF-8" ?>  
 <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"  
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm  
                              http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"  
     version="2.0">  
   <named-query name="project.findAll">  
        <query>  
             from Project p  
        </query>  
   </named-query>  
   <named-query name="employee.findAll">  
        <query>  
             from Employee e;  
        </query>  
   </named-query>  
   <named-query name="employee.findByProject">  
        <query>  
             select e from Employee e JOIN e.projects p where p.project = ?  
        </query>  
   </named-query>  
 </entity-mappings>  

Finally Create Test Case as follow:
 @RunWith(SpringJUnit4ClassRunner.class)  
 @ContextConfiguration(locations = { "classpath:applicationContext/applicationContext-*.xml" })  
 @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)  
 public class ProjectDaoTest {  
      @Autowired  
      private ProjectDao projectDao;  
      @Autowired  
      private EmployeeDao employeeDao;  
      @Before  
      public void before() {  
      }  
      @After  
      public void after() {  
      }  
      @Test  
      @Transactional  
      public void testProjectAvailability() throws Exception{  
           Project p = projectDao.findByUuid("BEE9F3A7979F505EE040007F01001B21");  
           Employee e = new Employee();  
           e.setEmployeeId(UUIDGenerator.getUUID());  
           e.setEmployeeName("Peter");  
           e.setEmployeeType("Contractor");  
           employeeDao.persistChanges(e);  
           Employee e = employeeDao.findByUuid("785B9FDDD8DB56B14F13359027636041");  
           p.addEmployee(e, new Date());  
      }  
      @Test  
      public void testGetAllEmployeeFromProject() {  
           Project p = projectDao.findByUuid("BEE9F3A7979F505EE040007F01001B21");  
           List<Employee> employees = employeeDao.findByNamedQueryAndParams("employee.findByProject", p);  
           Assert.assertNotNull(employees);  
      }  
 }  

That's All. Enjoy Programming..................

Sunday, April 22, 2012

How to integrate JSF2.0 with Spring 3.0 Framework

Steps:

1. Create the Maven Project "JSF" with
groupId: com.jsf.app
artifactId: jsf
package: war
and add following dependencies in pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
      <modelVersion>4.0.0</modelVersion>  
      <groupId>com.jsf.app</groupId>  
      <artifactId>jsf</artifactId>  
      <version>0.0.1-SNAPSHOT</version>  
      <packaging>war</packaging>  
      <name>jsf</name>  
      <url>http://maven.apache.org</url>  
      <properties>  
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
           <org.springframework.bom.version>3.1.0.RELEASE</org.springframework.bom.version>  
      </properties>  
      <dependencies>  
           <dependency>  
                <groupId>junit</groupId>  
                <artifactId>junit</artifactId>  
                <version>3.8.1</version>  
                <scope>test</scope>  
           </dependency>  
           <!-- Logging Dependencies -->            
           <dependency>  
                <groupId>log4j</groupId>  
                <artifactId>log4j</artifactId>  
                <version>1.2.14</version>  
           </dependency>  
           <!-- http://download.java.net/maven/2 -->  
           <dependency>  
                <groupId>com.sun.faces</groupId>  
                <artifactId>jsf-api</artifactId>  
                <version>2.1.0-b03</version>  
           </dependency>  
           <dependency>  
                <groupId>com.sun.faces</groupId>  
                <artifactId>jsf-impl</artifactId>  
                <version>2.1.0-b03</version>  
           </dependency>  
           <!-- http://repo1.maven.org/maven -->  
           <dependency>  
                <groupId>javax.servlet</groupId>  
                <artifactId>jstl</artifactId>  
                <version>1.2</version>  
           </dependency>  
           <dependency>  
                <groupId>javax.servlet</groupId>  
                <artifactId>servlet-api</artifactId>  
                <version>2.5</version>  
           </dependency>  
           <dependency>  
                <groupId>javax.servlet.jsp</groupId>  
                <artifactId>jsp-api</artifactId>  
                <version>2.1</version>  
           </dependency>  
           <dependency>  
                <groupId>com.sun.el</groupId>  
                <artifactId>el-ri</artifactId>  
                <version>1.0</version>  
           </dependency>  
           <!-- Spring Related Dependency -->       
           <dependency>  
                <groupId>org.springframework</groupId>  
                <artifactId>spring-core</artifactId>  
                <version>${org.springframework.bom.version}</version>  
           </dependency>  
           <dependency>  
                <groupId>org.springframework</groupId>  
                <artifactId>spring-web</artifactId>  
                <version>${org.springframework.bom.version}</version>  
           </dependency>  
      </dependencies>  
 </project>  

2. Create the directory structure like:
jsf
-src
--main
---java
-----com
-------jsf
--------app
----------managedbean
-------------UserBean.java
----------service
-------------UserService.java
-------------impl
---------------UserServiceImpl.java
---resources
----applicationContext.xml
----log4j.xml
----messages.properties
---webapp
-----pages
-------jsfspring.xhtml
-----WEB-INF
--------faces-config.xml
--------web.xml
--test
--pom.xml

3. In web.xml file add these settings.
 <?xml version="1.0" encoding="UTF-8"?>  
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
      id="WebApp_ID" version="2.5">  
      <display-name>JavaServerFaces&Spring</display-name>  
      <listener>  
           <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
      </listener>  
      <listener>  
           <listener-class>  
                org.springframework.web.context.request.RequestContextListener</listener-class>  
      </listener>  
      <listener>  
           <listener-class>com.sun.faces.config.ConfigureListener</listener-class>  
      </listener>  
      <context-param>  
           <param-name>javax.faces.PROJECT_STAGE</param-name>  
           <param-value>Development</param-value>  
      </context-param>  
      <context-param>  
           <param-name>contextConfigLocation</param-name>  
           <param-value>classpath:/applicationContext.xml</param-value>  
      </context-param>  
      <context-param>  
           <param-name>javax.faces.CONFIG-FILES</param-name>  
           <param-value>WEB-INF/faces-config.xml</param-value>  
      </context-param>  
      <context-param>  
           <param-name>com.sun.faces.expressionFactory</param-name>  
           <param-value>com.sun.el.ExpressionFactoryImpl</param-value>  
      </context-param>  
      <servlet>  
           <servlet-name>Faces Servlet</servlet-name>  
           <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>  
           <load-on-startup>1</load-on-startup>  
      </servlet>  
      <servlet-mapping>  
           <servlet-name>Faces Servlet</servlet-name>  
           <url-pattern>/faces/*</url-pattern>  
      </servlet-mapping>  
      <servlet-mapping>  
           <servlet-name>Faces Servlet</servlet-name>  
           <url-pattern>*.jsf</url-pattern>  
      </servlet-mapping>  
      <servlet-mapping>  
           <servlet-name>Faces Servlet</servlet-name>  
           <url-pattern>*.faces</url-pattern>  
      </servlet-mapping>  
      <servlet-mapping>  
           <servlet-name>Faces Servlet</servlet-name>  
           <url-pattern>*.xhtml</url-pattern>  
      </servlet-mapping>  
      <welcome-file-list>  
           <welcome-file>pages/jsfspring.xhtml</welcome-file>  
      </welcome-file-list>  
 </web-app>  

4.Create new JSF bean name as UserBean as shown below in com.jsf.app.managedbean package

 package com.jsf.app.managedbean;  
 import java.util.logging.Logger;  
 import org.springframework.beans.factory.annotation.Autowired;  
 import org.springframework.beans.factory.annotation.Qualifier;  
 import org.springframework.stereotype.Component;  
 import com.jsf.app.service.UserService;  
 @Component("userBean") 
 @Scope("session") 
 public class UserBean {  
      private static final Logger logger = Logger.getLogger(UserBean.class  
                .getName());  
      @Autowired  
      @Qualifier("userService")  
      public UserService userService;  
      public String getPrintMsgFromSpring() {  
           logger.info("Invoking UserService");  
           return userService.getMessage();  
      }  
 }  

5. Next create Spring Interface and Implementation in com.jsf.app.service and com.jsf.app.service.impl package respectively:
 package com.jsf.app.service;  
 public interface UserService {  
      public String getMessage();  
 }  


 package com.jsf.app.service.impl;  
 import org.springframework.stereotype.Service;  
 import com.jsf.app.service.UserService;  
 @Service("userService")  
 public class UserServiceImpl implements UserService {  
      private String name = "Voila!";  
      public String getName() {  
           return name;  
      }  
      public void setName(String name) {  
           this.name = name;  
      }  
      @Override  
      public String getMessage() {  
           return "JSF - Spring Integrtion " + name;  
      }  
 }  

6. Now Create Faces-Config.xml with following information in WEB-INF folder:
 <?xml version="1.0" encoding="UTF-8"?>  
 <faces-config xmlns="http://java.sun.com/xml/ns/javaee"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
   http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"  
      version="2.0">  
      <application>  
           <locale-config>  
                <default-locale>en</default-locale>  
           </locale-config>  
           <resource-bundle>  
                <base-name>messages</base-name>  
                <var>msg</var>  
           </resource-bundle>  
           <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>  
      </application>  
 </faces-config>  

7. Also Create the applicationContext.xml in resources folder:
 <beans xmlns="http://www.springframework.org/schema/beans"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
      xsi:schemaLocation="http://www.springframework.org/schema/beans   
                            http://www.springframework.org/schema/beans/spring-beans.xsd  
                         http://www.springframework.org/schema/context   
                         http://www.springframework.org/schema/context/spring-context.xsd">  
      <context:component-scan base-package="com.jsf.app.managedbean,com.jsf.app.service" />  
 </beans>  

8. Now create the jsf page in the webapp/pages/ folder as shown below:
 <?xml version="1.0" encoding="UTF-8"?>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html">  
 <h:body>  
      <h1>JSF 2.0 + Spring Example</h1>  
            #{userBean.printMsgFromSpring}  
   </h:body>  
 </html>  

9. Finally add the Log4j.xml file for logging purpose inside the resources folder as shown in below:
 <?xml version="1.0" encoding="UTF-8"?>  
 <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >  
 <log4j:configuration>  
      <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">  
           <param name="Target" value="System.out" />  
           <layout class="org.apache.log4j.PatternLayout">  
                <!-- <param name="ConversionPattern" value="[%d{ISO8601}] %-5p [%c] %m %n" />     -->  
                <param name="ConversionPattern" value="%-5p [%c] %m %n" />  
           </layout>  
      </appender>       
      <appender name="STDERR" class="org.apache.log4j.ConsoleAppender">  
           <param name="Target" value="System.err" />  
           <layout class="org.apache.log4j.PatternLayout">  
                <param name="ConversionPattern" value="[%d{ISO8601}] %-5p [%c] %m %n" />  
           </layout>  
           <filter class="org.apache.log4j.varia.LevelRangeFilter">  
                <param name="LevelMin" value="ERROR" />  
                <param name="LevelMax" value="FATAL" />  
           </filter>  
      </appender>  
      <appender name="ROLLING_FILE" class="org.apache.log4j.RollingFileAppender">  
           <!-- param name="File" value="c:/logs/miis30.log" /-->  
           <param name="File" value="jsf.log" />  
           <param name="Append" value="true" />  
           <param name="MaxFileSize" value="5120KB" />  
           <param name="MaxBackupIndex" value="5" />  
           <layout class="org.apache.log4j.PatternLayout">  
                <param name="ConversionPattern" value="[%d{ISO8601}] %-5p %m%n" />  
           </layout>  
      </appender>  
      <root>  
           <level value="ERROR" />  
           <appender-ref ref="STDERR" />  
      </root>    
      <root>  
           <level value="DEBUG" />  
           <appender-ref ref="STDOUT" />  
      </root>   
 </log4j:configuration>  

10. Finally to run the application, right click the project->maven->maven clean,
again right click project->maven->maven install, this will create the war file.
Take a war file and deploy in the tomcat server and run the server as:
 http://localhost:8088/jsf/pages/jsfspring.xhtml  

Tuesday, March 6, 2012

Java J2EE Interview Questions Part 2

15. How do we test private methods in JUnit?
- Private methods cannot be directly tested. If required we can use Java Reflection to test private methods.

16. How do we test protected methods?

- Place the test class under the same package as the class under test.

17. How do you invoke Stored Procedure from Hibernate?
- use hibernate 3 annotation as:
@NamedNativeQueries({
    @NamedNativeQuery(
    name = "callStockStoreProcedure",
    query = "CALL GetStocks(:stockCode)",
    resultClass = Stock.class
    )
})

Query query = session.getNamedQuery("callStockStoreProcedure")
    .setParameter("stockCode", "7277");
   
18. How do you manage transaction in Spring using Hibernate?
- Declare HibernateTransactionManager and set dataSource and sessionFactory property
- Create TransactionInterceptor and set transactionManager and transactionAttributes
- Now create ProxyFactoryBean and set the target dao/bo bean and interceptorNames

19. How do you configure connection pooling using JDBC?
-

20. How to create store procedure in oracle?
CREATE OR REPLACE PROCEDURE my_store_procedure
IS
BEGIN
    select * from my_table where uid = n;
END;

21. What is the difference between LinkList and ArrayList?

22. What is the difference between forward and send redirect?

23. What is MVC?




In progress...........

Sunday, March 4, 2012

Java J2EE Interview Questions Part 1

1. What are the new features in JDK or Java 6?
- XML and Web Services support
- JDBC 4.0 support
- More Annotation type
- More flexible annotation processing
- Java compiler API accessible from programs
- Application client GUI enhancements for both AWT and Swing.
- Scripting support.
- Security like XML-Digital Signature APIs.

2. What is Java reflection?
- Java's reflection API's makes it possible to inspect classes, interfaces, fields and methods at runtime, without knowing the name of the classes, methods etc at compile time. It is also possible to instantiate new objects, invoke methods and get/set field values using reflection. Board use of Java Reflection is: security, code complexity, run time performance etc. Other tangible use of reflection is in JavaBeans, where software components can be manipulated visually via a builder tool.

3. What is synchronization?
-    With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. this usually leads to significant errors.

4. What is volatile in Java?
- volatile is keyword and value of the volatile variable will never be cached thread-locally (i.e. all reads and writes will go straight to main memory).
- also access to the variable acts as though it is enclosed in a synchronized block.

5. How do you improve performance of the database query? or How do you performance tune your database?
- denormalize the table where appropriate.
- proper use of index columns (eg index based on numeric fields than character columns)
- reduce number of columns that make up a composite key
- proper partitioning of tablespace and create special tablespace for CLOB, BLOG
- data access performance can be tuned by store procedure reducing network overhead and also caching data within your application

6. What is Hibernate dirty checking?
- Hibernate automatically detects object state changes in order to synchronize the updated state with the database, this is called dirty checking. Hence, it automatically update only those fields which has been modified. As opposed to updating all persistent objects at the end of each work, automatic dirty checking can offer significant performance savings.

7. What is SOAP fault?
- SOAP fault is an error in a SOAP communication resulting from incorrect message format, header-processing problems, or incompatibility between appliaiton. when a SOAP fault occurs, a special message is generated that contains data indicating where the error originated and what caused it. This data is called a fault element. A message that includes a fault element is known as a fault message.

8. What is the difference between SOAP and RESTful web services?
- Use SOAP when
    1. required stateful operations
    2. required more formal contracts
    3. required asynchronous processing and invocation
- Use RESTful when
    1. required limited bandwidth and resources
    2. required totally stateless operations
    3. required caching situations

9. What is the difference between JDBC excecute(), executeQuery() and executeUpdate()?
-    execute statement is prepared statement which is kind of SQL statement. signature boolean execute().
-    executeQuery  statement is prepared statement to execute SQL Query and returns ResultSet. signature ResultSet executeQuery().
-    executeUpdate is prepared statement for insert, update, delete and returns nothing. signature int executeUpdate().

10. What is the prepared and callable statement in JDBC?
- Prepared Statement is precompiled SQL Statement and accept parameters, more faster than regular statement and secure for SQL Injection.
- Callable Statement is for calling Stored Procedure.

11. What happen to the JMS message when MOM is down?
- message delivery mode set to durable (persistent) when MOM save message to database incase of server crash or message lost and it has adverse effect on performance, but ensure that message delivery is guaranteed.

12. How will you map class inheritance to relational data model?
- Map class hierarchy to single database table (union mapping)
- Map each class to its own table (vertical mapping)
- Map each concrete class to its own table (horizontal mapping)

13. What is the difference between throw and throws in Java?
- throws declare the exception for the method like:
    public void myMethod() throws MyException{} //tells us that what method might pass back to the caller.
- while throw actually throw the exception like:
    public void myMethod() throws MyException{
        if(condition) {
            throw new MyException("throw exception"); // tells us to throw MyException to the caller.
        }
    }
  
14. How will you control two concurrent transactions accessing a database?
- use isolation levels. Dirty read, Norepeatable read and Phantom reads. Provide different isolation levels like:
    TRANSACTION_READ_UNCOMMITED, TRANSACTION_READ_COMMITED, TRANSACTION_REPEATABLE_READ, and TRANSACTION_SERIALIZABLE.

Saturday, December 25, 2010

Cyber Security and E-Government

As cyber activities increases, the threats related to cyber activities also growing. The consequence of those threat or attack is sometime small and some time big enough to bring down business or organizational activities. Even thought main objective of e-Government is to serve citizen, businesses and to provide transparent and open government rather than earning profits, the vulnerability to threat and attack is no more different from those of e-commerce or e-business. As e-participation and civic engagement in e-Government activities is increasing. The risk toward public privacy and database and infrastructure security of e-Government is also increasing. Hence there are risks and threats in both sides and the current cyber law couldn’t address all these issues. Since different countries have different ways of implementing e-Government projects and they has devised their own framework for implementation base on their culture, information resources, politics and law, but when it comes to cyberspace they all have same global issues which can be addressed only by creating International or Global Cyber Law because once when the e-Government is deployed it is visible around the world and cannot restrict on the particular geographical boundary. Global Cyber Law will not only make sure that the public or government information asset and infrastructure be protected but also help address the cyber related crime globally. As we have read or heard the issue about wiki leaks and disclose of US diplomatic cable gives every nation an attention how to protect the vital information internally and externally. As it seen that the threat is emerged from outside world, the inside world is also equally responsible for creating cyber attacks and cyber crime. To better protect from vital information discloser to outside world, better cyber security and law is essential and e-Government implementer should recognize those potential consequences which creating and implementing e-Government services. Government should also recognize public privacy and respect public opinions and freedom of speech. The e-Government initiatives will only be successful when the citizens feel free to participate in e-Government activities and enhance the democracy norms and value by actively participating in e-democracy without worrying the government will sneaks and use their personal information or government surveillance.
As we know that every country has its own constitution and statues to protect their citizen’s right and freedom of speech, the e-Government initiatives in those countries should also reflect those constitution and statues and should create transparent, accountable, efficient and open government by engaging civic participation using current web 2.0 based technologies.
As we already discussed that Gov 2.0 presents exciting opportunities to reach out public and citizens, it has also potential to erode public privacy in the ways that undermine the participatory goals of open government. As companies and non-profit organizations have already adopted on-way mirror policies, the government can also use a one-way mirror policy to ameliorate the problem and facilitate democratic discourse without engendering privacy risk.
Further the risk from public and anonymous group can also be lowered by establishing better cyber security infrastructure, law and awareness. Adopting new innovative technologies like cloud computing will not only lower the infrastructure cost of e-Government projects, but also provide secure and scalable infrastructure for successful e-Government initiatives.

Sunday, November 21, 2010

The effect of Authentication on Cyberspace Laws

Authenticating a person means to verify his/her identity. In cyberspace, absence of relatively self-authenticating makes it extremely difficult to regulate behavior, especially among the young kids. Like for example, In real space if kids go to watch adult movies or go to buy liquor then he/she will definitely ask for true age and once his age is verified then he/she is allowed to purchase or watch such movies. Also by looking at person, one can easily find the physical attributes of that person like age (most of the time), race, gender and so on. Hence authenticating one's identity in real space makes it really easy to regulate behavior and control the crime and other illegal activities.

But cyberspace lacks such self-authenticating mechanism. Like most of the adult web site has got some sort of authentication like before visiting those site people were ask their actual age but that in fact doesn't make any difference whether the person is kids or adults because he/she is not visible and can't control their behavior. Hence authenticating in cyberspace poses serious issues and sometime that leads to criminal activities also. Like, these days we often heard news that person's identity has stolen or one become victimized or even committed suicide related to some social activities in cyberspace. These types of crime related to cyberspace is very difficult to track since people can use fake identity specially in social sites like my-space, face-book and so on. Almost 1 in 5 young school kids in USA is victimized by some sort of cyber bullying. All of these activities are direct consequences of fake authentication or lack of authentication in cyberspace. Internet architecture or network infrastructure has provided no mechanism to control such activities. All these mechanism has to be implemented at the end of the Internet (which is in application itself) and websites like social networking doesn't provide such mechanism till now.
But in the other hand, activities related to the transactions like online banking, shopping and so on required authentication and authorization about the person's identity. This is mostly achieved by asking person principal/credential and other security related questions. Hence commercial web site has secured their business and transaction through layer of security and authentication mechanism and able to regulate the activities. But cyberspace doesn't only consist of banking, shopping and other commercial web site but also includes other web sites like social networking site and other illegal mature and adult site. Most of these sites are free of cost which is how young kids have access without or with very weak authentication mechanism.

Hence looking at these trends in cyberspace, the proper mechanism of authentications still lack in cyberspace and the kinds of protections for privacy and autonomy are still needed.

Effect of Identity on Cyberspace Laws

Identity is an attribute of a person which define who the person is, what he does and how he looks like. Person's identity in the real space is more apparent because he is visible and people can judge base on one's look. Even though one's identity can't truly find out even in real space but person's gender, age and other attribute can be find out by looking at a person. Hence law pertaining to the identity can be applied to real space based on geographic location. Also one's behavior and attitude toward other person can also be controlled by state law. Hence bottom line is that people activities is mostly regulated by some sort of government and constitutional law and that law is based on his or her true identity. Hence identity has got very significant effect on regulating law in real space.

Now what happens in cyberspace when person's identity is not visible or in other word there are thousands activities happening in cyberspace and no one knows who doing what. Tracking person's activities and motive behind his/her activities in cyberspace is very difficult not only because he is invisible but also there is not geographic boundary. Hence identity become crucial in cyberspace. Few decades before when World Wide Web was deployed, there is not such things as identity in cyberspace because all it has to do is to broadcast the information and don't care who receive what information. As Information Technology advances, commercial and government sites are being deployed in web and lots of monetary related activities/transactions started happening in the web, business and government has felt huge importance and necessity of one's identity to complete the transactions/activities successfully. Without person's true identity, it is impossible to carried out this kind of transactions like banking, online shopping, online bill pay and other online activities that happens in cyberspace. Hence identity in cyberspace become one of the serious global issue these days not only because it involves business transaction but also involve other activities like cyber attack, cyber terrors and identity thief. All these cyber related crime happening because of the identity issues. If one can be identified what he is doing and who is he then it is possible to track the yber related activities. These days innovation and advancement in cyberspace, it is possible to track down who is doing what in cyberspace. Most of the commercial activities like banking, online shopping required identity verification before proceeding online activities, but for other activities it is still major issues like computer hacking, virus spreading etc. At least the technology can help us when these activity started and where is the source of these activity by reverse DNS mapping and IP identification but still the exact location and true identity of who is involved in this activity is very difficult. Hence identity has become serious issue in cyberspace and consequences of these cyber crime is disastrous. The serious in the sense that it is very difficult to apply cyber law because of the geographical boundary and one can't be held responsible if the activities happening beyond the specific boundary and law.
Since it is very difficult to regulate all the activities in the cyberspace but still there are possibilities due to the technological advancement to help find out the exact source of those activities and at least its impact can be minimize and controlled in some way.