Let's execute in Java!

Let's execute in Java!

Basics before you execute programs in Java

The Stuff need to know before you Code!

There are several programming languages like Python, Java, C++, etc. Each programming has its unique way of writing or programming. The syntax is a set of rules for programming a programming language that makes it different from other programming languages. A syntactically correct program can be successfully compiled and executed else it won't. To be a successful programmer, you have to develop a detailed knowledge of syntax. The syntax is just a part of the story, you need to know more about programming. The syntax is like all the characters in a drama or a movie, which helps to drive our program forward. If you write a program without any syntax errors and you get your desired output, it is known as semantic.

To execute a java program on your computer, you need to have Java Virtual Machine installed on your computer. So, to install please refer to this video link.

Basic Java program

This is just a block of code, please don't try to understand it. I'll explain everything in this detail in this blog itself. Please stick to the concepts which I'll be explaining now.

//PRINTING HELLO WORLD
//BASIC SYNTAX PROGRAM IN JAVA
class HelloWorld{
  public static void main(String[] args){
System.out.println("Hello World");
}
}

in this code, the line System.out.println("Hello World"); is a subroutine call statement. It is a built-in subroutine in Java that is already defined as part of the language and therefore automatically available for use in any program.

This subroutine call statement is used to display what we include in those brackets (parenthesis). To print a sentence or a word, we just need to include " " marks to help the compiler that what needs to display to the user, this is called a String data type.

At last, it is mandatory to include a semi-colon after the parenthesis. Because it is an indication that's the end of a subroutine of a program. Now, the output of the program will be - Hello World

In the beginning, you have seen slashes, and thereafter a common sentence. It refers that it is a comment. A comment is a part of code which neglected by the compiler. Let's say you had written code and you are re-visiting it after a long time.

You will be confused by seeing your own code. Now, to avoid these confusions we use comments, in which we write about code, which can be your own explanation of some blocks function or anything related to the program. Compilers won't compile these comments and it is only useful for the coders who actually work on it.

In Java, there is a thumb rule that, to name the program file name and main class name should be the same. For the program file Helloworld.java, I named my main class name HelloWorld.

Summary

public static void main, as we had discussed in earlier blog public is one of the access specifiers in Java. The specifier public means that this subroutine can be called from outside the program. Up to now, this information is sufficient to run a program seamlessly. Because further learning about the other keywords of the main function can make you confuse. We will discuss everything related to the main function of OOPs and upcoming blogs in this series.

Did you find this article valuable?

Support ManjuBlogs by becoming a sponsor. Any amount is appreciated!