Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Newsletter
Enter your email address to receive full length articles at Stardeveloper:


Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  ADO (16)
  ADO.NET (11)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article
Stardeveloper RSS Feed
Hosted by Securewebs.com
 
Home : .NET : ASP.NET : Migration from J2EE to .NET
 
RSS - Read full length articles at Stardeveloper using Stardeveloper RSS Feed RSS

Migration from J2EE to .NET

by vivek devarajan.

Overview
Hi all, here are some quick tips to get you started, in case you need to migrate a J2EE based application to a .NET based application.

We approach the migration tier wise. Firstly, a technology mapping between both the platforms :--

Service or Feature .NET J2EE
GUI WinForms SWING & AWT
Web GUI ASP.NET JSP
Web Scripting ISAPI, HttpHandler, HttpModule Servlet, Filter
Server Side Business Logic Component Serviced Component (COM+) EJB Session Beans
Server side Data component Serviced Component (COM+) with DB Logic EJB BMP Entity Beans
Server Side Data Component Object Spaces EJB CMP Entity Beans
Naming ADSI JNDI
Remote Invocation .NET Remoting RMI or RMI-IIOP
Data Access ADO.NET JDBC
Messaging MSMQ JMS
Transactions COM+ or MTS JTA

Highlights of the migration strategy

  1. Presentation Tier JSP -> ASP.NET
  2. Business Logic Tier EJB -> COM+ (.NET Enterprise Service)
  3. Data Access Tier JDO/JDBC -> ADO.NET

i. Presentation tier migration

  1. JSP -> ASP .NET (sample code snippets)

    JSP scriptlet :--
    <!--Scriptlet--> 
    
    <%
    	for(int i = 0; i < 3; i++) {
    		out.println(i + "<br>"); 
    	}
    %>
    ASP .NET scriptlet :--
    <!--Scriptlet-->
    <%
    	for(int i = 0; i < 3; i++) {
    		Response.Write(i + "<br>");
    	}
    %>
    JSP expression :--
    <%= new java.math.BigDecimal(10.1).negate() %>
    ASP .NET expression :--
    <%= System.Decimal.Negate(new System.Decimal(10.1)) %>
    JSP declaration :--
    <%!
    	public String foo() {
    		return "foo";
    	}
    %>
    ASP .NET declaration :--
    <script runat="server" language="c#">
    	public virtual string foo() 
    	{
    		return "foo";
    	} 
    </script>
  2. Implicit objects :--

    JSP ASP .NET
    application Application
    session Session
    request Request
    response Response
    out Response.Write

  3. Cookies :--

    Creating a cookie and setting its expiry time.

    Code in J2EE :--
    <%
    	Cookie userCookie = new Cookie("user", "uid123");
    	userCookie.setMaxAge(60*60*24*365); // 1 year
    	response.addCookie(userCookie);
    %>
    Code in .NET :--
    <%
    	System.Web.HttpCookie userCookie = 
    		new System.Web.HttpCookie("user", "uid123");
    	System.DateTime dateTime = System.DateTime.Now;
    	System.TimeSpan timeSpan =
    		new System.TimeSpan(0, 0, 60*60*24*365); // 1 year
    	
    	cookie.Expires = dateTime.Add(timeSpan);
    	Response.Cookies.Add(userCookie); 
    %>
  4. Beans :--

    Java code :--
    public class Bean1 {
    
    	private String text = "Hello";
    	
    	public Bean1 () {}
    	
    	public String getText() {
    		return this.text;
    	}
    	
    	public String setText(String text) {
    		this.text = text;
    	}
    }
    C# code :--
    using System; 
    
    public class Bean1{
    
    	private string text = "Hello";
    	
    	public Bean1() {} 
    
    	public string Text
    	{
    		get { return text; }
    		set { text = value; }
    	}
    }
  5. Converting Servlets to ASP .NET code behind :--

    Servlet sample code :--
    import javax.servlet.*; 
    import javax.servlet.http.*;
    
    import java.io.*;
    
    public class SimpleServlet extends HttpServlet {
    
    	public void doGet(HttpServletRequest request, 
    			HttpServletResponse response)
    			throws ServletException, java.io.IOException {
    		
    		response.setContentType("text/html");
    		PrintWriter out = response.getWriter();
    		
    		out.println("<html><body>");
    		out.println("Simple Servlet Body");
    		out.println("</body></html>");
    		
    		out.close();
    	}
    }
    ASP .NET code-behind sample :--
    using System; 
    using System.Web; 
    using System.Web.UI; 
    
    public class SimpleServlet : System.Web.UI.Page
    {
    	private void Page_Load(object sender, EventArgs args)
    	{
    		Response.ContentType = "text/html";
    		
    		Response.Write("<html><body>");
    		Response.Write("Simple Servlet Body");
    		Response.Write("</body></html>");
    	}
    }
  6. Tag Library :--

    JSP ASP .NET
    Tag Handler Class
    JSP Tag Library Descriptor
    JSP Tag Library Directive
    ASP.NET Web User Controls
    ASP.NET Web Custom Control

    JSP tag lib Sample code :--
    <!– JSP --> 
    <!– the source file is specified in the TLD --> 
    
    <%@ taglib uri="taglib.tld" prefix="tags" %> 
    
    <tags:sample />
    ASP .NET tag lib Sample code :--
    <!– ASP.NET --> 
    
    <%@ Register TagPrefix="tags" TagName="sample"
    	Src="ExampleTag.ascx" %> 
    
    <tags:sample id="mySample" runat="server" />
  7. Converting Java Applets to .NET Winforms control :--

    Applet code :--
    package helloWorldPackage; 
    
    public class HelloWorld extends Applet {
    
    	public void paint(Graphics g) {
    		g.drawString(getParameter("parameter1"), 25, 25);
    	}
    	
    	public void init() {}
    	public void start() {}
    	public void stop() {}
    }
    .NET Winforms code :--
    namespace HelloWorldPackage
    {
    	public class HelloWorld : System.Windows.Forms.UserControl
    	{
    		string parameter1;
    		bool isActive;
    		
    		public HelloWorld()
    		{
    			init();
    		}
    		
    	protected override void OnPaint(PaintEventArgs e)
    	{
    		e.Graphics.DrawString(parameter1, Font,
    			new SolidBrush(ForeColor), 25, 25);
    	}
    	
    	public void init()
    	{
    		this.GotFocus +=
    			new EventHandler(this.helloWorldControl1_Start);
    		this.LostFocus +=
    			new EventHandler(this.helloWorldControl1_Stop);
    	}
    }

 ( 1 Remaining ) Next

Comments/Questions

No Comments Found.


Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.