A blog for computer science passionates.

Wednesday 29 January 2020

Hello World, Hello Java!!!

Hello Friends!!!!

In this article, I am going to share one big thing i.e. Say Hello World i.e. How to start Java programming. Let's start.

I give you one suggestion before the start, if you are a beginner in programming please use notepad as an editor don't use any smart editor for Java or any other development. For Java, Netbeans and Eclipse both are smart editors but don't use it if you are a beginner otherwise you don't feel Java programming and work hard and tough so we can remember syntaxes and can learn more effectively.

Let's start Java Programming. Our First Program is to say Hello World, Hello Java!!!

So for that open notepad (I am working on Windows) or open run (window+r) and type notepad press enter.

It will open notepad now type below program:


And you just need to run this code in the command prompt: To open a command prompt again go to the run (window+r) and type cmd and press enter or click OK button.

Now you need to open your path i.e. your drive and directory. Just follow the following commands

To open drive in cmd:
type drive letter and colon i.e. if you want to open d drive, type d: command.
And you will get your drive open with

d:\>

To open directory (folder) that should be available in your drive use below command:

cd <your_directory_name>\<another directory name (if any)>

For Example, in d drive, we have java folder in which ch1 folder so type

This command opens all directories in one command
d:\> cd java\ch1

or
This command opens directory one by one.
d:\> cd java
d:\java> cd ch1

it will open d:\java\ch1> directory.Check out this video on how to open drive and directory in cmd. (I show two different ways to open directory either one by one or in a hierarchy)

To Compile & Run Java Program:

We have javac command to compile the program and java command to run the program.

For example, in our above example we define a class with the name SayHello now we just save this file with the name "SayHello.java" and just compile this file with the following command:


javac SayHello.java
This command generates a class file and  we need to run this class file by using the following command:


java SayHello

This command shows the output "Hello World, Hello Java!!!" See the figure below:
Fig. The output of the Java program

So, that's it for today in the next article I will tell you about what we exactly use i.e. which classes and what is the main method and some other aspects.

Till then Happy Coding☺

No comments:

Post a Comment