[Jon's Java class] A simple Java Program.

Jon™
by Jon™ · 3 posts
10 years ago in JAVA
Posted 10 years ago · Author
Once you are done with the Introduction, let's move on and create a simple Java program.

I dislike the famous "Hello World!" program and frankly got tired of it being spammed all over the internet so we won't go for it. But instead, we will take a revolutionary step by starting by creating a "Jon is awesome!" program.

Just write down the following code in Editplus or Notepad++ as it is and I will explain bits and pieces of it as we progress.

Code
class Jonisawesome{

public static void main(String[] args)
{

System.out.println("Jon is awesome!");

}

}


Once done, save the file in a directory with the name "Jonisawesome.java". It is important that the file should end with .java extension and the name of the file should be same as the class name, which in our case is "Jonisawesome".

Running your Java file!

Once you have saved your file;

Step 1: Open up the command prompt/cmd.

Step 2: Change the location of the cmd prompt that of which your program's stored in.

( This can be done by using "cd <-- Paste the location -->" )

Then type in the following;

Code
javac <--Insert the location of Jonisawesome.java --> 


It wil compile and create a .class file. Now if you check the directory, it should contain a .class file by the name Jonisawesome.class.

Step 3: Type in

Code
 java Jonisawesome 
and hit enter.


If everything goes right you should have something like this. If you haven't figured out how to change directories on cmd, check the below screen.

Image

Explanation:

Here is a brief explanation of the program. I won't go into details here as you need to learn a few more concepts before going into the details. But no worries, we will learn it in time!

-> In the above program, Jonisawesome is a class.

You can create your own class by using the keyword "class".

-> Inside the class, we used a method "public static void main(String[] args)". For now, just remember that without this method, no class will compile. I will explain what this is about when it's time.

-> System.out.println() is the function used to display the output in the monitor. Whatever you write inside the " " in the System.out.println("") function will be displayed in the monitor.

In our case, it was "Jon is awesome!".

Assignment:

If you have any doubts, post below and I will clear it for you.

Once done, create a Java program that says Yournamehere is awesome!
Posted 10 years ago · Author
I am a bit tied up iRL having interviews on a daily basis but I haven't forgotten about this certainly!
From next week, I'll start with more basic programming stuffs, OOPs, File Handling, Exception Handling, Collections and Threads.

Then if possible I'll go on with JDBC, Servelets, JSP, Hibernate and Springs.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT