Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

"Obviously, You Will Need a Java Course..."

by azatoth (Curate)
on Apr 03, 2001 at 22:04 UTC ( #69406=monkdiscuss: print w/replies, xml ) Need Help??


As some of you may be aware from my whinging in the CB, I attended "Java for Non-C Programmers" last week.

When I joined my current company as a Support Analyst(circa 4 months ago), I had no programming experience. I was told the learning curve would be steep, and I would have to pick up a lot off my own back, without pestering colleagues for help. I was introduced to Perl in my first week, and by the end of that week I had sent merlyn some royalties and purchased "Learning Perl, 2nd Edition".

Wow! How come I haven't seen the utter coolness of programming until now? I mean sure, I hacked HTML once before (which isn't a programming language incidentally, see Learning Perl, 2nd Ed. Page 61) - but I've never enjoyed data input so much in my life! I felt I had finally found my career, and I was ready to stay and absorb as much as possible.

Anyway, this happy marriage continues for a few months, until my boss comes up to me and says "I want you to join us in Development. You're going nowhere with the Support schmucks." (paraphrased).

I said, "Ok, sure, you're the boss", whilst secretly rejoicing at the prospect of hacking Perl all day without phone interruptions.

"Great!" he says. "Obviously, you will need a Java Course...".


So, background aside, my company paid a fair amount of moolah for me to attend "JVANC" for the week. I was looking forward to it to tell the truth, as this would be my first formal course in IT. I was excited. The first day, we cover fundamentals like variable types and what classes are etc, and I'm thinking, "Well hey, OO Programming seems to be pretty cool!". The theory complete, we hit our first practical. The "Hello World!" java applet. "Easy peasy," I think to myself. I'm smiling away until I see the following :

System.out.println("Hello World!");

Come again?

What the hell is wrong with  print "Hello World!";. What's with this longwinded crap? That was when I realised which language I loved. I knew from that Monday afternoon, that Perl was for me. I enjoyed the course as it turned out, but I know in my heart that Perl is a language that really was suited to me as a non-programmer. I mean look at this : -

try { FileInputStream inStream = new FileInputStream( args[0] ); inStream = ("myFile.txt"); } catch(IOException ioerr) { System.out.println( ioerr.toString() ); }

and compare it with this :-
open(FH,"myFile.txt") or die "Nope : $!\n";

Azatoth a.k.a Captain Whiplash

Make Your Die Messages Full of Wisdom!
Get YOUR PerlMonks Stagename here!
Want to speak like a Londoner?

Replies are listed 'Best First'.
(Guildenstern) Re: "Obviously, You Will Need a Java Course..."
by Guildenstern (Deacon) on Apr 03, 2001 at 22:43 UTC
    Personally, I don't have much of a problem with Java. We're using it to develop our Web applications, and it works fine for that. It all boils down to using the right language for the job. Granted, Perl is great, but it's not a be all, end all solution. I'm not saying that Java is that solution either, but there are some cases where (IMHO) it's easier to get things done. Take, for example, session handling. In a Java Servlet, I just need to say something like
    HttpSession session = request.getSession(); session.addAttribute("key","value");

    if I want to add something to a persistent session. In Perl, this can be done (see Apache::Session), but it doesn't have the same flow to me. Sure, somebody can write a Perl session handler that works like its Java counterpart, but that's not the point I'm trying to make here. I'm saying that in this case, Java works better for me.

    One of the driving design issues behind our site development is to make eveything server-side to the point of excluding client side scripting (JavaScript, VBScript,etc). This means that we must perform all of the input validation in the Java Servlets and Java Server Pages. This is a case where Perl is by far the superior language. It's so much easier to run a string through a regex than to use Java's String methods. (Of course, somebody has written a regex package for Java, but once again that's not the point I'm making.)

    As far as the examples that you provide, System.out.println("Hello"); should be familiar to anyone who's had exposure to Object Oriented Programming. Since you said you're new to programming in general, I can understand your confusion.

    The second example illustrates a very simple example of Java's error handling. Instead of die-ing, catching the error can let you do other things like retrying the open or notifying another process. I'm not sure if Perl supports error handling in the same manner (try and catch, or similar), but I'm sure somebody here can clue me in.

    Negaterd character class uber alles!
      Guildenstern writes:

      I'm not sure if Perl supports error handling in the same manner (try and catch, or similar), but I'm sure somebody here can clue me in.

      darobin mentions this below - use eval BLOCK with die to catch and throw exceptions:

      eval { # code that might die }; if ($@) { # $@ contains your exception }

      Update: merlyn is right, of course - forgot the ";". Curse my flying fingers! :-)

        eval { # code that might die } if ($@) { # $@ contains your exception }
        Don't forget the semicolon after the eval {}. That kind of eval is an expression, not a statement, so it needs a semicolon to become a statement.

        -- Randal L. Schwartz, Perl hacker

Re: "Obviously, You Will Need a Java Course..."
by Corion (Patriarch) on Apr 03, 2001 at 23:17 UTC

    Each tool has its merits, even if it only serves as a bad example :-)

    I think that if you learn more different languages, you have more tools available to you to tackle the problems you'll encounter. One major point I find in Java programming is the pattern-orientedness of the algorithms / classes implemented in Java; my experience with Java is, that people there tend to document which Programming Pattern they applied to solve a certain problem, be it the Visitor pattern (an object iterates over a collection of other objects, and "visits" each element) or the Observer pattern (an object registers itself with another object and is then notified of changes within that other object). It's easy to implement these patterns elsewhere, but Java people seem (to me at least) to be more educated about patterns.

    I see that you are already good at comparing Java with Perl and at finding the Perl way and Java way to express what you want to accomplish. This is what speaking languages is really about, expressing the same thing in different ways, only that Java is more roundabout in IO tasks than Perl.

    To show you a small thing which is easy in Java but hard in Perl, have a look at threads. Java (and the underlying JVM) has threading built in, together with semaphors (called "monitors" AFAIR). This makes threads ubiquituous in Java, while they are virtually non-existent in Perl.

Re: "Obviously, You Will Need a Java Course..."
by merlyn (Sage) on Apr 04, 2001 at 00:12 UTC
    Not to fan the fires too much, but it's too bad people are touting Java as "Object Oriented", when in fact it's only a hybrid-OO language like Perl or C++. Most people will never see the elegance of pure objects in Smalltalk, Self, or Eiffel (or Ruby perhaps), and may never quite get what OO is really all about.

    In any event, I hope Java replaces C++ entirely. We've had that abomination for far too long. But Java won't replace Perl, any more than Perl replaces C++.

    -- Randal L. Schwartz, Perl hacker

      Just curious: what makes Java only "hybrid-OO"? I haven't dabbled with Java for many, many years*, so I don't recall too much about it...

      *I was excited when I first heard about Java, and searched hard before I found what was apparently the /only/ book on the market about it, that was heavy on the buzzwords and light on the examples. Kind of lost interest after that. Now there's whole sections in bookstores devoted to it. Must have been a sign to focus on Perl. :)

        Java has "primitive types" that cannot be subclassed nor extended.

        Smalltalk has no such artificial distinction.

        Java proponents claim that you must have primitive types to get decent performance. Odd, because Sun's Java VM itself is primarily written in Self, which has no primitive types (in fact, it doesn't even have classes!).

        -- Randal L. Schwartz, Perl hacker

Re: "Obviously, You Will Need a Java Course..."
by footpad (Abbot) on Apr 03, 2001 at 23:41 UTC

    Corion's right, every tool has its merits and its idiosyncrasies. A simple idiom in one will turn into a tortured mess in another. A key, I think, is to learn what each does well and then leverage those strengths. At the very least, the additional exposure will help round out your skills. In turn, this should help round out your resumé and fatten your wallet in the long run.

    Since you're still getting started in this wonderful discipline (and hopefully making a little more than you used to), allow me to recommend two books that may help you get a good start (and contribute to the Monastery's Treasury, should you purchasing using the links.)

    While the latter is getting a bit dated, it still contains very useful information.


Re: "Obviously, You Will Need a Java Course..."
by indigo (Scribe) on Apr 04, 2001 at 01:57 UTC
    I mean look at this : -
    try { FileInputStream inStream = new FileInputStream( args[0] ); inStream = ("myFile.txt"); } catch(IOException ioerr) { System.out.println( ioerr.toString() ); }
    and compare it with this :-
    open(FH,"myFile.txt") or die "Nope : $!\n";
    or this:
    die "Nope : $!\n" unless open(FH,"myFile.txt");
    or this:
    if (not open FH, 'myFile.txt') { print STDERR "Nope : $!\n"; exit; }
    or even this:
    !open FH => 'myFile.txt' == 0 && die "Nope : $!\n";
    Every one of those are (probably) valid Perl. And at a glance, they all look like they might kinda work. That's the tradeoff. A diagonal language like Perl, is terse and expressive, not only do you see the same thing done in several ways, you will revel in it. With orthogonal languages like Java, you code may be verbose and ugly, but everyone's code verbose and ugly in the same way, and there is less detective work involved.

    It all depends on what you and your task need in a programming language. I like to think of Java as being egalitarian, where everyone writes the same code, and Perl as elitist, where you can soar with the eagles, or crash and burn like a flaming eagle who can't soar anymore.
Re: "Obviously, You Will Need a Java Course..."
by rchiav (Deacon) on Apr 04, 2001 at 06:23 UTC
    I discoverd Perl about 4 months ago after I dusted off Programming Perl 2nd edition.. if that shows you how long I had been _meaning_ to learn it. And I'd have to say that's it's (not so) slowly becomming my language of choice. There's a few gotcha's for me, but that's there with any language. I've worked with C/C++, java, vb, asmbler etc.. but on to the point..

    Each and every one of these languages has it's place and purpose. When I first started to pick up Perl, I really struggled with writing it. "What do you mean it it figures out if it's a string or an integer?!" That's a really tough concept to find peace with when your pervious language of choice was C. The layers of abstraction were a little more acceptable with something like VB since it seemed like a toy language anyway. BUT.. even VB has it's place.

    I promised a point, right?

    I guess the point is that even though you may love Perl, learn what you can of other languages. My least favorite language is probably Java for it's slowness.. and don't talk about compiled java because then it just looses it's whole damn purpose in the furst place. But it still has it's place too. It's another tool.. and programming is about "programming", not about which language you use. Design is the key.. and you choose the language to meet the needs. You're not going to use Java or Perl for RTOS programming.. and you're not (or shouldn't) use C to do some simple one liner shell script. And even though I'd love to.. I'm not going to pump perl out to thousands of Wintel desktops so I can write login scripts in Perl instead of batch files or vbscript/jscript. OK.. maybe I would if we were still left with just batch files but..

    Anyway.. to make a short point longer, Java is just another tool. Tools are good. And even bad tools teach you something.

Re: "Obviously, You Will Need a Java Course..."
by darobin (Monk) on Apr 04, 2001 at 15:27 UTC

    Actually, open(FH,"myFile.txt") or die "Nope : $!\n"; isn't really equivalent to the try-catch part above. A closer moral equivalent would be:

    eval { open FH, '<my_file' or die $!; }; print $@ if $@;

    ...or of course a number of other possible Perl constructs around the same idea.

    -- darobin

Re: "Obviously, You Will Need a Java Course..."
by jbwiv (Acolyte) on Apr 04, 2001 at 08:29 UTC

    I know how you feel. I work for a company that has aspirations of being a "Java only" shop. Each week in our status meetings, they request things and the lead says it absolutely can't be done in under 3 weeks...I quietly go back to my cube, sit down at the machine, and script it in perl in less than a day.

    Java is good for some things......Perl is good for many things ;-).

Re: "Obviously, You Will Need a Java Course..."
by azatoth (Curate) on Apr 04, 2001 at 13:32 UTC
Re: "Obviously, You Will Need a Java Course..."
by LD2 (Curate) on Apr 07, 2001 at 08:05 UTC

    You make a good point azatoth, but I believe .. as others have already commented on that that each language has it's uses/pros/cons. At the company where I am now, we primilary use Perl for parsing(tis excellent) and a bit of database programming. We're just starting to use weblogic with Java - jsp - for our new web application projects. I like you, just took a Java course - although this was a bit intense for 5 days (it was a sun certified course - oddly enough not one student was planning on taking the exam), it went through OOP and many of it's advantages, as well as Java and it's many uses. I won't discuss it here, it's not really the place - but I can definately appreciate perl's simpleness and ease of use after taking the course - although I liked the freedom that a developer is given with Java and it's event handling, interfaces, inner classes, etc. But, to reiterate - I think Perl is great because one doesn't have to go through such lengthy syntax to produce the same output as Java.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: monkdiscuss [id://69406]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2023-03-26 02:36 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (63 votes). Check out past polls.