DEV Community

Cover image for Java is NOT EASY to learn. But still worth :)
Rodion Gorkovenko
Rodion Gorkovenko

Posted on

Java is NOT EASY to learn. But still worth :)

Here was the post Why should learn Java in 2020 - and it started with:

Java is Easy to Learn

I'd say this is QUITE NOT TRUE, sorry :)

Perhaps someone have tried and found the same already? Don't be frustrated, it's not only for you!

Working as Java developer since 2011, I do know something about it. Let me share briefly. There are few topics following:

  • Java is worth learning
  • but it is hard
  • couple of examples
  • why is it so
  • cheer up!

Java is worth learning - it will make you wealthy :)

Look at tiobe language popularity index - Java is in the top consistently. Look at your favorite job-finding site - there are usually more java positions than for most other languages.

And though it is not "language for everything" (as some people would say), it is widely used, especially:

  • for zounds of server-side services, tools and frameworks - and they are behind almost every modern applications - online games, social networks, even services for storing data from mobile apps (and this includes popular modern world of BigData / Data Science things);
  • for mobile apps - either for Android (80% of market share among mobiles) or for various cross-platform frameworks (which compile both to Android and iOS) - there are more devices running Java than people on the Earth!
  • for automated testing of web-applications with Selenium - it can use other languages, but Java is usually preferred - this is probably most interesting option for those beginners who want to to get employed with java fast!

Also it opens path to other Java-based languages, like Scala, Kotlin and others.

And it is sturdy language which teaches many good principles and habits. So it prepares one to be guru-programmer despite of further language choice.

But... :(

Now see - here I am, senior java dev for many years, making good money with it and my mailbox bloating with nasty recruiters' messages suggesting even more money... And nevertheless:

  • I almost never use Java for personal projects!
  • I never advice it as a first language to learn, or to be taught in school;
  • I always say Java is HARD

Of course there are harder languages. Learning C++ to full extent, or trying to grasp Haskell, for example - both may frustrate you.

Really, learning almost any language to guru level requires a lot of time. However some languages allow easier "learning curve". They are more friendly to newcomers.

But Java is not one of them :)

Two examples

Let's try first "Hello World". In some languages, e.g. Python, it is just "one-liner", like print("Hi People"). But not in Java:

public class SoooSimple {
    public static void main(String... args) {
        System.out.println("DIE HARD!");
    }
}

Why all this stuff? What are public before class and before method? Won't it work without any of them? How about static? Why we put args as parameters though we don't use them? What is System and what is System.out? Besides "that is the thing for printing", of course.

Java pours tons of difficult things on your head at once. Surely when you learn these things one by one, it is easier - but on start it could be painful.

Another example - code for retrieving data from web link (url). In PHP this would be just this:

<?php

echo file_get_contents("https://google.com");

Yes, PHP just gives single method for retrieving data either from file or from web. But Java knows better than this!

import java.io.*;
import java.net.*;

public class ReadURL {
    public static void main(String... args) throws Exception {
        InputStream in = new URL("https://google.com").openStream();
        while (true) {
            int c = in.read();
            if (c < 0) break;
            System.out.write(c);
        }
    }
}

Note that I've tried to make it as short as possible (and due to this - awful in some places). We need to open URL, take stream from it, read this
stream bytewise and print out. If we try using other read method which reads all at once into array - it may stop reading prematurely.

And it is short because I don't care about nasty exceptions. The code could be three times larger if I do.

Why is it so?

The main thing is - Java was not created to be simple to learn. It had another goal:

to make simple working in LARGE PROJECTS and LARGE TEAMS

When you create some small thing - from school exercise or some proof-of-concept app - even to JS game - it is beneficial if language is "lightweight" and allows you do things fast without much headache.

But when project is being developed by team of several (many people) and is extended in the course of years - usually people come and go, no one remember exactly what and how is working.

Because of this Java syntax and type system may be difficult for beginner. And its standard library is vast. PHP and JavaScript use arrays almost for
everything. Python offers lists and dicts mainly. But Java has over dozen
classes dedicated to various collections type. Numerous Streams and Readers - and some of them not very convenient.

And when you master syntax and standard library, you'll find it's just start!

Java is famous for its libraries and frameworks, and usually to get hired you need to get acquainted with at least some of them. Spring, Hibernate, Google Guava - thanks to them, you may feel miserable sometimes :)

Conclusion

Well, friends! I have no intention to frighten you. Java is nice language anyway. And anyone can learn it. Just don't get frustrated if it doesn't come easy. It may be simpler after you have experience with few more languages and general things about programming.

Top comments (20)

Collapse
 
delta456 profile image
Swastik Baranwal

If you think Java is hard then learning C will be a nightmare.

PHP standard library has good net and https support as it's made for the web and Java can have a support like this as well if drafted and added to standard library.

Collapse
 
rodiongork profile image
Rodion Gorkovenko

I'm afraid you are messing C and C++

And anyway I learnt and used C years before Java. I started career as electronics developer where it is quite popular.

Collapse
 
delta456 profile image
Swastik Baranwal

What you mean by that?

Thread Thread
 
rodiongork profile image
Rodion Gorkovenko

If you say "C is nightmare" there probably is some mistake.

C is quite simple language originating from 1970. C++ is it's extension from mid-1990s, with OOP, templates and (in recent standards) it have become really difficult to learn just because it has tons of features, many of which are legacy.

C++, Java, C# and Objective-C - they all are decendants of old simple C in some way.

Thread Thread
 
delta456 profile image
Swastik Baranwal

Most people don't find it simple.
I agree C is small and simple.

Thread Thread
 
oldprogrammer profile image
OldProgrammer • Edited

C is easy enough to learn, but issues such as the following make it difficult to master:

  1. Pointer / array syntax and semantics are difficult to understand.
  2. Lack of variable initialisation to safe values e.g. zeroes.
  3. The ability to write all over memory.
  4. Doing things that otherwise would cause fast failure in other languages may result in a program that runs and works, or fails in unexpected ways.
  5. Dynamic memory allocation - the memory must be allocated and freed. This comes for free in other languages, and increase the complexity of C code.
  6. Null terminator character instead of length / array representation for strings.
  7. C requires more lines of code to do some things than other languages e.g. implement a simple linked list.
  8. Lack of a namespace to organise source code.
  9. Portability issues - possibility of different results on different hardware even if code works correctly e.g. due to different int sizes.

I say this as somebody who's programmed C for many years, and still do. In my university placement year, I was given a copy of "Kernighan & Ritchie" to learn C in my first week.

Thread Thread
 
delta456 profile image
Swastik Baranwal

Agreed but if you understood all these concepts then you will be able to understand any language.

Thread Thread
 
oldprogrammer profile image
OldProgrammer • Edited

Differerent classes of languages have their own subtleties so take time to learn. For example, I'd personally really need to think about how to write a prime sieve in a functional programming language.

It's surprising that some developers, even with quite a lot of C programming experience, program without giving sufficient thought to things I've listed above e.g. a new struct is defined, code is written to allocate memory for the structure and fields within it, but with no clean-up strategy in the (admittedly rare) case that memory allocation fails.

I've seen this on projects where a developer is programming in other languages e.g. Java alongside C.

Thread Thread
 
delta456 profile image
Swastik Baranwal

It's because they are used to newer languages which cleans up everything for them.

Thread Thread
 
oldprogrammer profile image
OldProgrammer • Edited

Even with Java care has to be taken so that the garbage collector thinks it can actually release an object when it goes out of scope.

Collapse
 
cheetah100 profile image
Peter Harrison • Edited

Java isn't a great first language. I've been a professional Java dev since 99. It is rational to choose technologies that are in demand. But it isn't about just learning one thing. A 'full stack' developer will also need to know about SQL, possibly Mongo, Object Relational Modeling, have a understanding of Git, Jenkins, JUnit. If writing front end apps you will need to know about CSS, Javascript, Angular, React, or Vue.

Furthermore there are other languages which are probably more concise and productive. For back end there is Node and Python now, both of which are gaining popularity in what was core Java territory.

The important thing as a developer is that you are always evaluating technologies. That does not mean learning every new flavour of the day language, but it does mean having a broader toolkit than just one language.

I recommend that new developers use something like Python which is both general purpose and concise. It does not force you into object orientation before you learn the basics. It is not a toy language, so you will actually be able to earn a dollar from it. And if you want to continue to Java it gives you a good foundation.

As a long time Java dev I can say it isn't the worst language, but it is wordy and does encourage you into binding to data structures through objects. In terms of difficulty learning, probably also not the worst, but not the best either. Better to start with languages that don't introduce complex concepts early.

Collapse
 
jonesey712 profile image
Jonesey712

I learned Java this past year and I still have trouble with it. So I going through drills on HackerRank and CodeWars. My sister is also learning it now so I'm helping her where I can. I agree its worth it to learn, but very difficult.

Collapse
 
rodiongork profile image
Rodion Gorkovenko

Hi Friend!

Thanks for sharing your experience!

What is the goal for you and your sister? Some kinds of tasks where Java is heavily used are simpler than others. For example, one may prefer to start career is "Web QA automation" - here people use Java to write tests which run through web-interfaces with Selenium library. It may be significantly easier for beginner than writing production server-side code for example. So I dare to recommend this way :)

Collapse
 
jonesey712 profile image
Jonesey712

Right now my goal is to start a new career! I've used Java with SpringBoot and MAMP to create a CRUD app. There's so much to possibly do, so now its wherever I can get in to work and learn. I went through LaunchCode here in STL to learn and we were told right off that there is a chance that where we end up may not be coding in Java or Python(the other language we learned) as they do placement.
I'm not sure what my sister's goals are. I feel like she would be good in a consultant type role.

Collapse
 
captainawesomedi profile image
Di Wu • Edited

Can't agree more. I am Rails Developer who graduated from bootcamp 2 years ago. Java is hard. For me, specially doing OO programming a lot of syntax didn't make sense to me. But After I learned Ruby, everything about OOP made sense, due to it's beautiful and readable syntax. I would recommend beginners or self-taught who wants to get into programming learn languages that has a simple syntax first, like Ruby or Python

I want to share how these language made to me to understand different programming paradigms on my journey:

  1. Ruby: Understand the concepts of OOP
  2. Javascript/Node: Necessary language for web, introduce to functional programming
  3. Java: With understanding OOP from Ruby, things I learned from Java are attributes about static typed language.
  4. Typescript: Combine all my knowledge together about OOP and Static Types and apply it
Collapse
 
javierpomachagua profile image
Javier Pomachagua

Nice post. I'm from Peru.
When I graduated 5 years ago I learned Java and also I use Primefaces, Hibernate and a bit of Spring. The years passed and I wanted to learn something new so I started to learn PHP using Laravel and I love it. I have learned also Vue, Nuxt and working in company using these technologies but usually I found more job offers in Java or .NET (also learned 4 years ago but not using now) than PHP and Laravel. Now I am very interesting to learn Flutter (basic now) for working on it ...
What do you suggest me?
TY (sorry for my english)

Collapse
 
smuschel profile image
smuschel

nasty recruiter's messages - that one made me really laugh.

Java wasn't my first language when I started programming (I guess that would be Basic or maybe Pascal). I think learning is never really easy. It's important to take small steps. Yes, Java has a huge ecosystem full of libraries for any aspect you can imagine. So do other languages. As a developer, one of the most valuable skills (in my opinion) is to be able to learn new languages.

In the end, learning a programming language isn't different from learning other stuff, e.g. if you learn to swim, you typically won't start in the middle of the ocean and see how it goes. You'll take small steps and improve on that. The same should apply to your programming skills. Learn the basics, only look at a small subset. Then start looking at other aspects, one at a time. If you do too much at once, you might drown.

Collapse
 
oldprogrammer profile image
OldProgrammer • Edited

Coming from a C background, Java is relatively easy to pick up.

There is a load of other stuff such as the large number of libraries, how to use code comments, how to override methods such as equals / hashCode so that proper equality works in a collection.

However, subtleties - understanding and making proper use of features such as generics, enumerations, collections, why inheritance and interfaces should and should not be used take effort to understand. I suggest the book "Effective Java" by Joshua Bloch as it covers things from this angle instead of, say, going through the network programming library classes.

Collapse
 
oldprogrammer profile image
OldProgrammer

I'd suggest Python as a first language (maybe after a pictorial language such as Scratch for beginners) with something like inventwithpython.com/ or Raspberry Pi to work with.

Also, python has good support in areas such as numeric and scientific computing, machine learning and data science, and web development.

Collapse
 
nombrekeff profile image
Keff

Great post, definitely agree. My first language was Java, and what a journey it was... I don't recommend as the first language.