How to start coding Java in 60 minutes

How to start coding Java in 60 minutes

​​How long have you been thinking about starting coding in Java? Advised to dive deep into tutorials for endless hours, learned the basics already but not a single line of code yet? Fear not!

You will illustrate the basic syntax of Java in 60 minutes from now on. Java is a platform-independent language that means “Write Once Run Everywhere.” 

Let’s explain this a bit more; You can develop a Java application  on any device, you will have to compile it into a standard bytecode, and the produced bytecode is expected to run on any OS which has Java Virtual Machine (JVM)

Running your first Java code is simple and a fun process. 

A Simple Java Program

To run a Java program, we need to have a Java Development Kit (JDK) installed on our local machine.

How to install JDK?

macOS

Download the JDK.dmg file, jdk-16.0.1_osx-x64_bin.dmg from the Java SE Downloads page, double-click to install, and follow the instructions.

Windows

Download the JDK.exe file, jdk-16.0.1_windows-x64_bin.exe from the Java SE Downloads page, double-click to install, and follow the instructions.

When you complete the installation, check the Java version on terminal/cmd to verify the installation:

				
					$ java -version
				
			

Expected output

				
					java version "16.0.1" 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)
				
			

Writing your first Java program

A Java program gets executed in a specific order. So to start a program, we need to let Java Virtual Machine (JVM) know where to start execution. And all instructions are being implemented in Java classes. So we can define a Java class as a set of grouped instructions and for related data.

Java Class Declaration

				
					
public class MyFirstClass { 
}
				
				
			

This Java code needs to be in a file with same name as the class and ending with .java suffix

So let’s create a file with the name MyFirstClass.java and place the above code inside.

A Java program starts the execution from the main method;

				
					public class MyFirstClass {
   public static void main(String[] args) { 
   } 
}
				
			

We defined a class and a main method but the method is empty and there are no instructions to be executed. Let’s try to print something to the console and add this as an instruction to the main method.

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

Running a Java Program

JDK has a command-line compiler with the name javac.

To be able to run a Java class; we need to compile source code into Java bytecode first and then start the execution. 

To compile our source code into the Java bytecode; in the terminal go to the folder you saved the file MyFirstClass.java and run the below code. 

				
					$ javac MyFirstClass.java
				
			

This will create a MyFirstClass.class file in the same folder with your class name which can be used for the execution. 

Trigger the execution:

				
					$ java MyFirstClass
				
			

Output:

				
					Hello World!
				
			

Congratulations! You are at the point where Java begins. The keys to learning a programming language are practice and consistency.

I strongly suggest you practice with the Java coding challenges on Exercism.io. Exercism is a great platform with lots of free, gamified scenarios for you to improve your Java skills until our next post! Don’t forget to share this post on social media!


Learn more on Exercism

9 thoughts on "How to start coding Java in 60 minutes"

  1. Pingback: Exceptionly
  2. Pingback: Exceptionly
  3. Pingback: Exceptionly
  4. Pingback: Exceptionly

Leave a Reply

Your email address will not be published. Required fields are marked *

#

“Exceptionly was such a fast and efficient process. Complete game changer for hiring remote.”

Liam Martin
Co-Founder at TimeDoctor

#

“Great service, outstanding speed, stunning quality.”

Andy Tryba
CEO at Gigster

Is Exceptionly an outsourcing business?

No. We encourage our clients to do direct hires. We provide payroll consultancy and services in a 100% transparent way if our clients are new to remote hiring.

Is Exceptionly a database of candidates?

Not really, data is only a small part of our business. While we own over 2 million publicly available software engineer data evaluated, our power lies in hands-on testing and engineer-to-engineer technical interviews.

Is Exceptionly expensive?

Exceptionly is more cost-efficient than any other serious competitor who owns a decent technical testing funnel. If you compare Exceptionly with HR agencies who only do resume screening before endorsement, yes, it is expensive.

Who is the founder of Exceptionly?

Sinan Ata is the founder of Exceptionly, who previously built two global technical talent acquisition enginess and tested over 2.5 million software engineers in his career.

Still have questions? Contact us.

Ready to meet top-notch engineers?

Let's get your talent pipelines up and running!

HIRE WITH EXCEPTIONLY

No hidden fees.