Java is NOT EASY to learn. But still worth :)
Tags: java, career, webdev
Published: 2020-02-07 14:32:01

Here was the post [Why should learn Java in 2020](https://dev.to/j_marathi/why-should-learn-java-in-2020-8j6) - 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](https://www.tiobe.com/tiobe-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:

```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
<?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!

```java
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.