Difference: JavaNotes (1 vs. 36)

Revision 3609 Mar 2015 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 78 to 78
  public class date { public static void main(String[] argv) throws java.io.IOException {System.out.println(new java.util.Date()); }}
Added:
>
>
Make sure that /etc/sysconfig/clock is correct. The ZONE value should point to a valid file in /usr/share/zoneinfo.
 

Arrays vs Collections

Why don't people use arrays in Java? It seems to me that people get so excited about Collection, Set, List etc that they forget about arrays. Arrays have some definite issues, but they also have some advantages. Arrays are fixed-length so they're not good if you're not sure how many things that you're going to put into them in advance. Their big advantage (which limits their use) is that they're strongly typed. This can be an advantage in many cases, i.e. where you've got a bunch of the same thing. In this case an array is nice because it enforces type safety in a way that a Collection doesn't.

Revision 3506 Aug 2009 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 32 to 32
  database access: http://www.squirrelsql.org/ - good, not great, database browser in Swing.
Changed:
<
<
Java Development Environment for EMACS - http://jdee.sunsite.dk/
>
>
Java Development Environment for EMACS - http://jdee.sf.net/
  A Source Measurement Suite for Java - http://www.kclee.com/clemens/java/javancss/

Revision 3417 Jun 2008 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 95 to 95
  There was another implementation but it seems to have fallen off the net. Google had cached entries for a package called TCE/Java at http://www.voicenet.com/~hsk0/tce/ but it seems to have fallen off the net. The guy that wrote it is Howard Kapustein, maybe he'll show up again.
Added:
>
>
Update - it's not just a Java problem, since it's inherent to binary representations of fractions. In fact, people have died because of this problem: http://www.ima.umn.edu/~arnold/disasters/patriot.html
 

XML Event-based Parsing

http://cafeconleche.org/books/xmljava/ - looks like a good starter book.

Revision 3317 Apr 2008 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 160 to 160
 

Debugging

Changed:
<
<
JSwat's not bad.
>
>
JSwat's not bad: http://jswat.sourceforge.net/
  How to connect a debugger to a running JVM: http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/idebug/help/en_US/debug390/tasks/tb3attjv.htm
Changed:
<
<
-- TobyCabot - 28 Dec 2001 - 10 Nov 2003
>
>
How to run a JVM in debug mode: http://java.sun.com/products/jpda/doc/conninv.html - e.g. -agentlib:jdwp=transport=dt_socket,server=y,address=8000
 
META TOPICMOVED by="guest" date="1088797898" from="Tech.JavaTips" to="Tech.JavaNotes"

Revision 3219 Dec 2007 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 38 to 38
 

Infrastructure

Changed:
<
<
Java application servers are available from a bunch of commercial vendors like Sun, IBM, BEA, Oracle, etc but there are some compelling open source options, too. They tend to work well, and the price is right, but the documentation is often weak.

J2EE: JBoss http://www.jboss.org/ is the leading open-source "J2EE" container. I put "J2EE" in quotes because it's Sun's trademark and JBoss has not yet been certified compliant with the spec, although that's in process. JBoss works well but the documentation (even the stuff you pay for) is weak. It comes with an integrated Tomcat servlet container so it's a good way to get started with J2EE.

>
>
Java application servers are available from a bunch of commercial vendors like Sun, IBM, BEA, Oracle, etc but there are some compelling open source options, too. They tend to work well, and the price is right, but the documentation is often weak. See JavaProgrammingBookmarks#EJB_Containers.
  Servlet: Tomcat http://jakarta.apache.org/tomcat/ is the reference implementation of Servlets and JSP. I've used it standalone and integrated with JBoss and it's pretty sweet. Back in the 3.x days it was slower than Jetty but I've heard that 5.x is comparable.

Revision 3130 Jan 2007 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 34 to 34
  Java Development Environment for EMACS - http://jdee.sunsite.dk/
Added:
>
>
A Source Measurement Suite for Java - http://www.kclee.com/clemens/java/javancss/
 

Infrastructure

Java application servers are available from a bunch of commercial vendors like Sun, IBM, BEA, Oracle, etc but there are some compelling open source options, too. They tend to work well, and the price is right, but the documentation is often weak.

Revision 3030 Jan 2007 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 28 to 28
  modelling: argouml - a UML modelling tool that can generate Java skeletons.
Changed:
<
<
debugging: jswat, http://bocks.psych.purdue.edu/~pizman/PTDS/
>
>
debugging: jswat
  database access: http://www.squirrelsql.org/ - good, not great, database browser in Swing.
Added:
>
>
Java Development Environment for EMACS - http://jdee.sunsite.dk/
 

Infrastructure

Java application servers are available from a bunch of commercial vendors like Sun, IBM, BEA, Oracle, etc but there are some compelling open source options, too. They tend to work well, and the price is right, but the documentation is often weak.

Line: 154 to 156
  GCViewer - http://www.tagtraum.com/gcviewer.html a GUI that visualises the output of the JVM GC dump info.
Added:
>
>
PTDS - http://bocks.psych.purdue.edu/~pizman/PTDS/
 

Debugging

JSwat's not bad.

Revision 2930 Jan 2007 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 28 to 28
  modelling: argouml - a UML modelling tool that can generate Java skeletons.
Changed:
<
<
debugging: jswat
>
>
debugging: jswat, http://bocks.psych.purdue.edu/~pizman/PTDS/
  database access: http://www.squirrelsql.org/ - good, not great, database browser in Swing.

Revision 2814 Jul 2006 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 152 to 152
  JRat - http://jrat.sourceforge.net/ takes an interesting approach - you "instrument" your code after you build.
Added:
>
>
GCViewer - http://www.tagtraum.com/gcviewer.html a GUI that visualises the output of the JVM GC dump info.
 

Debugging

JSwat's not bad.

Revision 2706 Oct 2005 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 152 to 152
  JRat - http://jrat.sourceforge.net/ takes an interesting approach - you "instrument" your code after you build.
Added:
>
>

Debugging

JSwat's not bad.

How to connect a debugger to a running JVM: http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/idebug/help/en_US/debug390/tasks/tb3attjv.htm

  -- TobyCabot - 28 Dec 2001 - 10 Nov 2003

Revision 2616 Feb 2005 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 10 to 10
  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.
Changed:
<
<
See also: JavaProgrammingBookmarks, JHotDrawNotes, GeronimoNotes, PrevaylerNotes, JbossTips
>
>
See also: JavaProgrammingBookmarks, SwingNotes, JHotDrawNotes, GeronimoNotes, PrevaylerNotes, JbossTips
 

Revision 2510 Dec 2004 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 10 to 10
  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.
Changed:
<
<
See also: JavaProgrammingBookmarks, GeronimoNotes, PrevaylerNotes, JbossTips
>
>
See also: JavaProgrammingBookmarks, JHotDrawNotes, GeronimoNotes, PrevaylerNotes, JbossTips
 

Revision 2402 Jul 2004 - TWikiGuest

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 154 to 154
 

-- TobyCabot - 28 Dec 2001 - 10 Nov 2003

Added:
>
>
META TOPICMOVED by="guest" date="1088797898" from="Tech.JavaTips" to="Tech.JavaNotes"

Revision 2302 Jul 2004 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 10 to 10
  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.
Changed:
<
<
See also: JavaProgrammingBookmarks, JbossTips
>
>
See also: JavaProgrammingBookmarks, GeronimoNotes, PrevaylerNotes, JbossTips
 

Revision 2230 Jun 2004 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
(over to JavaProgrammingBookmarks)
Line: 93 to 93
  There was another implementation but it seems to have fallen off the net. Google had cached entries for a package called TCE/Java at http://www.voicenet.com/~hsk0/tce/ but it seems to have fallen off the net. The guy that wrote it is Howard Kapustein, maybe he'll show up again.
Changed:
<
<

XML Parsing

>
>

XML Event-based Parsing

  http://cafeconleche.org/books/xmljava/ - looks like a good starter book.
Line: 103 to 103
 

SAX Parser

Changed:
<
<
This is the old approach.
>
>
This is the old SAX 1.0 approach.
 

Property

Line: 116 to 116
 

XML Reader

Changed:
<
<
This is the new approach.
>
>
This is the SAX 2.0 approach.
 

Property

Line: 131 to 131
  parser = XMLReaderFactory.createXMLReader();
Added:
>
>

STaX

A "pull" approach where the application requests events from the parser. Need to check it out further. Intro at http://www.xml.com/pub/a/2003/09/17/stax.html .

 

Profiling

Revision 2109 Jun 2004 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
Added:
>
>
(over to JavaProgrammingBookmarks)
 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 that popular in the Free Software community because it's a proprietary product owned and controlled by Sun. There is a lot of "open source" development in Java, though.

Revision 2016 Mar 2004 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
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.
Changed:
<
<
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.
>
>
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 that popular in the Free Software community because it's a proprietary product owned and controlled by Sun. There is a lot of "open source" development in Java, though.
 
Changed:
<
<
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.
>
>
The Java home page is http://java.sun.com/; you can download a developer kit or run-time from there. If you're running on Linux and don't need the latest-and-greatest API then you can use the IBM JVM which I've found to be faster than Sun's: http://www6.software.ibm.com/dl/lxdk/lxdk-p

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
Added:
>
>
 

Books

http://www.mindview.net/Books/TIJ/ - Bruce Eckels Thinking in Java. I used Thinking in C++ to learn C++ and it was excellent, so it's likely that this book is, too.

Changed:
<
<
O-Reilly Nutshell Book
>
>
O'Reilly Nutshell Book. Nice to have, although I find that I use javadoc more and the book less these days.
 

Development Tools

Changed:
<
<
building: ant - "like make only without make's wrinkles"
>
>
building: http://ant.apache.org/ - "like make only without make's wrinkles." I can't remember the last time I worked on (or looked at) a Java project that built using make.

unit test: http://www.junit.org/ - "keep the light green to keep the code clean." I'm definitely test-infected, writing and running unit tests is becoming second nature.

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

debugging: jswat

Changed:
<
<
database access: isql, squirrelsql

Profiling

There are many expensive commercial tools for profiling Java programs while they're running, but since Java has the JVMPI interface pretty much anyone can hook into the JVM at run time and find out what's going on. This is another category of programs where there seem to be far too many half-baked efforts, but here are my notes from a few hours of fooling around with various tools.

Mike's Profiler - http://mjp.sourceforge.net/ looks promising, has actual documentation and the maintainer seems to be maintaining it on an ongoing basis. The GUI is easy to understand. Unfortunately it seems to run very slowly and crash before JBoss can fully boot up. NOTE - I need to test 0.06 which has a statistical sampling mode

JTreeProfiler - http://sourceforge.net/projects/jcoverage/ this one streams to an XML file on a per method invocation basis so it's probably unsuitable for anything but trivial profiling (booting JBoss wrote a 2.3GB file). The analysis GUI is interesting and very graphical but hard to make sense of.

>
>
database access: http://www.squirrelsql.org/ - good, not great, database browser in Swing.
 
Changed:
<
<
JPerfAnal - http://sourceforge.net/projects/jperfanal/ can you think of a more unfortunate name for a performance analysis tool? In any case this guy seems to have the right idea in that he reads the stock Sun profiler output so he doesn't need a platform-specific library to gather data. Unfortunately his GUI is lame and there's not one word of documentation.
>
>

Infrastructure

 
Changed:
<
<
Extensible Java Profiler - http://ejp.sourceforge.net/
>
>
Java application servers are available from a bunch of commercial vendors like Sun, IBM, BEA, Oracle, etc but there are some compelling open source options, too. They tend to work well, and the price is right, but the documentation is often weak.
 
Changed:
<
<
JMP - http://www.khelekore.org/jmp/ GTK GUI, written in C.
>
>
J2EE: JBoss http://www.jboss.org/ is the leading open-source "J2EE" container. I put "J2EE" in quotes because it's Sun's trademark and JBoss has not yet been certified compliant with the spec, although that's in process. JBoss works well but the documentation (even the stuff you pay for) is weak. It comes with an integrated Tomcat servlet container so it's a good way to get started with J2EE.
 
Changed:
<
<
JRat - http://jrat.sourceforge.net/ takes an interesting approach - you "instrument" your code after you build.
>
>
Servlet: Tomcat http://jakarta.apache.org/tomcat/ is the reference implementation of Servlets and JSP. I've used it standalone and integrated with JBoss and it's pretty sweet. Back in the 3.x days it was slower than Jetty but I've heard that 5.x is comparable.
 
Changed:
<
<

Infrastructure

>
>
MVC: At some point Sun declared that Smalltalk's "Model View Controller" was the right way to implement web user interfaces. Without getting into the discussion of what constitutes a "model" in a stateless environment, there are many frameworks to help you build web applications. http://jakarta.apache.org/struts/ Struts is by far the most popular, and is the only one I've seen with enough market share to become a resume buzzword. Many people aren't fond of Struts, which is one reason why there are so many me-too application frameworks. I'm fond of one called Maverick http://mav.sf.net/ which is very simple and elegant. It doesn't include a lot of what Struts does (form processing, validation, tag libraries, etc) but its basic flow is very cool - a simple XML file describes pipelines that start with a DOM-ified representation of Java objects and pass through multiple processing stages. It works well with XSLT.
 
Deleted:
<
<
tomcat - servlet engine, jboss - j2ee container, openejb - ejb container, avalon - server framework, maverick - presentation framework
 

Coding Conventions

Line: 71 to 68
  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.
Added:
>
>

IBM JVM on Linux

IBM's JVM 1.4.1 for GNU/Linux doesn't seem to recognize old-style timezone names. My /etc/localtime was a link to /usr/share/zoneinfo/US/Eastern and the JVM would never use daylight savings - it was always GMT+5. When I changed the link to /usr/share/zoneinfo/America/New_York it worked fine. See http://www.mainframeforum.com/t590240.html which seems to be relevant despite being a mainframe forum.

public class date { public static void main(String[] argv) throws java.io.IOException {System.out.println(new java.util.Date()); }}

 

Arrays vs Collections

Changed:
<
<
Why don't people use arrays in Java? It seems to me that people get so excited about Collection, Set, List etc that they forget about arrays. Arrays have some definite issues, but they also have some advantages. Arrays are fixed-length so they're not good if you're not sure how many things that you're going to put into them in advance. Their big advantage (which limits their use) is that they're strongly typed. This can be a big advantage in many cases, i.e. where you've got a bunch of the same thing. In this case an array is nice because it enforces type safety in a way that a Collection doesn't.
>
>
Why don't people use arrays in Java? It seems to me that people get so excited about Collection, Set, List etc that they forget about arrays. Arrays have some definite issues, but they also have some advantages. Arrays are fixed-length so they're not good if you're not sure how many things that you're going to put into them in advance. Their big advantage (which limits their use) is that they're strongly typed. This can be an advantage in many cases, i.e. where you've got a bunch of the same thing. In this case an array is nice because it enforces type safety in a way that a Collection doesn't.
  In summary, an array is the correct data structure to use where you have a known number of objects all of the same type.
Line: 127 to 130
 
Changed:
<
<

Misc Notes

>
>

Profiling

 
Changed:
<
<
IBM's JVM 1.4.1 for GNU/Linux doesn't seem to recognize old-style timezone names. My /etc/localtime was a link to /usr/share/zoneinfo/US/Eastern and the JVM would never use daylight savings - it was always GMT+5. When I changed the link to /usr/share/zoneinfo/America/New_York it worked fine. See http://www.mainframeforum.com/t590240.html which seems to be relevant despite being a mainframe forum.
>
>
There are many expensive commercial tools for profiling Java programs while they're running, but since Java has the JVMPI interface pretty much anyone can hook into the JVM at run time and find out what's going on. This is another category of programs where there seem to be far too many half-baked efforts, but here are my notes from a few hours of fooling around with various tools.

Mike's Profiler - http://mjp.sourceforge.net/ looks promising, has actual documentation and the maintainer seems to be maintaining it on an ongoing basis. The GUI is easy to understand. Unfortunately it seems to run very slowly and crash before JBoss can fully boot up. NOTE - I need to test 0.06 which has a statistical sampling mode

JTreeProfiler - http://sourceforge.net/projects/jcoverage/ this one streams to an XML file on a per method invocation basis so it's probably unsuitable for anything but trivial profiling (booting JBoss wrote a 2.3GB file). The analysis GUI is interesting and very graphical but hard to make sense of.

JPerfAnal - http://sourceforge.net/projects/jperfanal/ can you think of a more unfortunate name for a performance analysis tool? In any case this guy seems to have the right idea in that he reads the stock Sun profiler output so he doesn't need a platform-specific library to gather data. Unfortunately his GUI is lame and there's not one word of documentation.

Extensible Java Profiler - http://ejp.sourceforge.net/

JMP - http://www.khelekore.org/jmp/ GTK GUI, written in C.

JRat - http://jrat.sourceforge.net/ takes an interesting approach - you "instrument" your code after you build.

 
Deleted:
<
<
public class date { public static void main(String[] argv) throws java.io.IOException {System.out.println(new java.util.Date()); }}
  -- TobyCabot - 28 Dec 2001 - 10 Nov 2003

Revision 1911 Mar 2004 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingNotes"
Deleted:
<
<
(back to ProgrammingNotes)
 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.

Line: 12 to 10
 

Books

Changed:
<
<
Bruce Eckels Thinking in Java
>
>
http://www.mindview.net/Books/TIJ/ - Bruce Eckels Thinking in Java. I used Thinking in C++ to learn C++ and it was excellent, so it's likely that this book is, too.
 
Changed:
<
<
Nutshell
>
>
O-Reilly Nutshell Book
 

Development Tools

Line: 46 to 44
  tomcat - servlet engine, jboss - j2ee container, openejb - ejb container, avalon - server framework, maverick - presentation framework
Deleted:
<
<

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.

Line: 94 to 88
  There was another implementation but it seems to have fallen off the net. Google had cached entries for a package called TCE/Java at http://www.voicenet.com/~hsk0/tce/ but it seems to have fallen off the net. The guy that wrote it is Howard Kapustein, maybe he'll show up again.
Added:
>
>

XML Parsing

http://cafeconleche.org/books/xmljava/ - looks like a good starter book.

Java as of version 1.4 comes with a competent XML parser and XSLT transformer built in, but sometimes it's preferable to use a different one, for features or speed.

There are two ways that an application can get a parser so you need to either know which one you're trying to use or cover both.

SAX Parser

This is the old approach.

Property

  • javax.xml.parsers.SAXParserFactory
    • org.apache.xerces.jaxp.SAXParserFactoryImpl - value to use for Xerces (xercesImpl.jar on the classpath)

Code

http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/SAXParserFactory.html

XML Reader

This is the new approach.

Property

  • org.xml.sax.driver
    • org.apache.xerces.parsers.SAXParser - value to use for Xerces

Code

http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/helpers/XMLReaderFactory.html

				parser = XMLReaderFactory.createXMLReader();
 

Misc Notes

IBM's JVM 1.4.1 for GNU/Linux doesn't seem to recognize old-style timezone names. My /etc/localtime was a link to /usr/share/zoneinfo/US/Eastern and the JVM would never use daylight savings - it was always GMT+5. When I changed the link to /usr/share/zoneinfo/America/New_York it worked fine. See http://www.mainframeforum.com/t590240.html which seems to be relevant despite being a mainframe forum.

Revision 1817 Feb 2004 - TWikiGuest

Line: 1 to 1
Changed:
<
<
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
>
>
META TOPICPARENT name="ProgrammingNotes"
(back to ProgrammingNotes)
  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.

Revision 1710 Nov 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 83 to 83
  In summary, an array is the correct data structure to use where you have a known number of objects all of the same type.
Added:
>
>

Float sucks

Binary arithmetic (e.g. Java float) doesn't cut it when applied to money - it's not accurate on the right side of the decimal point. Java seems to have the answer in java.math.BigDecimal but from what I've seen on the web it's not a very good implementation.

IBM has proposed a replacement of the BigDecimal class, the website is at http://www2.hursley.ibm.com/decimalj/. The site does a great job of explaining why decimal arithmetic is better than binary and also has many interesting links. They also have an implementation available but it's under a very restrictive license, you can only use it for 90 days and then you must destroy it - there's no way to buy it, either.

The IBM page points to a commercial implementation of a BigDecimal class at http://users.belgacombusiness.net/arci/math/. It's not very expensive - 500 Euro (which is closer to $500 than those common-market pinkos would hope!). It claims to be fast and have good formatting features.

There was another implementation but it seems to have fallen off the net. Google had cached entries for a package called TCE/Java at http://www.voicenet.com/~hsk0/tce/ but it seems to have fallen off the net. The guy that wrote it is Howard Kapustein, maybe he'll show up again.

 

Misc Notes

IBM's JVM 1.4.1 for GNU/Linux doesn't seem to recognize old-style timezone names. My /etc/localtime was a link to /usr/share/zoneinfo/US/Eastern and the JVM would never use daylight savings - it was always GMT+5. When I changed the link to /usr/share/zoneinfo/America/New_York it worked fine. See http://www.mainframeforum.com/t590240.html which seems to be relevant despite being a mainframe forum.

public class date { public static void main(String[] argv) throws java.io.IOException {System.out.println(new java.util.Date()); }}

Changed:
<
<
-- TobyCabot - 28 Dec 2001 - 24 Jun 2003
>
>
-- TobyCabot - 28 Dec 2001 - 10 Nov 2003

Revision 1624 Jun 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 83 to 83
  In summary, an array is the correct data structure to use where you have a known number of objects all of the same type.
Changed:
<
<
-- TobyCabot - 28 Dec 2001-31 May 2002
>
>

Misc Notes

IBM's JVM 1.4.1 for GNU/Linux doesn't seem to recognize old-style timezone names. My /etc/localtime was a link to /usr/share/zoneinfo/US/Eastern and the JVM would never use daylight savings - it was always GMT+5. When I changed the link to /usr/share/zoneinfo/America/New_York it worked fine. See http://www.mainframeforum.com/t590240.html which seems to be relevant despite being a mainframe forum.

public class date { public static void main(String[] argv) throws java.io.IOException {System.out.println(new java.util.Date()); }}

-- TobyCabot - 28 Dec 2001 - 24 Jun 2003

Revision 1524 Jun 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 36 to 36
  JPerfAnal - http://sourceforge.net/projects/jperfanal/ can you think of a more unfortunate name for a performance analysis tool? In any case this guy seems to have the right idea in that he reads the stock Sun profiler output so he doesn't need a platform-specific library to gather data. Unfortunately his GUI is lame and there's not one word of documentation.
Added:
>
>
Extensible Java Profiler - http://ejp.sourceforge.net/
 JMP - http://www.khelekore.org/jmp/ GTK GUI, written in C.

JRat - http://jrat.sourceforge.net/ takes an interesting approach - you "instrument" your code after you build.

Revision 1409 Jun 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 30 to 30
  There are many expensive commercial tools for profiling Java programs while they're running, but since Java has the JVMPI interface pretty much anyone can hook into the JVM at run time and find out what's going on. This is another category of programs where there seem to be far too many half-baked efforts, but here are my notes from a few hours of fooling around with various tools.
Added:
>
>
Mike's Profiler - http://mjp.sourceforge.net/ looks promising, has actual documentation and the maintainer seems to be maintaining it on an ongoing basis. The GUI is easy to understand. Unfortunately it seems to run very slowly and crash before JBoss can fully boot up. NOTE - I need to test 0.06 which has a statistical sampling mode
 JTreeProfiler - http://sourceforge.net/projects/jcoverage/ this one streams to an XML file on a per method invocation basis so it's probably unsuitable for anything but trivial profiling (booting JBoss wrote a 2.3GB file). The analysis GUI is interesting and very graphical but hard to make sense of.

JPerfAnal - http://sourceforge.net/projects/jperfanal/ can you think of a more unfortunate name for a performance analysis tool? In any case this guy seems to have the right idea in that he reads the stock Sun profiler output so he doesn't need a platform-specific library to gather data. Unfortunately his GUI is lame and there's not one word of documentation.

Deleted:
<
<
Mike's Profiler - http://mjp.sourceforge.net/ looks promising, has actual documentation and the maintainer seems to be maintaining it on an ongoing basis. The GUI is easy to understand. Unfortunately it seems to run very slowly and crash before JBoss can fully boot up.
 JMP - http://www.khelekore.org/jmp/ GTK GUI, written in C.

JRat - http://jrat.sourceforge.net/ takes an interesting approach - you "instrument" your code after you build.

Line: 75 to 75
  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.
Changed:
<
<

Random Musings

>
>

Arrays vs Collections

  Why don't people use arrays in Java? It seems to me that people get so excited about Collection, Set, List etc that they forget about arrays. Arrays have some definite issues, but they also have some advantages. Arrays are fixed-length so they're not good if you're not sure how many things that you're going to put into them in advance. Their big advantage (which limits their use) is that they're strongly typed. This can be a big advantage in many cases, i.e. where you've got a bunch of the same thing. In this case an array is nice because it enforces type safety in a way that a Collection doesn't.

Revision 1321 May 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 36 to 36
  Mike's Profiler - http://mjp.sourceforge.net/ looks promising, has actual documentation and the maintainer seems to be maintaining it on an ongoing basis. The GUI is easy to understand. Unfortunately it seems to run very slowly and crash before JBoss can fully boot up.
Added:
>
>
JMP - http://www.khelekore.org/jmp/ GTK GUI, written in C.

JRat - http://jrat.sourceforge.net/ takes an interesting approach - you "instrument" your code after you build.

 

Infrastructure

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

Revision 1201 May 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 34 to 34
  JPerfAnal - http://sourceforge.net/projects/jperfanal/ can you think of a more unfortunate name for a performance analysis tool? In any case this guy seems to have the right idea in that he reads the stock Sun profiler output so he doesn't need a platform-specific library to gather data. Unfortunately his GUI is lame and there's not one word of documentation.
Changed:
<
<
>
>
Mike's Profiler - http://mjp.sourceforge.net/ looks promising, has actual documentation and the maintainer seems to be maintaining it on an ongoing basis. The GUI is easy to understand. Unfortunately it seems to run very slowly and crash before JBoss can fully boot up.
 

Infrastructure

Revision 1101 May 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 26 to 26
  database access: isql, squirrelsql
Added:
>
>

Profiling

There are many expensive commercial tools for profiling Java programs while they're running, but since Java has the JVMPI interface pretty much anyone can hook into the JVM at run time and find out what's going on. This is another category of programs where there seem to be far too many half-baked efforts, but here are my notes from a few hours of fooling around with various tools.

JTreeProfiler - http://sourceforge.net/projects/jcoverage/ this one streams to an XML file on a per method invocation basis so it's probably unsuitable for anything but trivial profiling (booting JBoss wrote a 2.3GB file). The analysis GUI is interesting and very graphical but hard to make sense of.

JPerfAnal - http://sourceforge.net/projects/jperfanal/ can you think of a more unfortunate name for a performance analysis tool? In any case this guy seems to have the right idea in that he reads the stock Sun profiler output so he doesn't need a platform-specific library to gather data. Unfortunately his GUI is lame and there's not one word of documentation.

 

Infrastructure

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

Revision 1020 Feb 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 40 to 40
  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".
Changed:
<
<
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.
>
>
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 array or iterator of some sort.
 

Misc

Line: 61 to 61
  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.
Added:
>
>

Random Musings

Why don't people use arrays in Java? It seems to me that people get so excited about Collection, Set, List etc that they forget about arrays. Arrays have some definite issues, but they also have some advantages. Arrays are fixed-length so they're not good if you're not sure how many things that you're going to put into them in advance. Their big advantage (which limits their use) is that they're strongly typed. This can be a big advantage in many cases, i.e. where you've got a bunch of the same thing. In this case an array is nice because it enforces type safety in a way that a Collection doesn't.

In summary, an array is the correct data structure to use where you have a known number of objects all of the same type.

 -- TobyCabot - 28 Dec 2001-31 May 2002

Revision 903 Feb 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 40 to 40
  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".
Added:
>
>
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

Revision 830 Jan 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 34 to 34
  trace logging: log4j
Added:
>
>

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".

 

Misc

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

Revision 714 Nov 2002 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 8 to 8
  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.
Changed:
<
<
See also: JavaProgrammingBookmarks
>
>
See also: JavaProgrammingBookmarks, JbossTips
 

Books

Revision 631 May 2002 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
(back to ProgrammingTips)
Line: 51 to 51
 $ kaffe -addclasspath . HelloWorldApp
Changed:
<
<
-- TobyCabot - 28 Dec 2001-16 May 2002
>
>
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

Revision 516 May 2002 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
Changed:
<
<
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. 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.
>
>
(back to ProgrammingTips)
 
Changed:
<
<
Here's a cute hack to enable token substitution in java property files: http://www.sys-con.com/java/source.cfm?id=1228
>
>
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
Added:
>
>

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

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.
Line: 17 to 51
 $ kaffe -addclasspath . HelloWorldApp
Changed:
<
<
-- TobyCabot - 28 Dec 2001-19 Mar 2002
>
>
-- TobyCabot - 28 Dec 2001-16 May 2002

Revision 409 Apr 2002 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="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. 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.
Line: 10 to 10
 /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.
Added:
>
>
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
  -- TobyCabot - 28 Dec 2001-19 Mar 2002

Revision 319 Mar 2002 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="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. 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.
Line: 6 to 6
  See also: JavaProgrammingBookmarks
Changed:
<
<
-- TobyCabot - 28 Dec 2001
>
>
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.

-- TobyCabot - 28 Dec 2001-19 Mar 2002

Revision 209 Jan 2002 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="ProgrammingTips"
Added:
>
>
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. 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.
 Here's a cute hack to enable token substitution in java property files: http://www.sys-con.com/java/source.cfm?id=1228
Added:
>
>
See also: JavaProgrammingBookmarks
 -- TobyCabot - 28 Dec 2001

Revision 128 Dec 2001 - TobyCabot

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="ProgrammingTips"
Here's a cute hack to enable token substitution in java property files: http://www.sys-con.com/java/source.cfm?id=1228

-- TobyCabot - 28 Dec 2001

View topic | History: r36 < r35 < r34 < r33 | 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