Introduction to Java

Introduction

Java can be a bit confusing because you can use this language in different environments:

Note: Java and JavaScript are not the same thing. JavaScript looks somewhat like Java, but this is a small scripting language whose source-code is embedded in web pages, before being downloaded and interpreted on the client host.

Once in the Virtual Machine, the bytecodes are interpreted by the Intepreter, or optionally turned into machine code by the just-in-time (JIT) code generator, known more commonly as the JIT Compiler. The Interpreter and JIT Compiler operate in the context of the runtime system (threads, memory, other system resources). Any classes from the Java Class Libraries (API) are dynamically loaded as needed by the applet.

Servelts are a more efficient, alternative to CGI calls, as servelts are kept loaded in the JVM.

When a JSP page is called, it will be compiled (by the JSP engine) into a Java servlet. At this point the servlet is handled by the servlet engine, just like any other servlet. The servlet engine then loads the servlet class (using a class loader) and executes it to create dynamic HTML to be sent to the browser. The servlet creates any necessary object, and writes any object as a string to an output stream to the browser. The next time the page is requested, the JSP engine executes the already-loaded servlet unless the JSP page has changed, in which case it is automatically recompiled into a servlet and executed.

Tomcat: Sun's recommended server for JSP development, Tomcat takes care of parsing JSP pages and also provides a servlet engine for Java servlets

JServ is an Apache loadable module that serves as the all-important connection between the Tomcat and Apache servers

Most application servers also contain a Web server, meaning you can consider a Web server a subset of an application server. While application servers contain Web server functionality, developers rarely deploy application servers in that capacity. Instead, when needed, they often deploy standalone Web servers in tandem with application servers. Such a separation of functionality aids performance (simple Web requests won't impact application server performance), deployment configuration (dedicated Web servers, clustering, and so on), and allows for best-of-breed product selection.

Java is most visible on the client side of the Web, in the form of applets running in Web browsers. However, Java is also very useful on the server side. A servlet is a Java program that is meant to be executed by a Web server. This is similar to the way that applets are executed by a Web browser. If a Web server is capable of executing servlets, then its capabilities can be extended indefinitely by writing new servlets for it. Java is certainly not the only programming language used in this way, but it is an attractive choice because of its security, network-awareness, and large collection of APIs.

The task of writing dynamic Web pages can be simplified by using Java Server Pages (JSP) instead of servlets. A Java server page is an HTML file with some Java code embedded in it. When a Web server receives a request for the page, the Java code is executed to generate the dynamic part of the page. JSP is used on many Web sites. You can recognize a JSP page because the file name for the page will end with ".jsp". Servlets and JSP are not part of the standard edition of Java, J2SE, but they are included in the enterprise edition, J2EE.

JSP = ASP = PHP

Java actually has two complete sets of GUI components. One of these, the AWT or Abstract Windowing Toolkit, was available in the original version of Java. The other, which is known as Swing, is included in Java version 1.2 or later. The AWT (Abstract Windowing Toolkit) has been part of Java from the beginning, but, almost from the beginning, it has been clear that the AWT was not powerful or flexible enough for writing complex, sophisticated applications. The Swing graphical user interface library was created to address the problems with the AWT. With the release of Java version 1.2, Swing became an official part of Java. (Versions of Java starting with 1.2 are also called, rather confusingly, "Java 2.") There are still good reasons to write applets based on the AWT, such as the lack of support in many Web browsers for Java 2.

Java programs are supposed to work on any computing platform. Ideally, they should have the right look-and-feel for the platform where they are running. In Swing, this is made possible by pluggable look-and-feel, or PLAF.

The Java Native Interface (JNI)

If an applet uses a lot of .class files, it's a good idea to collect all the .class files into a single .zip or .jar file.

JavaBeans vs. Enterprise Java Beans (EJB)?

JavaBean is a component that can be combined with other components to make a complete program. JavaBeans are objects, not classes. Many JavaBeans are GUI components, but this is not a requirement and a JavaBean might have no visual representation at all. Objects belonging to Java's standard GUI component classes are JavaBeans and can be used in visual development environments.

Java has support for two types of distributed object computing. RMI (Remote Method Invocation) is used for communication between two Java objects running on different computers. Java also supports CORBA (Common Object Request Broker Architecture), a standard that allows communication between objects written in different programming languages.

You want to download the "J2SE 1.4 SDK." This is the "Java 2 Platform Standard Edition Version 1.4 Software Development Kit." This package includes a Java compiler, a Java virtual machine that can be used to run Java programs, and all the standard Java packages. You want the "SDK", not the "JRE". The JRE is the "Java Runtime Environment." It only includes the parts of the system that are need to run Java programs. It does not have a compiler. You'll also see the "J2EE SDK." This is the "Enterprise Edition," which includes additional packages that are not needed on a personal computer. Don't forget to read and follow the installation instructions.

Java Foundation Classes (JFC) : The Java Foundation Classes (JFC) are a comprehensive set of GUI components and services which dramatically simplify the development and deployment of commercial-quality desktop and Internet/Intranet applications. The Java Foundation Classes are a superset that contains AWT. JFC extends AWT by adding many components and services.

If you've worked with Java servlets you know that servlets allow you to create dynamically-generated web pages that include data from server-side Java objects. But you also know that the servlet approach to generating web pages is to embed HTML tags and presentation code within a Java class. This means that changes to presentation code requires modification and recompilation of the servlet source file. Because web authors who design HTML pages may not be the same folks as the developers who write servlet code, updating servlet-based web applications can be an involved process.

Enter JavaServer Pages, which are an extension of the Servlet API. In fact, JSP pages are compiled into servlets before they are used, so they have all of the benefits of servlets, including access to Java APIs. Because JSP pages are generally presentation code with application logic embedded in them, they can be thought of as "inside-out" servlets.

Setup

Web development with Java

Jetty

http://jetty.mortbay.org/jetty/

Orion

http://www.orionserver.com/

WyonaCMS

http://www.wyona.org/

OpenCMS

Tapestry

JBoss

Tomcat

Jakarta Jetspeed

Cocoon

Apache offshoot. http://xml.apache.org/cocoon/

OpenACS

Redhat's CCM

Formerly ArsDigita's tool. http://ccm.redhat.com/ . J2EE-based, and GPLed

Enhydra

Q&A

What's the difference between applets, servlts, and JSP pages?

What is the difference between Jakarta and Tomcat?

Why should I run Tomcat behind a web server instead of using it as a stand-alone web server?

JRun, JetSpeed, JServ?

JServ is Apache's servlet module.

Strut?

An open-source framework for building web applications.

J2EE?

EJB?

Enterprise JavaBean

Java Beans?

Resources

Temp

> 1. What do I need to write web applications in addition to the JDK and a web server?

1. You need the JDK and a J2EE compatible java web server - Tomcat is ideal for beginning development.

> 2. What does a servlet engine actually do : load compiled java apps when called from JSP?

2. Take a look at

> 3. What is Tomcat, really? A servlet engine? A JSP engine?

3. Tomcat is a J2EE compliant servlet engine. A JSP is basically a HTML page with java in it that get translated and compiled down to a servlet.

> 4. I understand Tomcat has its own web server. Is it good enough for  professional use, or should I use it only as a servlet engine (if that's what it is)?

4. Depends on what you need. Some people use it. If you can pay then look at WebSphere, WebLogic, JRun and the rest of the commercial crop.

> 5. What are JRun, JetSpeed, and JServ?

5. JRun is a commercial J2EE server. It has web, EJB, etc... JetSpeed is an open source portal implementation. JServ is an open source Servlet/JSP engine, but it's no longer being enhanced - it's the forerunner to Tomcat.

> 6. What are JavaBeans and EJB?

6. JavaBeans are java classes that correspond to a spec of parameterless constructor and getter/setter methods in a defined format. EJB are enterprise level, managed Java software components.

Take a look at

http://jakarta.apache.org/tomcat/index.html  - info on Tomcat

http://java.sun.com/j2ee/faq.html  - for info on J2EE (EJB, JMS, JDBC, Servlet/JSP, etc.)

http://java.sun.com/j2ee/1.3/docs/  - J2EE 1.3 documention - with tutorials

> 1. Que dois-je installer sur un serveur en plus du JDK ou JRE et un serveur web?

pour faire quoi ? un tomcat ou un jboss (ou autre serveur d'applications) si tu veux faire tourner des applications d'entreprise...

> 2. A quoi sert un moteur de servlet : c'est une sorte de module à qui le serveur web envoie toute requête ds un fichier JSP pour faire exécuter un programme Java?

si tu connais ASP ou PHP tu comprendras le probleme... il s'agit de donner une interface Web (HTTP) a des applications Java...

> 3. A quoi sert Tomcat?  

c'est un servlet engine /moteur de JSP...

> 4. Tomcat peut également servir de serveur Web?

en effet

> Dans quel cas est-il préférable de l'utiliser derrière un serveur web?

pour des raisons de perf, de stabilite et d'existant (modules apache) et  de securite aussi...

> 5. Que sont JRun, JetSpeed, et JServ?

Jrun est un produit concurent de tomcat, JSERV est un vieux module sans  utilité aujourd'hui...

> 6. Différence entre JavaBeans et EJB?

cherches dans les archives du NG, trop long :)

> 7. Y a-t-il un équivalent Java de Zope? Je pense notamment à sa capacité d'acquisition, c.a.d. un outil basé sur une base de données objet.

tu veux publication de documents ? oui des choses du type cocoon et autres

JRun, JBoss, JetSpeed, Tomcat, (outdated) JServ

Using Java Web Start technology, standalone Java software applications can be deployed with a single click over the network. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java Runtime Environment (JRE).