DEV Community

Cover image for Learn Java from scratch with these easy steps
The Educative Team for Educative

Posted on • Originally published at educative.io

Learn Java from scratch with these easy steps

Originally posted on Educative.io

Java is one of the most popular programming languages for software development. Learning and mastering Java will open doors for you as a developer, no matter your end-goal or skill level. Today, we’re going to go over some reasons we think you should start learning Java and then offer an in-depth roadmap on how to get started. If you want to skip the reading and get hands-on with Java programming, you can visit this great free course, Learn Java from Scratch.

Why should I learn Java?

Java is easy to learn

Java is a general purpose, object-oriented, high-performance, interpreted, secure, and multithreaded language. What does this all mean? Basically, Java simplifies the process required to make a network connection. Its security models safeguard against viruses. Many of the tedious processes run automatically, which saves you time. Java is statically-typed, so it’s easier to track down errors in your code. Java is a great first language for absolute beginners.

Java is popular

Java is one of the most commonly used programming languages in the world. In fact, it has the 2nd largest online community on StackOverflow. This means that there is a huge, mature community of support for Java programmers and learners. If you ever get stuck, you can be sure that someone has tackled your questions online. And with a thriving ecosystem of developers, there’s always something exciting to learn.

Java deals with real-world problems

Java is famous for its “write once, run anywhere” capabilities. This means that code compiled on Java can run on any platform without needing to be recompiled. That’s why Java is used in all kinds of distributed environments. In fact, Oracle estimates that Java is used in over 3 billion devices worldwide, such as Blu-ray players, game consoles, and Android phones. Java is even used by the financial service industry and NASA. There’s no limit to the real-world application of Java.

Java will boost your career

Since Java helps us solve real world problems, there are a lot of job opportunities for Java programmers. It’s an in-demand language for companies of all sizes and scopes. Java continues to be one of the most sought after programming languages by employers, both within the high-tech industry and outside of it. According to industry estimates, approximately 90% of Fortune 500 companies make use of Java in some capacity.

Java skills are transferable

Java is an object-oriented programming (OOP) language, and its syntax is derived from C. These concepts are prevalent in many other programming languages as well, so as you learn and master Java, you’re also preparing yourself to tackle other languages in the future. JavaScript, C#, and C++ just got a whole lot easier.

I want to learn Java. Where do I start?

Let’s break down six smart steps to learning Java and go over some basic vocabulary to get you started.

1. Make your motivation tangible

Java might be easier to learn other languages, but that doesn’t mean it won’t be challenging. In order to master Java, you need to study and practice daily. This will be harder if you don’t have an objective behind your hard work.

Having a clear motivation will push you through the challenges and keep you focused on your learning. Do you want to build a game? Do you want a full-time career as a Java developer? Setting these goals early in your journey will redirect your focus when it dwindles and make it easier to measure your progress.

2. Create an education plan

Discipline is your new best friend. Making a plan for your learning will make or break you as a new Java learner. With an educational plan, you’ll know when and what to study.

Set a weekly curriculum starting with the basics. A lot of people ask how long it takes to master Java, and, of course, there is no one answer. But a committed, organized learner will certainly learn faster and smarter than someone who doesn’t plan it out. If you’re serious about learning Java, we recommend setting aside 2 hours per weekday and 4 hours per day on the weekend for studying. If you stick to this plan, you’ll probably need 4-7 months before you’ll be ready to apply for a job as a Junior Java Developer.

Here’s a general progression of the topics you will need to learn:

  • Java Syntax (the rules for writing a program)
  • Object Oriented Programming Concepts
  • Core Java (how you develop a java application)
  • Java Collections (architecture for storing groups of objects)
  • Libraries and frameworks (large collections of prewritten code)
  • APIs (protocols and tools used to build applications)
  • Git (a widely used control system)

Make an educational plan that progresses through these topics. Remember that your timing will depend both on your knowledge of other programming languages and your personal learning style.

3. Download Java Development Kit (JDK)

The Java Development Kit is a development environment where you can document and compile Java applications. It includes all the basic tools you need to write and develop Java. This package includes Java Runtime Environment (JRE) and Java Virtual Machine (JVM). JRE provides the libraries and components to actually execute your code and applications. JVM is what runs your Java bytecodes and implements your code on any platform. You can download JDK from Oracle.

If you’re still on the fence about Java, don’t worry about this step quite yet. You don’t have to commit right away and could start with courses that offer embedded environment.

4. Start with the basics

Even if you’re familiar with other programming languages, a solid introduction to Java is crucial to building a foundation and ensuring success. Once you understand how to compile code and fix errors, you can move onto the next stage of your learning. So, let’s jump into a few key terms and concepts to get you started.

What is Java Syntax? Like any language, a programming language has a set of terms and rules to make meaning and order. Java has its own syntax that you will need to learn to write code. Java is case sensitive, so capital letters matter. For example, endLoop and Endloop would have different uses and meanings. Everything from declaring data types, declaring variables, and using operators will make use of syntax.

What are identifiers? Identifies are the names we use to create all our Java elements. You can use an identifier to refer to an item later in your program. Here are the syntax rules for all identifiers:

  • Identifiers are case sensitive
  • Identifiers begin with a letter (A to Z or a to z), an underscore (_), or a currency character ($)
  • An identifier cannot be a keyword
  • Examples: age, _number, _1_value

What are operators? Operators are symbols that perform particular operations or functions. Think of these like the punctuation of a sentence or the symbols of an algebraic formula. There are several types of operators in Java.

  • Arithmetic Operators: these are used in mathematical expressions. They function the same as in algebra. Examples include: +, -, *, /.

  • Relational Operators: there are six relational operators that compare two numbers and return a boolean value. The six operators are: <, >, <=, >=, !=, ==.

  • Logical Operators: these return a boolean result based on the boolean result of other expressions. Examples include: &&, ||, !.

  • Bitwise Operators: these perform operations of individual bits of number and can be applied to the integer types long, int, short, char, and byte.

  • Assignment Operators: these assign values on its right to the variables on its left. For example, age = 5 defines the value 5 to the variable age.

  • Miscellaneous Operators: these do not fit into any of these categories, such as the conditional operator and the instance of operator.

What are keywords? Keywords are words reserved for predefined meanings or functions. There is an established list of keywords that you will need to learn. For example, the keyword new creates a new object. Take a look at the Java keywords below.

Alt Text

What are data types? In programming languages, data types specify the value of a variable and what type operations can be applied to a variable. There are two classifications of data in the Java programming language:

  • Primitive Data: These data types are built into the Java language and reserved with keywords. There are 8 primitive data types: boolean, byte, char, short, int, long, float, double.

Alt Text

  • Object Data: These data types come built into the Java language, but the programmer can create their own classes. These include Classes, Interfaces, and Arrays.

What is an object? An object is a combination of data with a state (attribute) and behavior (method). An object is given a name using an identifier. Java is extremely object oriented, so your programs are organized around objects rather than functions or logic. Once you organize your objects, you can manipulate them.

An object has three characteristics.

  • State: the data of the object
  • Behavior: the behavior or actions of the object
  • Identity: the unique name of the object

For example, if our object was a cat, we could define it like this:

  • State: age, color, size
  • Behavior: sleep, meow, eat
  • Identity: name of cat

We could make this object using the new keyword.

Alt Text

What is a class? A class is the blueprint we use to create objects and describe their behavior. They are comprised of a collection of fields and methods. Following our cat examples, we could make class of cats to categorize multiple cats into one group.

A class is comprised of three parts:

  • Visibility modifier (e.g. public)
  • Keyword class
  • Name of the class

What are methods? Methods perform actions in your code and display the behavior of your objects. They are comprised of a collection of statements and must be invoked either to return a value or to return nothing.

A method is declared within a class. You declare a method using the name of the method, followed by ().

The main() method is mandatory for every Java program. Think of this as the entry point for your application. You will see it written like this public static void main(String args[]). Take a look at the code below to see an example:

Alt Text

What are variables? A variable is like a container that stores data. Java is statically-typed, so we have to declare a variable before we can use it. There are three types of variables in Java.

  • A local variable is defined within the body of a method, and its scope is confined to that variable.

  • An instance variable is defined in a class and is outside any method or block. Instance variables are created in attachment to an object.

  • A static variable (also known as a class variable) is defined in the same way as an instance variable, but its keyword is static. These are created at the start of your program.

5. Balance your theory and practice

Once you get a grasp of the basics, the best way to learn Java is to jump into practice. Learning only theory won’t get you very far. New learners will master the language more rapidly if they actually practice with hands-on projects.Practice is good for your eventual interview process, and it helps build confidence. Write your own code. Design your own algorithms. Learn from your mistakes. So many experts agree: the smartest way to master Java is to actually use it. Your new motto is “Code Everyday”.

Theory and practice are interrelated, so you need a good balance. You can’t just throw out theory entirely, or you won’t have a good foundation for your actual coding skills. That’s why we recommend spending 20% of your time on theory and 80% on actual hands-on practice.

6. Learn with others

Don’t make the mistake of thinking that your learning has to be in isolation. Java has a really collaborative and active community online. Other than forums and articles, there are also hundreds of meet-up events for developers of all levels. You don’t have to be an expert to start engaging with forums, blogs, events, or online communities.

Trust us. Developers want to share their wisdom and knowledge with you. Don’t repeat the mistakes of others when their wisdom is readily available, and free! As you familiarize yourself with the language, you could even try pair programming. This gives you a chance to learn from others and ask questions as they come up.

Get started right now, for free

If you want to learn Java online, there’s no better time to start than now! While this is a brief intro to Java, there is still a lot more to cover. You can visit our free course, Learn Java from Scratch to introduce you to this exciting language and empower you to start writing your own code. This highly interactive course offers a roadmap for all you need to get started on your Java journey.

Here’s what you’ll learn:

  • Basic Definitions and “Hello World”
  • Variables and User Input
  • Simple Math in Java and Functions
  • Strings and String Processing
  • Conditional Statements and Loops
  • Classes and Inheritance
  • Arrays and ArrayLists

Our course is loaded with hands-on practice, interactive playgrounds, and illustrations to speed up and personalize your learning experience. And the course also comes fully prepared with in-browser embedded coding environments so no need to switch back and forth.

We know that being a beginner is already hard, so taking the first step shouldn’t come at any extra cost or stress to you. That’s why we’ve made our Learn Java from Scratch course completely free. You’ll get lifetime access to the course without any sneaky subscription fees.

Get started on your Java journey today!

Top comments (2)

Collapse
 
cheetah100 profile image
Peter Harrison

As a Java Developer for about 20 years I wouldn't start with Java these days. Python is certainly a popular language and has many benefits in terms of being more succinct. What takes 500 lines in Java can take 100 in Python.

Learning Java is also pretty pointless without learning all about the other parts of the Java ecosystem such as Spring, Hibernate and Maven. To become productive with Java might be longer than with other platforms.

If you are looking at web applications you will also be looking at learning various JavaScript frameworks such as Angular, React or Vue. Each of these comes with its own ecosystem of tooling.

As a former teacher of Java I recommend starting your programming journey with something like Python first. It is easier to get started with the basics without getting to grips with objects and classes out of the gate. Python still gives you objects and classes, but does not force you to use them. Learning Python will give you core competence with all the common programming concepts such as variables, conditionals, loops, functions and so on. You might not need to learn Java after this.

However, Python will form a good grounding for Java later while being easier to learn initially.

Collapse
 
michelemauro profile image
michelemauro

If we are talking of someone who is learning its first language, I totally agree with you. I may even hint at Scala as another interesting first language, but you need a very skilled teacher, as most resources online are not oriented to first-language learners.

But if you have in mind a junior or a professional who is eyeing a new field to enter into, Java is a very good choice. The market is huge, the OSS ecosystem is vast, and the resources are everywhere. So, as a second or third language is an excellent choice.