The Caboteria / Tech Web / ProgrammingTips / JavaNotes (revision 9)
(back to ProgrammingTips)

Java is a popular programming language written by Sun Microsystems. It's an object-oriented language that runs inside a "virtual machine" which, at least in theory, allows code to run on many different machines. Sun calls this "Write once, run anywhere", and in practice it actually works reasonably well, although it took years for this to happen.

Java is extremely popular in commercial software development - it's dominant in the area that I work in: operations support software for communications companies. It's not at all popular in the Free Software community because it's a proprietary product owned and controlled by Sun.

The Java home page is http://java.sun.com/; you can download a developer kit or run-time from there. Java per se is a proprietary product, but there are many free projects that aim to provide all (or part) of the Java environment as Free Software. http://www.dwheeler.com/java-imp.html lists many of those projects.

See also: JavaProgrammingBookmarks, JbossTips

Books

Bruce Eckels Thinking in Java

Nutshell

Development Tools

building: ant - "like make only without make's wrinkles"

modelling: argouml - a UML modelling tool that can generate Java skeletons.

debugging: jswat

database access: isql, squirrelsql

Infrastructure

tomcat - servlet engine, jboss - j2ee container, openejb - ejb container, avalon - server framework, maverick - presentation framework

Libraries

trace logging: log4j

Coding Conventions

Use Sun's http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html and override what you feel is wrong. Personally, I feel that the 80 column constraint is too limiting; I prefer to allow people to use 132 column line widths.

When something is an identifier, and you feel that you must append "Id" in some form to the name, use ID not Id. It's easier to type and reflects that most people call it an "eye-dee" not an "id".

When a class has a member variable that holds multiple items, don't make a setFoo(Collection foos) method, make an addFoo(Foo foo) method instead. Maintain the collection (or set or whatever) internally. The difference is that there's some type checking in the second approach whereas the first approach lets the client pass a Collection full of anything in. It's also often more convenient for the client to call add() a few times rather than create their collection, fill it, and then set() it. If they want to look at it you can return either a collection/set/list (some interface) or you can return an iterator of some sort.

Misc

Here's a cute hack to enable token substitution in java property files: http://www.sys-con.com/java/source.cfm?id=1228

Using Java on Debian GNU/Linux

When I tried to run Sun's JDK 1.3.1 on Debian Sid (in March 2002) I got the following error: /home/tcabot/local/Linux/jdk/bin/i386/native_threads/java: error while loading shared libraries: libstdc++-libc6.1-1.so.2: cannot open shared object file: No such file or directory. This can be solved by linking to the existing libstdc++, i.e. ln -s /usr/lib/libstdc++-libc6.2-2.so.3 /usr/lib/libstdc++-libc6.1-1.so.2.

Java is a proprietary language (controlled by Sun) but there are a few Free implementations of the compiler, JVM, and class libraries. If you're running a new version of Debian you can apt-get gcj and kaffe.

$ gcj -C HelloWorldApp.java
$ kaffe -addclasspath . HelloWorldApp

Java is very resource-intensive: cpu, memory, and processes. So you might bump into the limits that Unix uses to limit individual user resource consumption. An important one is max user processes which you can see if you run ulimit -a. You probably want to bump this up to 1020 or so: ulimit -u 1020. Other limits that you might bump into are SHMMAX and SHMANY which you can set using files in /proc/sys/kernel/ or by setting values in /etc/sysctl.conf.

-- TobyCabot - 28 Dec 2001-31 May 2002

Edit | Attach | Print version | History: r36 | r11 < r10 < r9 < r8 | Backlinks | Raw View | Raw edit | More topic actions...
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding The Caboteria? Send feedback