Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Java as a Web App

Okay, I know that Java is a language but somebody has asked me if they can write a web application to interface in with a web app I've written in ASP.NET. I'm implementing a web service to serve up an XML so it's pretty language agnostic.

However, I'm not 100% sure whether going down the Java route makes a lot of sense. I was kind of expecting PHP or ASP.NET server side code with maybe some Ajax/JavaScript or maybe a heavier client JavaScript program using JScript.

Could someone please explain the basic Java environment when it comes with webapps? I've inferred the following - am I barking up the right tree?

  • Java when run like ASP.NET is called JSP
  • JavaBeans is a bit like the .NET framework, i.e. it's a library of re-usable components
  • Java EE is a bit like ASP.NET in that it's a framework for building web pages on a server
  • Java can also run on the client but it needs the Java VM installing

When running Java on the client, can you use JavaBeans and is there a framework? Can it also use JScript? I don't think so as JScript is JavaScript library.

While running Java on the server would be okay, this is a relatively small application and therefore Java sounds like a bit of overkill. PHP or ASP.NET feels a better fit.

But I don't think they should go down the Java applet in the browser and it adds complexity that's not needed.

like image 820
Rob Nicholson Avatar asked Aug 05 '09 12:08

Rob Nicholson


2 Answers

Let's try to define some terms (not necessarily 100% exact, but understandable)

  • Java: can be a lot of things: The language, the JVM, the platform, the idea, ...
  • Java SE: Java Standard Edition: "normal" Java as it is used to run desktop applications. This has formerly been known as "Java 2 SE" and "J2SE".
  • Java EE: Java Enterprise Edition. The enterprise-level stack for developing web applications and other more complex beasts (contains tons of components). This has formerly been known as "Java 2 EE" and "J2EE".
  • JSP: Java Server Pages. A language that allows mixing HTML/XML content with Java Scriptlets. Pretty much equivalent to ASP.NET.
  • Java Beans (note: not "JavaBeans"): a rather light-weight specification that just describes how classes should be written so that their properties and methods can be automatically discovered. Not to be confused with Enterprise Java Beans (EJB)
  • Enterprise Java Beans / EJB: The much, much more complex bigger brother of Java Beans. Allows you to encapsulate some parts of your application. Terribly complex and cumbersome to use (got a bit better in recent versions, but that change seems to have come to late).

JScript is the Microsoft dialect of JavaScript and has nothing at all to do with Java.

By the way, JavaScript doesn't have anything to do with Java either. The only similarities are the first 4 characters of their name and a superficial similarity in syntax.

So basically: if they want to write a Java application to interface with your application that simply provides some XML, then Java is definitely suited for this. You don't need any of the Java EE technologies for this. Java SE is more than enough for this.

Edit: Note that it is a fairly common practice to not use the entire Java EE stack for (small-ish) web applications. Specifically Apache Tomcat, which is widely-used, is not a full Java EE Server (as required by the Java EE specification), but rather an implementation of the JSP and Servlet standards (two core parts of Java EE). It still runs many, many useful Java web applications just fine, because they simply don't use the more complex features of Java EE.

like image 50
Joachim Sauer Avatar answered Sep 20 '22 13:09

Joachim Sauer


Java when run like ASP.NET is called JSP

This is sort of true - a traditional JSP page is a lot like a classic ASP page. There's no "codebehind" like you have with ASPX.

The big difference in Java is that the web framework is based around things called servlets. A servlet is a bit like a ASP.NET "axd" in that it handles raw HTTP requests (get, post, etc) and spits out a response.

On top of that servlet "base" are many other frameworks - JSP is one of them (JSPs are ultimately compiled by the server into servelets). JSF, Struts, Tapestry, and many others are also built on this base. In the .NET world you really have two choices - ASP.NET (.aspx pages with codebehind) or .NET MVC. Most of the Java web frameworks are more like .NET MVC, although (as I understand it) JSF is more like ASP.NET

JavaBeans is a bit like the .NET framework, i.e. it's a library of re-usable components

Not really. What you are thinking of is J2SE, which is the basic framework upon which all Java apps are built - has the collection classes, sockets, security, etc. etc. JavaBeans is just a specification for how to write DTO type objects (standard naming for getters and setters, etc.)

Java EE is a bit like ASP.NET in that it's a framework for building web pages on a server

This is more-or-less correct. J2EE is an extension of J2SE for doing web development (as well as EJB's which are a whole nother ball of wax that don't really have a direct equivilent in .NET)

Java can also run on the client but it needs the Java VM installing

Yes, this is true. Just like you can use .NET to develop desktop or web applications, you can use Java the same way. And in both cases, a runtime is required (whether thats the Java VM or the .NET framework)

As for your assessment about using Java vs. PHP vs. .NET, I've worked with all of them, and I would say Java is the most complex, but also very powerful for very large scale applications. PHP will be the easiest by far, and is great for small apps, but can get messy when things get bigger. ASP.NET has a pretty good balance. Quite a bit more complex than PHP, but also much more powerful.

like image 36
Eric Petroelje Avatar answered Sep 18 '22 13:09

Eric Petroelje