Fred Stluka on 21 Mar 2007 18:18:01 -0000 |
PLUG folks, I got a direct e-mail query about Java in response to my previous posting, but it and my reply may be of general interest. If so, read on. If not, you know what to do... Since you seem knowledgeable/experienced with Java, I was wondering if you would mind if I followed up with you directly with a question or two about that programming language? I suggest you start at the Getting Started section of the Java Tips page at my web site. The links I posted to the PLUG list are complete examples of Hello World as an application, applet, and servlet, plus a slightly more complex JSP example. Each article is very short (1-2 screens of text) but contains the source code for a complete example, plus instructions on how to download and install any tools (Java compiler, Tomcat web server, etc.) you might need: http://bristle.com/Tips/Java.htm#applications http://bristle.com/Tips/Java.htm#applets http://bristle.com/Tips/Java.htm#servlets http://bristle.com/Tips/Java.htm#jsp_intro Yes, Java is very modular. Instead of having everything built into one massive monolithic hulk, there are modules you can pick and choose from to do what you need to do, without carrying along all the other baggage. They all work smoothly together, but you don't necessarily need all of them. Don't try to take it all on at once. Why bother? Just use what you need. It's easy to get started, and easy to add more later. Don't bother to dive into technologies that you haven't yet found a need for. I don't believe in using technologies just because they exist. Many of the latest fads you hear about are just "solutions looking for a problem to solve" -- useless! Java makes it very easy to use what you need and leave the rest behind. If someone challenges you, asking why you are not using some particular feature, get them to give you a detailed list of benefits, and decide whether any of them matter to your project. Again, you will find lots of people trying to sell you solutions for problems you don't have. Use what you need, and leave the rest. Learn Java in the same way that you read this e-mail message -- a piece at a time. Both are written very incrementally, and very modularly. If you start getting bored, you must have hit a solution that doesn't fit any of your current problems. Not of interest right now, so skip to the next paragraph, or stop reading entirely. Don't bother with things you don't need yet. Just be aware that there is more out there when you need it. Since you want to do Web development, start by just using Java servlets, until you see that it is tedious to wrap all of your HTML in print statements. Then add JSP pages to the mix, replacing those servlets that were mostly generating simple HTML, but continuing to use servlets for more complex things. For a concrete example of this, see: http://bristle.com/Tips/Java.htm#jsp_intro Then, perhaps learn some of the additional power of JSP. It does not do anything a servlet can't do, but it is often easier. JSTL is another step in the same direction. Nothing you couldn't do with a servlet or with JSP, but some things are again much easier. For JSP and JSTL info, see the series of short articles and summary sheets at: http://bristle.com/Tips/Java.htm#jsp http://bristle.com/Tips/Java.htm#jsp_directives http://bristle.com/Tips/Java.htm#jsp_scripting_elements http://bristle.com/Tips/Java.htm#jsp_and_jstl_actions http://bristle.com/Tips/Java.htm#jsp_and_jstl_implicit_objects http://bristle.com/Tips/Java.htm#accessing_properties_of_objects_in_jsp_and_el http://bristle.com/Tips/Java.htm#el_convenience_objects http://bristle.com/Tips/Java.htm#enabling_el_expression_evaluation http://bristle.com/Tips/Java.htm#looping_through_cookies_in_jsp_and_el http://bristle.com/Tips/Java.htm#looping_through_parameters_in_jsp_and_el http://bristle.com/Tips/Java.htm#looping_through_headers_in_jsp_and_el If you need to access a relational database, start using the JDBC classes: http://bristle.com/Tips/Java.htm#jdbc Along the way, you'll start to hear about Java Beans. Stop to read the two-pager: http://bristle.com/Tips/Java.htm#java_beans and learn that you have been writing Java Beans all along. They are not huge complex things like Microsoft ActiveX objects. In fact, the following is the complete source code for a trivial JavaBean: public class BeanWithNoProperties {} They are just as powerful as ActiveX objects, but much simpler, since all of the "discoverability" is already built in to the Java language. All you have to do is follow a couple of simple conventions about how you name your methods. At some point, you'll want to automatically generate your API documentation from your code, producing docs like: http://bristle.com/Tips/javadocs/index.html Want to generate such a set of docs with minimal effort? The javadoc tool comes for free with the free Java compiler, so it is already installed and ready go on your computer. Just type: javadoc *.java as described in: http://bristle.com/Tips/Java.htm#javadoc_intro For a description of the layout and contents of the generated docs, see: http://bristle.com/Tips/Java.htm#javadoc_default Want more detailed docs, based on the comments in your Java code, not just on your Java code itself? See: http://bristle.com/Tips/Java.htm#javadoc_comments Want the docs to contain even more detail about each method (descriptions instead of just names of each parameter, return value and exception)? See: http://bristle.com/Tips/Java.htm#javadoc_tags For a complete small example, see: http://bristle.com/Tips/Java.htm#javadoc_example Want more control over which portions of the docs are included/omitted, or the format of the generated pages? See: http://bristle.com/Tips/Java.htm#javadoc_cli http://bristle.com/Tips/Java.htm#javadoc_formatting http://bristle.com/Tips/Java.htm#javadoc_doclet If you: - Are planning a large Web application and want the benefit of a formal Model-View-Controller architecture to separate your user interface from your business logic, or - Find it tedious and clunky to have each JSP page or servlet hardcoded to know the name of the next JSP page or servlet in your workflow, or - Want a way to separate the presentation tier (JSP pages) from the business logic so that human factors people can do one and Java programmers can do the other, or - Are just getting tired of writing lots of tedious repetitive code to check user input fields for errors and show error messages to the user you may want to look into the Struts library. See links to lots of Struts info at my links page: http://bristle.com/~fred/#java_struts If you want a more object-oriented, less HTML-centric user interface, consider JavaServer Faces (JSF, not just JSP). See my links at: http://bristle.com/~fred/#java_jsf If you are writing a lot of JDBC code for database access, you may prefer to use Hibernate: http://www.hibernate.org/ or EJBs (Enterprise JavaBeans): http://bristle.com/~fred/#java_ejb If you are writing a huge application that has to manage thousands of instances of each object in memory at the same time, and run on multiple Web and application servers in a server farm, that's another reason to look into EJBs. If you want a more lightweight architecture, but still want the benefits of an "inversion of control" framework to automatically instantiate your Java Beans, and offering dependency injection, service abstractions, and aspect oriented programming (AOP), you may want to look into the Spring framework: http://www.springframework.org/ Each of these increments is compatible with all of the others. Mix and match as you like. Use what you need and leave the rest. You also mentioned Tomcat and web containers. If you are going to write a Java web app, you're going to be writing servlets and/or JSPs, so you're going to need a "servlet container" (a Web server that knows how to run Java servlets and JSPs). Tomcat is the official reference implementation of such a container, and is free. Download it, unzip it, and run it. No install required. BTW, if you want some personal one-on-one tutoring in any of these areas, I am available at an hourly rate. Again, incremental -- pay for one hour and then decide if you got enough value to justify paying for another hour. When you don't need any more, stop. Use what you need and leave the rest. --Fred -------------------------------------------------------------------------- Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/ Bristle Software, Inc -- http://bristle.com -- "Glad to be of service!" -------------------------------------------------------------------------- ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|