Category Archives: Java

Trending up: Windows7, Agile Methodologies, Scrum, Python. Everything else? Down!


Linked-in are now listing ala-carte qualifications which one can endorse one’s acquaintances on, or be endorsed by them. No surprise, 20 people say I’m good at “hardware”, which is my highest endorsement. What I want to draw your attention to here is that if you hover your pointer over each of the possible qualifications, Linked-in will show you a working definition and the year-to-year trend on people who say they do-have-know-practice-are-qualified-in the specific item.

Not so surprising, people saying they know ‘hardware’ are down year on year… also C, C++, software engineering, Perforce, customer support, regression test, unit test, and so forth. VMware is 0% – neither up nor down over last year.

Agile Methodologies are up, Windows 7 is way-up, Python is up, Scrum is up. The other 44 categories, on my list, not including VMware at 0 and Windows 8 which doesn’t have a year on year trend, are down.

So, among people who list qualifications similar to mine, the majority and growth area are Python users, on Windows 7, employing Scrum and Agile project management methods.

Your choice whether that’s:

a) what everyone wants;

b) what people looking for work think they need;

c) some cross section of professionals on Linked-in.

I think its worth noting in passing, but not worth a lot of study. But it is a curiosity.

An example that pleased me: The difference between an abstract class and an interface, in Java:


Here’s the punch line:

In Java, Prussia can extend (“be a”) one of the super-classes, Holy, Roman or  Empire, but only one. Prussia can implement the other two as interfaces, but only with methods and fields uniquely its own. If Prussia is to be Holy, be Roman and be an Empire, the strictly hierarchical relationship of those three super-classes has to be worked out separately and in detail, in advance. I can only imagine Herr von Bismark would approve.

 

And the whole magilla:
1) What is the difference between an interface and an abstract class?

An abstract class defines data (fields) and member functions but may not, itself, be instantiated. Usually, some of the methods of an abstract class are abstract and expected to be supplied by a sub-class, but some of the methods are defined.  Unless they are final, they can be overridden, and they can always be overloaded. Private parts of an abstract super class, for example, data, are not available to a subclass, so access methods (public or protected) must be used by the subclass. An abstract superclass is “extended” by a subclass. A given subclass may only extend one super-class, but a super-class may extend another super-class, in a hierarchy. (This avoids the complexities/difficulties of multiple inheritance in C++)

An interface is a proper subset of an abstract class, but has a different scope and use. An interface has ONLY abstract member functions and static, final, fields, aka constants. Any subclass has to provide all the variable fields and code which implements an interface. The implementing class cannot override the interface’s member signatures – the signatures are what the interface *is*. It is possible to overload an interface’s signatures, adding or subtracting variables, changing return or variable types, but the overloads do not satisfy the requirements of the interface. The implementing class(s) must contain actual member functions to satisfy all of the signatures in the interface, because there is no default, no code in the interface.  As used above, a given class ‘implements’ an interface, it does not ‘extend’ it. These limitations to an interface allow a given class to implement more than one, which retains most of the utility of multiple inheritance without, as it were, opening Plethora’s bag. (grin)

For example: In Java, Prussia can extend (“be a”) one of the super-classes, Holy, Roman or  Empire, but only one. Prussia can implement the other two as interfaces with methods and fields uniquely its own. If Prussia is to be Holy, be Roman and be an Empire, the strictly hierarchical relationship of those three super-classes has to be worked out separately and in detail, in advance. I can only imagine Herr von Bismark would approve.

Recursion III, using Java


Here’s a Java example of the classic recursion/tree/web traversal. Note that this uses an array of other nodes, not just Left and Right, so you can make n-link webs as well as proper trees using this example.

The method interMed() is used to avoid having to make the data structures static- there is much I have yet to learn about Java! But I can manage this, and that feels pretty good!

/*
recurse.java

Recursive tree/web traversal, in Java. No explicit pointers, so I state that
the array of pointers to nodes is an array of nodes, and treat it as such.
Is it really pointers if I believe it is but can't see them? Its like String
Theory...

Original 11:58am 4/21 Bill4

*/

import java.util.ArrayList;

public class recurse {

public class node { String name; ArrayList kids; };
public class leveledName { String name; int level; };

ArrayList nLs = new ArrayList ();

public void recur ( node n, int level ) {

// System.out.println( "recur " + n + " level " + level );
leveledName lN = new leveledName();
lN.name = n.name;
lN.level= level;
nLs.add( lN );

for ( int i = 0; i < n.kids.size(); i++ ) { // better way to do this?

recur( n.kids.get(i), level + 1 );

} // for int i...

} // recur function

public void interMed() {

node Q = new node(); Q.name = "Q";
Q.kids = new ArrayList ();
// System.out.println( Q );

node S = new node(); S.name = "S";
S.kids = new ArrayList ();
// System.out.println( S );

node T = new node(); T.name = "T";
T.kids = new ArrayList ();
// System.out.println( T );

node N = new node(); N.name = "N";
N.kids = new ArrayList (); N.kids.add(Q);
// System.out.println( N );

node P = new node(); P.name = "P";
P.kids = new ArrayList (); P.kids.add(S); P.kids.add(T);
// System.out.println( P );

node M = new node(); M.name="M";
M.kids = new ArrayList (); M.kids.add(N); M.kids.add(P);
// System.out.println( M );

recur( M, 0 );

int maxLevel = 0;
for ( int i = 0; i maxLevel) {
maxLevel = ((nLs.get(i)).level );
} // if ...
} // for ...

for (int j = maxLevel; j > -1; j-- ) {
// System.out.println( "j " + j );
for ( int i = 0; i < nLs.size(); i++ ) {
// System.out.println( "j " + j + " i " + i );
if ( j == (nLs.get(i)).level ) {
System.out.printf( "%s %d \n", (nLs.get(i)).name,
(nLs.get(i)).level );
}
} // for i...
} // for j...

} // fn interMed

public static void main ( String args[] ) {

recurse r = new recurse();
r.interMed();

} // main

} // class recurse

Using Java’s String.split() to divide a string delimited by whitespace AND other things.


I have a file containing lines that look like:

#### #.##% #.##% ## ###### someLongStringAtTheEnd
__ (leading blanks
where #### is an integer number and ##.## is a floating point number. The two floats are labeled as percentages by the literal percent signs.

As far as spaces go, .split( ” ” ) works just fine. If you want more than one ‘whitespace” you have two choices: Write your own RegExp naming each whitespace character after double back slashes to escape them from the Java compiler AND Java runtime:

…split( “[\\ \\t]+” );

catches both spaces and tabs…

However, the world of Regular Expressions offers something even neater: \s, which stands for all Ascii whitespace.

Of course, you still have to escape it
…split( “[\\s]” )

and add the percent sign, and a “+” outside the braces to allow it to take one or more of the specified characters:
…split( “[\\s%]+” )

Here is a nice discussion of whitespace delimiters, larger-than-ascii character sets, etc.:
http://stackoverflow.com/questions/1822772/java-regular-expression-to-match-all-whitespace-characters

Bill

Getting directory contents from inside Java


I went searching for an example, found:
http://www.javafaq.nu/java-example-code-120.html
which shows several different ways to display content- everything, directories only, filter by string. I added a toy user interface so I can play with it interactively, resulting in a new main method:

public static void main(String[] args) {

String target = “//”;
String filter = “”;

if (args.length == 0) {
System.out.println(“java ListFilesSubs [first char(s) filter]”);
} else {
if (args.length > 0) {
// Call the simple file listing method
target = args[0];
doSimpleFileListing( target );
} // if args.lenl > 0

if (args.length > 1) {
// Now do the file listing but pass in a String to filter the file list
filter = args[1];
doFileFilterListing( target, filter );
} // if args.lenl > 1

// Now do another example that only prints out the directories
doFileFilterDirectoryListing( target );

} // if args.length == 0.. else

}
}

Much nicer, more fun, than a compiled-in directory string.

Even better than NetBeans, HProf comes with the JVM in 1.5 and 1.6…


Bingo! NetBeans’ profiler is very nice, thank you, and WAY easier to get started with than Eclipse, but its a GUI and you run it interactivly- good for some things, not for automated performance testing, which is what I’m trying to set up. Well, turns out HProf (Heap Profile) is a tool built into the Java Virtual Machine and available as a launch-time option whenever you run a Java program. The example on Sun’s web page profiles “javac”- pretty confident there. So I tried it on Mac OS-X and Win XP and it works just fine on both. You get percentages, not absolute times, but it gives you the total time and you can multiply out the absolute time if that’s what you really want. I must say I’m enjoying this again. Trying to get JMeter and TPTP running under Mac OS wasn’t any actual fun, since they didn’t work. In fact, having put TPTP into Ecipse, I can’t use Eclipse anymore… that’s a useful definition of software that’s not quite ready for prime time- it installs successfully, then tells you it doesn’t support your platform when you try to run with it, and it prevents your IDE from working until you figure out how to remove it. Joke’s on me, eh?

Anyone have expereince running NetBeans’ Profiler from command line?


Just found the following about running the NetBeans Profiler with Eclipse…  not command line but headed that way, maybe…

http://www.jroller.com/ortegon/entry/on_profiling_eclipse_rcp_applications

I left the following comment for Mario and I wouldn’t mind answere from anyone who reads this plea anywhere!
I’m trying to find a platform neutral profiling tool for Java- I need to support *nux, Windows and Mac OSX (yeah, BSD, but…) and I need to run from a command line so I can automate it. The Java library I’m testing is a thin client that talks TCP/IP to a server, all I care about is the client library performance, but I care on all three major platforms.

I tried to get JMeter going and realized it wasn’t aimed at what I was doing. I installed TPTP and was really hoping it would do the job but then discovered it has NO agent for Mac OSX and hasn’t for years. Phoey!  So I got NetBeans, imported my code (trivial, why can’t Eclipse be this easy?) and happily profiled on my Mac. Good so far.

Does anyone have experience running the NetBeans Profiler from Solaris, Linux, Mac OSX and/or Windows command lines?

Other all-platform Java profilers?

Many thanks for any help!!!

Bill