Introduction to Java Programming Basics

Thumb

Introduction to Java Programming Basics

Developed by Sun Microsystems in 1995, Java is a high level programming language and computing platform. It is a general purpose programming language that is class-based, object-oriented, and created, so it can have less number of implementation dependencies. Java offers many benefits and hence, it has it gained wide popularity in the IT world. Due to its versatility and significance in web based and mobile based applications, it has laid the foundation for most networked applications. By learning the Java language and how to compile a Java program, you can do:

  • - Web-based content development
  • - Enterprise software development
  • - Games and mobile application development

Most Popular Technologies Survey

A survey done by Stack Overflow, which was taken by 64,000 developers shows that Java is the third most popular programming language amongst coders in the year 2017. The fact that it is still so popular amongst developers, even after 23 years of its creation, is a telling statistic and shows the value of Java in the IT world.

Java Programming Basics

Java is an object oriented language and its syntax is quite similar to that of other object oriented languages like C++.If you have some grasp on C++, you will definitely learn Java quicker.

The initiation of most coders in the world of Java begins by learning first Java program hello world. This program familiarizes you with the basic syntax of Java programming.

Hello World Program

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello World");

    }

 

Explanation

1. Public Class

The program begins with a public class called Hello World. Using a class is an absolute must for coding in Java. Also, the name of Java source file must be same as your public class. One cannot have more than one public class in a Java source file, though it is possible to have more than one class. Besides public class, Java also has private and protected classes with different usages.

2. The Main Method

The main method is very important as it is the entry point of a Java program. When "java" command executes on a system, it creates a Java Virtual Machine which is known in short as JVM. After that, JVM calls main() method of the class, which was supplied as argument. In the hello world program, the class as we know is "HelloWorld". Each word in public static void main (String args[]) has its own meaning. You can learn these meanings later for increasing your grasp on Java.

3. The String Array

If you notice the argument in the hello world program to the main method, it is a String array. The arguments that you pass to your program get stored in this array. These arguments are separated by white space. In case, you pass two arguments, array will contain two elements as provided in the example below:

Example:

$ java HelloWorld firstArg secondArg

This argument can be accessed from array: args[0] and args[1].

4. The System.out.println()

The println() command is able to accept a String. It prints on the console and also adds a new line character. System in this command is actually a class in java.lang package for System related elements of this language. The dot (.) is an operator, which is used for gaining access to members of a class, such as fields and methods. The word “out” is an object of PrintStream class. It defines println() method, and it is the main reason why we need out to call println() method in Java.

How to Compile a Java Program?

Once you have written the first Java program “Hello World”, you need to learn how to compile it. You can use modern IDEs’ like “Eclipse” for compiling and executing your code or go the old fashioned way by making use of command prompt and Notepad in any windows based computer.

  1. 1. Write the code in notepad and save your HelloWorld program into a file also named as HelloWorld.java.
  2. 2. Compile your HelloWorld.java file to create class file. For performing this action, move to the directory, which has your HelloWorld.java file and execute the command mentioned below:
  3. 3. $ javac HelloWorld.java
  4. 4. In case, you see a class file "HelloWorld.class" file in the same directory, it means that your first Java program hello world is compiled.

Learn Better Concepts with Best Certification

For better understanding of concepts, it is best to learn the basic fundamentals like how to compile a java program from a reputed institute like QuickStart. With its nearly three decades of experience in IT training, it offers the best platform for Java career aspirants.

About The Author
Arif
Digital Marketing Manager at QuickStart

Arif Ahmed

Arif has six years of experience in digital marketing. He has had the privilege of working in various industries such as media houses, advertising agencies, travel agencies, and SaaS tool companies. He specializes in web analytics and technical SEO.

Previous Post Next Post
Hit button to validate captcha