A Brief Introduction to Java

One of the most used programming languages in the world

Albert Ming

--

Photo by Emile Perron on Unsplash

Perhaps one of the most widely used and respected programming languages in the world is Java. It has a wide range of uses, including web, artificial intelligence, and database applications. Not only that, it is flexible as an object-oriented language that can be used on many different platforms such as windows and mac. Coming into college, I had some experience with Java, but it was really through my first year in university where I expanded my skills. Both my introductory and data structures and algorithms classes were taught in Java, allowing me to become familiar with the language. In this article, I hope to explain some of the most basic concepts for a complete beginner to help them get on their way to become at master at programming in Java!

First Program and Line of Code

To start from the very beginning, open an IDE of your choice, and create a file called Main.java. In the file, write these lines of code

public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

In Java, code must run within classes, and there must also be a main( ) method: this is where the code will be executed. In this case, we are leveraging the System class to print stuff out for us to see, and we just need to call System.out.println( ). You can also use System.out.print( ), which will output text on the same line instead of on a new one. Try editing the message and adding more statements to see what the new output is! Note that in Java, it is necessary to put a semi-colon after lines of code that aren’t class brackets. This can be slightly annoying since some languages like Python or Javascript don’t require this, but if your code outputs an error, always check for missing semi-colons first.

Types and Variables

Personally, I believe that these are the most important concepts to get down first because of how frequently they show up in computer programs. You can think of a variable much in the same way you’d think of a variable in mathematics: it holds or stores something. Now in mathematics, variables typically store a numeric quantity, but in computer science, that is not…

--

--