Friday, 7 March 2014

Eclipse Debugging Tutorial

Eclipse Debugging Tutorial

see more https://www.eclipse.org/resources/resource.php?id=503

Debugging key bindings / shortcuts for Eclipse 
KeyDescription
F5Executes the currently selected line and goes to the next line in your program. If the selected line is a method call the debugger steps into the associated code.
F6F6 steps over the call, i.e. it executes a method without stepping into it in the debugger.
F7F7 steps out to the caller of the currently executed method. This finishes the execution of the current method and returns to the caller of this method.
F8F8 tells the Eclipse debugger to resume the execution of the program code until is reaches the next breakpoint or watchpoint.

The following picture displays the buttons and their related keyboard shortcuts.
Debug Shortcuts

Saturday, 8 February 2014

Eclipse Shortcuts

Eclipse IDE Shortcuts

1. Using shortcuts in Eclipse
Using shortcuts is usually preferable as you can perform actions much faster.
Eclipse supports of course the common shortcuts, e.g. Ctrl+S for saving, Ctrl+C for copying the selected text or file and Ctrl+V for pasting the element currently in the clipboard.

2. Quick Access
The Ctrl+3 shortcut allows you to perform all available actions in Eclipse. This shortcut puts the focus into the Quick Access search box which allows you to execute any Eclipse command.
For example you can open a Preference, a Wizard, a view and a Preference page.
You can also use Quick Access to search for an opened editor by typing in the name of the resource which the editor shows.
The following screenshot shows how you could use Ctrl+3 to open the Wizard to create a new Java class.

3. Navigation
3.1. Globally available navigation shortcuts
Eclipse provides shortcuts for opening files or Java artifacts.
Table 1. Navigation
Shortcut
Description
Ctrl + Shift + R
Search dialog for resources, e.g. text files
Ctrl + Shift + T
Search dialog for Java Types
Ctrl + E
Search dialog to select an editor from the currently open editors
Ctrl + F8
Shortcut for switching perspectives

3.2. Navigation shortcuts in the editor
If you are working in the Java editor you can also use certain shortcuts for faster navigation. The following tables lists a few of them.
Table 2. Search from an editor
Shortcut
Description
F3
Opens editor to selected element (type) or navigate to the declaration of the selected variable
Ctrl + .
Go to the next problem / error
Ctrl + ,
Go to the previous problem / error
F4 on a variable
Show type hierarchy
Ctrl + J
Incremental search without popup dialog, just starting typing to search. Press Ctrl + J to find the next match
Ctrl + K
Searches the selected text or if nothing is selected the last search from the Find dialog.
Ctrl + Shift + G
In the Java editor, search for references in the workspace
Ctrl + Shift + P
Select the matching bracket. Cursor needs to be placed before or after a bracket.

Table 3. Navigation between editors
Shortcut
Description
Alt + ←
Go to previous opened editor. Cursor is placed where it was before you opened the next editor
Alt + →
Similar Alt + ← but opens the next editor
Ctrl + Q
Go to editor and the position in this editor where the last edit was done
Ctrl + PageUp
Switch to previous opened editor
Ctrl + PageDown
Switch to next opened editor

4. Start Java programs
Table 4. Running programs
Shortcut
Description
Ctrl + F11
Run last launched
Alt + Shift + X, J
Run current selected class as Java application

5. Editing
The following lists contains useful keyboard shortcuts if you are inside your Java editor.
Table 5. Handling the editor
Shortcut
Description
Ctrl + 1
Quickfix; result depending on cursor position
Ctrl + Space
Content assist/ code completion
Ctrl + T
Show the inheritance tree of the current Java class or method.
Ctrl + O
Show all methods of the current class, press Ctrl + O again to show the inherited methods.
Ctrl + M
Maximize active editor or view
Ctrl + Shift + F
Format source code
Ctrl + I
Correct indentation, e.g. format tabs/whitespaces in code
Ctrl + F
Opens the find dialog
Ctrl + Shift + O
Organize the imports; adds missing import statements and removes unused ones
Ctrl + Alt + Z
Wrap the select block of code into a block, e.g. try/catch.

Table 6. Cursor navigation and text selection
Shortcut
Description
Ctrl + ← or Ctrl + →
Move one text element in the editor to the left or right
Ctrl + ↑ or ↓
Scroll up / down a line in the editor
Ctrl + Shift + P
Go to the matching bracket
Shift + Cursor movement
Select text from the starting position of the cursor
Alt + Shift ↑ / ↓
Select the previous / next syntactical element
Alt + Shift ↑ / ↓ / ← / →
Extending / reducing the selection of the previous / next syntactical element

Table 7. Copy and move lines
Shortcut
Description
Ctrl + Alt + Cusor Down
Copy current line below the line in which the cursor is placed
Ctrl + Alt + Cusor Up
Copy current line above the line in which the cursor is placed
Alt + Up
Move line one line up
Alt + Down
Move line one line down

Table 8. Delete
Shortcut
Description
Ctrl + D
Deletes line
Ctrl + Shift + DEL
Delete until end of line
Ctrl + DEL
Delete next element
Ctrl + BACKSPACE
Delete previous element

Table 9. Create new lines
Shortcut
Description
Shift + Enter
Adds a blank line below the current line and moves the cursor to the new line. The difference between a regular enter is that the currently line is unchanged, independently of the position of the cursor.
Ctrl+Shift+Enter
Same as Shift + Enter but above

Table 10. Variable assignment
Shortcut
Description
Ctrl + 2, L
Assign statement to new local variable
Ctrl + 2, F
Assign statement to new field

6. Coding
Table 11. Coding
Shortcut
Description
Shift + F2
Show the Javadoc for the selected type / class / method
Alt+Shift + N
Shortcut for the menu to create new objects
Alt + Shift + Z
Surround block with try and catch

7. Refactoring
Table 12. Refactoring
Shortcut
Description
Alt + Shift + R
Rename
Ctrl + 2, R
Rename locally (in file), faster than Alt + Shift + R
Alt + Shift + T
Opens the context-sensitive refactoring menu, e.g. displays

8. Minimum
The following shortcuts are the absolute minimum a developer should be familiar with to work efficient in Eclipse.
Table 13. Must known shortcuts
Shortcut
Description
Ctrl + S
Saves current editor
Ctrl + 1
Quickfix; shows potential fixes for warnings, errors or shows possible actions
Ctrl + Space
Content assist/ code completion
Ctrl + Q
Goes to the last edited position
Ctrl+ D
Deletes current line in the editor
Ctrl + Shift + O
Adjusts the imports statements in the current Java source file
Ctrl + 2, L or F
Assign statement to new local variable or field
Ctrl + Shift + T
Open Type Dialog
Ctrl + O
Shows quick outline of a class
Ctrl + F11
Run last launched application


Saturday, 12 October 2013

Struts + Hibernate Integration Example With MyEclipse

Struts   +  Hibernate Integration Example With MyEclipse 




































index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@taglib  uri="http://jakarta.apache.org/struts/tags-html"  prefix="html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>    
    <title>My JSP 'index.jsp' starting page</title>
  </head>  
  <body> 
  <center><h1>Student Registration</h1><hr>
  <html:form method="POST" action="/store">
  <table bgcolor="#ccccff">
  <tr><td>Student Name : </td><td><html:text property="name"></html:text></td></tr>
  <tr><td>Course Name : </td><td><html:text property="course"></html:text></td></tr>
  <tr><td>Faculty Name : </td><td><html:text property="fname"></html:text></td></tr>
  <tr><td>&nbsp;</td><td><html:submit  property="Submit">Register</html:submit><html:reset>Clear</html:reset></td></tr>
  </table>  
  <br>
  </html:form> 
  </center>
  </body>
</html>

StudForm.java

package com.struts.hibernate;
import java.io.Serializable;
import org.apache.struts.action.ActionForm;
public class StudForm extends ActionForm implements Serializable{
private long sid;
private String name;
private String course;
private String fname;
public long getSid() {
return sid;
}
public void setSid(long sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
}

StudentAction.java

package com.struts.hibernate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.hibernate.Transaction;

import sf.HibernateSessionFactory;

public class StudentAction extends Action {
 public ActionForward execute(ActionMapping am,ActionForm af,HttpServletRequest req,HttpServletResponse res)throws Exception{
StudForm sform=(StudForm)af;
Session s=HibernateSessionFactory.getSession();
Transaction t=s.beginTransaction();
Long  id;
id=(Long)s.save(sform);
req.setAttribute("sid", id);
t.commit();
return am.findForward("success");
 }
}

stud.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
 <class name="com.struts.hibernate.StudForm" table="STUDENTS_DATA">
  <id name="sid" column="SID" type="long">
   <generator class="native"/>
  </id>
  <property name="name" type="string" column="NAME"/>
  <property name="course" column="COURSE" type="string"/>
  <property name="fname" column="FACULTY" type="string"/>
 </class>
</hibernate-mapping>

HibernateSessionFactory.java

package sf;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
public class HibernateSessionFactory {
 
    private  static Configuration configuration = new Configuration();    
    private static org.hibernate.SessionFactory sessionFactory;

static {
    try {
configuration.configure("/hibernate.cfg.xml");
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
    }
    public static Session getSession() throws HibernateException {
Session session =sessionFactory.openSession();
        return session;
    }
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
}

hibernate.cfg.xml


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/java</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">admin</property>
    <property name="hbm2ddl.auto">update</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <property name="format_sql">true</property>
    <mapping resource="com/struts/hibernate/stud.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

ViewStudentAction.java

package com.struts.hibernate;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.hibernate.Transaction;
import sf.HibernateSessionFactory;

public class ViewStudentAction extends Action {

 public ActionForward execute(ActionMapping am,ActionForm af,HttpServletRequest req,HttpServletResponse res)throws Exception{
StudForm sform=(StudForm)af;
Session s=HibernateSessionFactory.getSession();
Transaction t=s.beginTransaction();
List sdata=s.createQuery("from StudForm").list();
//Object stud1=s.get(StudForm.class, new Long(sform.getSid()));
req.setAttribute("sdata", sdata);
t.commit();
return am.findForward("success");
 }
}

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>  
  <form-beans >
  <form-bean name="st" type="com.struts.hibernate.StudForm"></form-bean>
  </form-beans>
  <action-mappings >
  <action path="/store" name="st" type="com.struts.hibernate.StudentAction">
  <forward name="success" path="/result.jsp"></forward>
  </action>
  <action path="/view" name="st" type="com.struts.hibernate.ViewStudentAction">
  <forward name="success" path="/show.jsp"></forward>
  </action>
  </action-mappings>
  <message-resources parameter="com.struts.hibernate.ApplicationResources" />
</struts-config>

result.jsp

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />    
    <title>result page</title>  </head>  
  <body>  <center>
   <font color="Blue">
   <h1>Thank You.......  </h1><br>
    <h2>Student Registered Successfully with SID : <%=request.getAttribute("sid") %> </h2>
    </font>    
    <br>
    <H3><html:link action="/view">View All Details</html:link></H3>
   </center>
  </body>
</html:html>

show.jsp

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@page import="java.util.List"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>    <html:base />    
    <title>show details</title>  </head>  
  <body bgcolor="#ccccff">  <center>
    <table border="1">
  <tr bgcolor="#ffcc66">
<th>StudentID</th>
<th>StudentName</th>
<th>StudentCourse</th>
<th>FacultyName</th>
  </tr> 
   <logic:iterate id="s" name="sdata">
   <tr bgcolor="#ccffff">
<td><bean:write name="s" property="sid"/></td>
<td><bean:write name="s" property="name"/></td>
<td><bean:write name="s" property="course"/></td>
<td><bean:write name="s" property="fname"/></td>
  </tr>
  </logic:iterate>
  </table>
   </center>
  </body>
</html:html>







Wednesday, 3 July 2013

java softwares

JavaSE/JavaEE softwares downloads websites 
-----------------------------------
JDK Softwares
------------------------------------
 jdk6
------------
 http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html

 jdk7
------------
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

------------------------------
IDE's 
-----------------------------
Eclipse
---------------
http://www.eclipse.org/downloads/

NetBeans
--------------------------
https://netbeans.org/downloads/

MyEclipse(commercial)
-------------------------
http://www.myeclipseide.com/module-htmlpages-display-pid-4.html

----------------------------------
DATABASES
--------------------------------
Oracle
-----------------
http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

MySQL5.5
------------------
http://dev.mysql.com/downloads/mysql/5.5.html

-----------------------------------
SERVERS
-----------------------------------
Tomcat
--------------
http://tomcat.apache.org/download-70.cgi

Oracle Web Logic Server
----------------------------------
http://www.oracle.com/technetwork/middleware/weblogic/overview/index.html

JBoss
-----------------
http://www.jboss.org/jbossas/downloads

glassfish 3.x
-----------------------
http://www.oracle.com/technetwork/middleware/glassfish/downloads/java-archive-downloads-glassfish-419424.html

 glassfish server 4.0
--------------------------------
https://glassfish.java.net/download.html

TOOLS
------------------------------------------------------------------
ANT
http://ant.apache.org/bindownload.cgi

MAVEN
http://maven.apache.org/download.cgi

LOG4J
http://logging.apache.org/log4j/1.2/download.html

SELF4J
http://www.slf4j.org/download.html

Monday, 4 March 2013

j2ee / JavaEE

J2EE (JavaEE)


J2EE/JavaEE - Java 2 Enterprise Edition is one of the 3 java platforms, the other being J2SE and J2ME. It is set of specifications or standards consisting of many APIs useful for building java based enterprise applications. At such it is not some software to be installed but is just a bundle of many technologies having set of APIs.

J2EE is not a software but is a set of standards/specifications having APIs to make java enterprise app. Provides a standard for developing multi-tier enterprise services. It is useful for building apps that span over LAN, WAN and broader and needs to make use of its technologies. It is platform independent.
Business logic is organized into reusable components... so J2EE is helpful.
Layers are logical divisions of J2EE while tiers are physical partitions depending on number of computing systems used(discussed later in this).
The J2EE platform uses a multitiered distributed application model. Application logic is divided into components according to function, and the various application components that make up a J2EE application are installed on different machines depending on the tier in the multitiered J2EE environment to which the application component belongs.
They are used when it comes to distributed environment and disparate systems and also when it need to make use of its technologies.

J2EE technologies are broadly classified into two categories:
1. Component technologies
2. Service technologies

Kinds of J2EE Components:
Client Side Components’ -> includes applets.
Web Components -> includes servelets and JSPs
Business Components -> includes EJB
Web components and Business components run on Server Side...

Kinds of J2EE Services:
JNDI -> Java Naming and Directory service
JMS -> java Messaging Service
JTA -> Java Transaction API
JAAS -> Java Authentication and Authorization Service
Java Mail

J2EE is meant for building the 3 layers of java based enterprise application. The layers being:
1. Presentation Layer
2. Service/Business Layer
3. Data Access Layer      


We have been talking on java based enterprise application... To clear you on it:
A computer application used to manage business services of an enterprise is called enterprise application and if the application is coded in java and is deployed into J2EE compliant application server then it becomes java based.
Any enterprise application generally covers 4 main tasks:
1. Providing user interface(UI) to the user.
2. Processing of data according to some business logic(rules)
3. Interacting with database(data access)
4. Storing of data
These tasks are logically divided into 4 layers
                                     A. Presentation layer
                                     B. Business/Service layer
                                     C. Data Access Layer
                                     D. Data Layer      

                                
     

J2EE developers are responsible for the first 3 layers while the data layer is the responsibility of database administrator(DBA).  Remember they are just the logical division. Now coming to actual or physical division...
The physical partition of enterprise application is known as 'tier' .

The enterprise application can be single-tier, two-tier, three-tier, n-tier or distributed-tier depending on number of computing systems on which the layers are installed.

Let’s talk more on layers... 

Presentation Layer is the user interface part of the application. If the app is web based then Servelets and JSPs are used to build it on server side. The main design patterns used in this layer are Front Controller, Model-View-Controller(MVC), Composite View.

Business/Service Layer is nothing but a code that processes data according to business logic(rules). Some important design patterns used in this layer are Service Locator, Business Delegate, Session Facade. Job of service layer is to receive the business request from presentation layer or some other service layer, communicate with data access layer to get the enterprise data, process that data using defined business rules, return the result to the requested component.

Data Access layer is again a code which communicates with the database. It performs CRUD(Create, Read, Update, Delete). Therefore it is just a code communicating with database specific APIs such as JDBC.
The design patterns used are Data Access Object(DAO), Data Transfer Object(DTO), Value Object. 
Can you guess what its job is???

 It receives request from service layer, communicates with the database to perform the requested operations and sends the result back to service layer.

We already know what is the job of service layer but in order for it to implement it, it needs some capabilities... like transactional capability, distributed computing capability, security implementation capability.  
To have these capabilities we make use of J2EE technologies(both components and services). Just scroll up and read the first three paragraphs... This should make it clear for you.