Programming Basics with Java - Part 1

Konstantin Borimechkov
5 min readMar 11, 2023

--

I was wondering what to write in my new blog post and came up with the idea to start series of posts, where I go trough the programming basics using Java ♨️. This is the first part of hopefully many others, in which we will go from ZERO to running our first Java application, so you don’t need any prerequisites except a computer 😁!

Firstly, what is Java?

Java is one of the most widely used programming languages with an estimate of 3 billion machines running it globally. Its use in a wide range of applications and industries, including desktop applications, web applications, mobile apps, enterprise software, scientific computing, and more.

Java is a object-oriented programming language (OOP is a topic, which we will discuss in future blogs) that was created to make it easy for programmers to write code that can run on different types of computers and devices. When a programmer writes Java code, it is compiled into a format that can run on any computer that has the Java software installed.

Why Java?

There are many reasons on why we choose Java over other programming languages, but this is out of scope for this blog post. With that said, here is a good explanation on the topic!

Where do we write Java?

Java code is typically written in an integrated development environment (IDE). Here are the most widely used IDEs for Java development:

  1. IntelliJ IDEA: IntelliJ IDEA is a commercial IDE for Java development that is known for its advanced features and productivity tools. It offers features like intelligent code completion, refactoring, and debugging, and supports many popular Java frameworks and technologies.
  2. Eclipse: Eclipse is a popular open-source IDE for Java development, which provides a wide range of tools and plugins for building Java applications. Don’t make your life harder by using Eclipse, please 😂
  3. Visual Studio Code: Visual Studio Code is a lightweight, cross-platform code editor that offers advanced features like syntax highlighting, code completion, and debugging for Java development. It supports many popular Java frameworks and technologies, and can be extended with plugins for additional functionality.

The IDE of choice for this ‘course’ will be the Intelij IDEA as it’s the most widely used in companies and generally provides the best Java developer experience.

How to set up InteliJ IDEA?

  • Download and Install IntelliJ IDEA: Visit the IntelliJ IDEA website (https://www.jetbrains.com/idea/) and download the community/free version for your operating system. Once the download is complete, run the installer and follow the prompts to install IntelliJ IDEA.
  • Once the installation is complete, open IntelliJ IDEA from your applications folder (on macOS) or start menu (on Windows). The first time you open IntelliJ IDEA, you will be prompted to set up your preferences and select a theme. I prefer the dark theme as it’s not that hard on my 👁️.
  • Create a New Project: To create a new project in IntelliJ IDEA, select “New Project” from the Welcome screen or the File menu. Choose the type of project you want to create, such as “Java,” name it and select the SDK or JDK you want to use (you may need to download one by just clicking on the ‘Download JDK’, choosing version 19 and for example Oracle OpenJDK for vendor).

Now click on ‘Create’ and see how InteliJ does it’s magic! 🔮

  • Navigate to the Main class, which InteliJ automatically generated, because we’ve ticked the box for ‘Add sample code’, as you can see on the picture above.

You should see this in the Main file. Now try to modify the text “Hello World!” with whatever you want and run the application by clicking on the green arrow you see next to the lines of code (or use Shift + F10 on Windows). Here is my result:

The program printed the text we’ve written! Congrats 🥳

BONUS: Diving deeper into the code we ‘wrote’ 😅

In Java, the main method is the entry point for a Java program. When you run a Java program, the Java Virtual Machine (JVM) starts executing the code from the main method.

Here is an example of a simple Java program with a main method:

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello Medium! This is our first line of code!");
}
}

In this example, we define a class called HelloWorld, which has a main method that takes an array of String objects as its argument. The main method prints the message "Hello, world!" to the console using the System.out.println method.

The main method must have the following signature:

public static void main(String[] args)

The public keyword means that the main method is accessible from outside the class. The static keyword means that the main method is associated with the class itself, rather than an instance of the class. The void keyword means that the main method does not return any value. The String[] args parameter is an array of command-line arguments passed to the program when it is run.

In summary, the main method is a required method in a Java program, and it is where the program begins its execution.

🚀I hope you’ve managed to run the application and if you have any questions feel free to drop a comment 💬! In the upcoming blogs I will cover things like basic operations, if-else, for-loop, while-cycle, arrays, lists and etc.. All these fundamental things you would use in your day to day life, writing code!

--

--

Konstantin Borimechkov
Konstantin Borimechkov

Written by Konstantin Borimechkov

Writing Code For a Living 🚀 | Software Engineer @ Tide | Writing Blogs About Python & CS

No responses yet