Java Fundamentals Explained

If you are new to coding, Java basics are for you. For both beginner programmers and professional programmers and web developers, choosing a new programming language to learn is often a difficult decision to make, because there seems to be some pressure to master many programming languages.

Learning various programming languages ​​is something that most programmers end up doing. However, it doesn't have to be all at once, as it usually happens on the fly, that is, you face a certain problem, or want to do something, and you learn a programming language that is well suited to that task. .

But sometimes, this decision is more conscious and we make it to acquire a valuable skill or increase our chances of getting a new job by learning about an in-demand technology, and this is the case when you want to learn the Java programming language.

Why learn Java?

If you are new to coding, Java basics are for you. For both beginner programmers and professional programmers and web developers, choosing a new programming language to learn is often a difficult decision to make, because there seems to be some pressure to master many programming languages.

Learning various programming languages ​​is something that most programmers end up doing. However, it doesn't have to be all at once, as it usually happens on the fly, that is, you face a certain problem, or want to do something, and you learn a programming language that is well suited to that task. .

But sometimes, this decision is more conscious and we make it to acquire a valuable skill or increase our chances of getting a new job by learning about an in-demand technology, and this is the case when you want to learn the Java programming language.

But Java is not just a good way to get a job, because this programming language is suitable for almost anything and, thanks to the Java Virtual Machine, it can run almost everywhere. There are video games successfully created in Java, and if you want to create Android apps, Java is the way to go.

In the field of web development, Java has been one of the most popular languages, due to its robustness and scalability, which makes it widely used in companies for their backend. This makes it a great language for getting jobs in web/server-side development.

Start learning Java basics now

Learning Java is exciting because it has a very large community, it is a more than solid language and it uses Object Oriented Programming at its core, which is a very important programming paradigm that you will eventually want to learn, and Java is a very good way to learn. understand it.

The first thing you'll want to do is choose a free Java IDE (integrated development environment). There are a few options, but let's use the IntelliJ IDEA community version, which is free, complete and modern (an attractive user interface is also important).

While we are installing IntelliJ, let's download the JDK (Java Development Kit), which allows us to write programs with the .java file extension. Currently the stable version is JDK 12 and you will want to use this.

Now, let's create a new Java project in IntelliJ, in the SDK list of the project, if it is empty, click new and add the path of Java on your computer (where you unzipped or installed the JDK). Next, we want to create a project from scratch, without using templates or libraries. Name it something like Hello World.

In the project, in the src folder, let's create a new class by right clicking and going to new. When using Java programming, there is a convention for creating packages and at first they have a particular naming convention. In the name of the Java class, we will say something like: com.example.helloworld.HelloWorld.

Let's analyze this:

  • with: A convention, it is good to follow it.
  • example: the name of the company. Of course, we don't need to have a company to program in Java. Simply use a name that covers the entire program. If your program is a game of tic-tac-toe, then we would say tictactoe.
  • Bonjour Monde: the name of the package. We can see packages as groups of classes that together make sense. If we make a calculator, we might want a package for math operations, so we could say calculator.operations.
  • HelloWorld: The name of the class, in this case exactly called HelloWorld. If you are making a Pac-Man clone, this could be pacman.logic.ghost.

Finally, let's write some code and analyze it as well.

By default, IntelliJ will output something like:

package com.example.helloworld;

public class HelloWorld {

}

We have the path of our package without the class name, which is right below it.

But, depending on how familiar you are with programming and object-oriented programming, you may be wondering what the public HelloWorld class means.

Knowing what everything is is very important. However, to get started with Java, we can start by doing certain things outside the box and eventually learn more in depth what each of these keywords does.

Public is an access modifier and in Java there are two more (private and protected). We use Public in classes and methods. Public means that other classes in the package can access this HelloWorld class. If you don't add Public and just say class Hello World, the class will be public by default.

The following keyword tells Java that we are creating a class and the following is your own name for the class. For classes, the convention is to use PascalCase, that is, no spaces, hyphens, or underscores, and to capitalize the first letter of each word.

Now let's complete this example:

package com.example.helloworld;

public class HelloWorld {

public static void main (String [] args) {

System.out.println(“Meow, world!”);

}

}

Now we add some code to that HelloWorld class. This is called a method, that is, a function within a class. This one, main one, is especially detailed. Don't worry, usually only one main method is expected and it is written this way by design. Let's analyze it:

public: Like classes, methods also use access modifiers. The main method is always public.
static: We haven't learned about instantiation, but this means that this method can be used from other classes without creating instances of this class. The main method is always static.
void: The return type of the method. This method returns nothing, so it is set to overridden.
main: the name of the method. For main, the Java compiler will always expect it to be called that way.
(String[] args): The method arguments. String[] means that it is an array (a collection) of strings and args is the name of the argument. This is also default for the main method. In a proprietary method, we would use something else, or nothing, depending on what we need.

Excellent! Remember that that (somewhat scary) way of writing that method is just a design decision by the creators of the language, and the Java compiler simply wants to see it somewhere in the program. Typically, it will go in a class called Main.java, but it is not required.

We can finally print our important message to the world! And we do it with this line: System.out.println(“Meow, world!”); But what does that mean?

Compared to other languages ​​like JavaScript, where the function to print is console.log(), or Python, where it is print(); This may seem a little intimidating. Fear not, this is how it was done and it's not that terrible.

If we get rid of the System.out part, we arrive at println, which is actually the name of the print function in some programming languages. Now we can see System.out as the origin of println, the classes where this method we are using comes from.

Once we have overcome this first, sometimes not very friendly, encounter with Java, we will be free to explore a truly powerful, popular, in-demand and useful programming language. With it we can practice object-oriented programming, learn to organize our programs and do many things! You may want to explore the Swing and JavaFX GUI libraries to create cross-platform desktop programs with Java!

But if you are an absolute beginner who wants to learn coding or have some coding knowledge in other languages ​​and want to learn Java, you can come to Ubiqum Code Academy and take the Full Stack Web Development with Java program (online or on campus) . and become a fluent programmer in this highly demanded language.

Do you want to know if your future in data analysis starts here?

Other articles of interest

What is a programming bootcamp?

What is a programming bootcamp? characteristics and operation Possibly you have a friend, family member or acquaintance who has told you about the programming bootcamp or coding bootcamp. The unstoppable

Read more »