Getting Started with Java

Start Programming with Java, first sample code and some additional details

In the first article I generally described the usages and abalities
of Java. Now we have better to start the real Java. The programmers of
C and C++ would find Java very friendly and familier, because it’s similar
to C++ in syntax. On the other hand Java is a full object-oriented
programming language.

Everything in Java is an object, even a Java program. We suppose you
know the basic concepts of OOP and start Java.

Attention: C++ programmers should remember that there are some
differences between OOP in Java and OOp in C++.

To see how lovely and simple Java is, let’s have our first program
just now:

(Sample1):

class startingJava {
     
        public static void main {

             System.out.println("This is my first Java program.");

           }
       }

After installing JDK (Java Develepment Kit) do the following setting
on your Windows:

1. Go to the folder you have installed JDK and creat a new folder
in the root called “Programs”.

2. Right-click on My Computer icon in your Windows Desktop.

3. Go to Properties/Advanced/Envierment Variables/

4. In the User variable,press New. Set the Variable Name to: “path”

5. Set the Variable Value to bin folder on the path you’ve installed
JDK.

( for example: C:\Java\bin\ )

6. Press OK.

7. In the System variable,press New. Set the Variable Name to:
“Class path”.

8. Set the Variable value to the path of the folder you have
recently created.

( for example: C:\Java\Programs\ )

9. Press OK.

Note: You can download final version of JDK from following link:

https://jsecom16.sun.com/ECom/EComActionServlet/LegalPage:~:com.sun.sunit.sdlc.content.LegalWebPageInfo;jsessionid=jsecom16.sun.com-1386d%3A40b1909d%3A57cbd686844da024


Running the first Program:

In order to compile your first Java program, type Sample1 code in a
simple text editor such as Windows Notpad.

Atention: Don’t use Wordpad or such stuffs to do the job.
Additionally don’t use any IDE to type and compile your
code. You’d better to learn to do it even without IDEs.

Then save the file in the Programs folder you’ve created as “startingJava.java”. Run the Command Prompt and change the current path to the JDK’s Progams folder. Type the following command and press Enter key:

javac startingJava.java

After a few seconds, Command Line would appear again while your
first Java program have been compiled. JVM (Java Virtual Machine)
now have created a class file for the program called startingJava.class .
The class file contains BYTE CODEs which is clearly similar to
Assembly codes. So there wouldn’t be any .EXE file (executable file)
after compiling. For the next step, type the following command and
press Enter key:

java startingJava.class (or) java startingJava

Now the JRI (Java Runtime Interpreter) changes the byte codes to
the processors commands. You can see the output in this way:

This is my first Java Program.

Close the Command Prompt Window.

Cogratulations ! You made and compiled your first Java Program.
Now at the end of this article let me ask some question. I’m going to
answer them in the next article:

  1. At first, why did we do those settings on Windows ?
  2. While Interpreting .class file, why do you can type in the both
    of the following ways? :

java .class (or) java

  1. Why does the Java compiler make byte code instead of Assembly
    code ?

In the next article we are going to start learning the Java’s Basisc.

Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to Geekpedia.com. With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

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

Back To Top