I have my mind set that I'm learning Java as my second language (I am a Perl developer). But just from reading a little of the online tutorials, I really can't find any similarities between the two. What will I have an easy time understanding when learning Java?

closed as too broad by user22815, durron597, Dan Pichelman, GlenH7, Kilian Foth Aug 7 '15 at 13:27

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Start up front by deciding "I LIKE THIS LANGUAGE!". Whenever you run into something difficult just remember your decision and save yourself a lot of teeth grinding and hair pulling. – user1249 Aug 9 '12 at 7:50
  • 1
    Recommended reading: Gorilla vs. Shark – user22815 Jul 30 '15 at 4:08

Perl is a high-level, general-purpose, multi-paradigm, interpreted, dynamic programming language. Java is a high-level, general-purpose, mostly single-paradigm, statically typed programming language.

So, both are high-level:

A high-level programming language is a programming language with strong abstraction from the details of the computer.

and general-purpose:

In computer software a general-purpose programming language (GPL) is a programming language designed to be used for writing software in a wide variety of application domains.

In essense this means that everything you can do with Perl, you can also do with Java. And as @KyleHodgson mentions, both their syntaxes derive from C and C++ and the syntax for simple stuff like for loops and if statements is essentially the same - and as @DipanMehta notes, both are garbage collected. And of course both are extremely popular and have vibrant communities.

But that's where the similarities stop. Perl is multi-paradigm, supporting a wide range of programming paradigms:

Perl does not encourage one single paradigm, they are essentially equal and you are free to choose whichever you think best suits whatever you're building, without of course limiting you to a single paradigm, you can mix and match. On the other hand, Java is mostly a class based object oriented language. There is support for generic programming, but as a beginner you should think of Java as strictly a class based object oriented language.

So Perl allows more than one ways to structure your code1, whereas Java just one. That's not a bad thing (or a good thing), it's just different. If you haven't written any object oriented Perl code, Java might seem a little bit alien at first. Don't be discouraged, object orientation is something that you will eventually have to learn, if you are considering a career in software development, and learning Java is a good way of learning the basic concepts of object orientation - not a perfect way, but definately a good way.

And as you know, Perl is interpreted, whereas Java is... well... a different beast entirely. In Java you write your code as you would in Perl, and then you compile it. The result is not an executable, but Java bytecode. This intermediatery format is executed (finally!) in the Java Virtual Machine, which is somewhat analogous to the Perl interpreter. A JVM must be installed beforehand for a Java program to run, simirarly on how you need to install a Perl interpreter to execute a Perl script2.

Coming from a Perl background, the most important thing to remember is the compilation to bytecode step: Every time you make a change to a Java source file you need to re-compile it. It might sound crazy at first, but compilation has a very nice consequence: Your code is checked for a variety of errors at this stage, and the compiler refuses to finish the process if there are any, and sometimes will help you pinpoint the errors with helpful messages (There are always messages, but only sometimes they are helpful).

Which brings us to the last major difference:

Perl is dynamic3:

Dynamic programming language is a term used broadly in computer science to describe a class of high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. These behaviors could include extension of the program, by adding new code, by extending objects and definitions, or by modifying the type system, all during program execution.

and dynamically typed4:

A programming language is said to be dynamically typed when the majority of its type checking is performed at run-time as opposed to at compile-time.

and Java is statically typed:

A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time.

Which, to put it as simply as possible, means that in Java you have to declare the type of your variables and methods before using them. There are other differences, but I wouldn't want to spoil the fun of discovering them by yourself :)

And, finally, there is one very important difference: Java is the sweetheart language of the academia5 and the corporate world, while you will rarely meet Perl in an academic setting anymore (where I first met her), and its career perspectives are shrinking (still quite a few jobs, but nowhere near as many as Java, .Net languages or PHP). I will not comment on the reasons, I'm just stating the (sad) facts. Since you are still very young, by learning Java you will be a little bit more prepared for a Computer Science degree, if you chose to follow that path.

Don't give up on Perl, of course, but do explore Java. The fact that they are more different than similar also means that you will learn quite different approaches and programming mentallities, it's a hard path but one that will ultimately make you a better programmer.

1 "Tim Toady"

2 The Perl community is actively exploring the possibillity of a Perl virtual machine, via Parrot.

3 Dynamic doesn't always mean dynamically typed.

4 Perl is dynamically typed for user defined types, statically typed with respect to distinguishing arrays, hashes, scalars, and subroutines, and strongly typed via use strict, so essentially it's a variable type system language, but to keep some sense of sanity let's call it dynamically typed.

5 To the point of abuse, as Joel Spolsky writes in The Perils of JavaSchools.

  • 6
    Compared with Perl, Java is not a high-level language. It takes much more Java code to write something than it does Perl code. – tchrist Feb 19 '12 at 14:41
  • 1
    @tchrist What does amount of code has to do with whether a language is high level, or higher / lower level than another language? – yannis Feb 19 '12 at 14:43
  • 1
    @YannisRizos That’s pretty easy to answer. If it takes more code, then you are not dealing with a high enough abstraction layer. One glaring example is with Java’s dodgy string handling. It deosn’t support the high-level concept of abstract Unicode code points except in the regex engine in Java 7. That makes for a great deal of malarkey because of how low-level a language Java is compared with Perl. – tchrist Feb 19 '12 at 14:46
  • @tchrist The subjectiveness of the term doesn't allow much room for a sane comparison, the lines are too blurry, and both languages have an extremely wide range of features, some of which are very high level and some lowish. So, I'll keep thinking them as being on the same level and won't worry much about it. I had a similar conversation here, which inspired me to not lose any time comparing languages ;) – yannis Feb 19 '12 at 14:59
  • @YannisRizos You cannot find a highlevel concept in Java that Perl lacks, but you can find many highlevel concepts in Perl that Java lacks. Thus, Perl is higher level. Perl has function pointers; Java doesn't. Perl has operator overloading; Java doesn't. Perl has deterministic destructors; Java doesn’t. Perl can overload functions by return type; Java cannot. I can go on this way for a very long time. You of course shall continue to ‘feel’ however most pleases you, and for whatever reason, but it is not due to subjective analysis. – tchrist Feb 19 '12 at 15:03

Well, they both use a C like syntax - semicolons, curly braces and the like. Personally, when I tried to make a switch from Perl to Java a number of years ago - the biggest thing that tripped me up was object oriented programming. I had developed some objects in Perl, but it hurt my head to try to imagine life in the Kingdom of Nouns.

  • @downvote, why? (I'm not so in love with the answer, just curious as to what you found so problematic.) – Kyle Hodgson Aug 11 '12 at 0:55

Taking a stab at an alternative answer since the currently selected one seems to be focusing on differences between the two (truly there are not a lot of similarities between Perl and Java).


  • They are both C-like (they have loops and braces and semi-colons)
  • They are principally imperative
  • Neither produce compiled binaries
  • They are both very mature
  • They are both battle-tested in the enterprise (Perl more as ops glue and Java more as applications/services)
  • They are both popular
  • They both support object-orientation
  • They both have a wide array of frameworks available
  • They both have books published about them
  • They are both higher-level than C/assembly
  • They are both "slow" (for various, specific scenarios of slow in that neither are C/assembly)
  • They both manage memory automatically ("garbage collection")
  • Neither are hip/cool as of summer 2012
  • They are both entrenched in the open source community
  • They are both available for many platforms

If your Perl code is very rigorous and orthogonal (well-tested, well-documented, uses Moose or strict object-orientation), then those concepts will carry very well into Java, since Java is extremely orthogonal and not as expressive.

Not the answer you're looking for? Browse other questions tagged or ask your own question.