A Closer Look to code HelloWorld in Java

A Closer Look to code HelloWorld in Java

September 22, 2019
Oracle DBA
oracle dba oracle database management database management system database oracle performance tuning oracle sql learn sql learn personal injury attorney new york mesothelioma lawyers mesothelioma lawyers new york mesothelioma lawyer the stock market plumbing retirement planning barclays stock broker financial advisor personal retirement financial advisor

The previous page was about to try your first “HelloWorld” code and to see what does it return.

The same following code we did run in the last chapter and now it’s time to have a look what does this all mean. First of all it’s very important to know that Java is case-sensitive and all class name or other declaration names should be used with exact sames and all upper and lower letter as they are in the declaration or object creation part.

About the code, the first thing you may note is “class HelloWorld“. Java is an object orjented language and that does mean we have to write our code into a “class“. The classes are called or refered in Java as objects. In other words you’ll become a fan of classes.

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

The second line “public static void main(String argv[])” is the starting point for your program and every keyword defines it’s signature. For example some explination:

  • public” – access to everybody
  • static” – this program runs without creating an instance of the main class “HelloWorld”
  • void” – set the method a “do not return a value” option
  • main” – the method name

The “String argv[]” defines that we are dealing with a text in this code.

The third command line “System.out.println(“Hello World!”);” is the actual code that does something. What does all this words separated with dots.

  • System” – a predefines class group that holds many common and useful commands.
  • out” – a method that belongs to “System” class and it’s purpouse is to send something to screen our out from the program.
  • println” – a method to print a text with a new line option on the screen.

The method has a input variable “Hello World” that will be used by the “System” method to print on screen.

This is the way how it looks on the console window and the input variable “Hello World!” on it.

java training java curso java in java latest java latest how to design a website html web page make web page personal injury attorney new york mesothelioma lawyers mesothelioma lawyers new york mesothelioma lawyer the stock market plumbing retirement planning barclays stock broker financial advisor personal retirement financial advisor

To run the same code without Eclipse you would need to use save the file as HelloWorld.java and the following two commands are Java platform built-in commands to compile the code and the last one is to execute it.

Java tool “javac” compiles your the source code and the compiled version can be used in web or other programs. The compiled file will loose .java part and the file name will be only “HelloWorld“.

javac HelloWorld.java

The following command is for running compiled Java code and the command name is “java“.

java HelloWorld

Using those last two commands will be useful when the Eclipse tool or other Java development porgrams are causing a problems and the compilation needs to be done via console.

P.S. When you are using the java command on Unix or Linux environment make sure the compiled file has a execution permissions.

See Also:
My First Java Code Java Home

Leave a Reply

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

*