Day to Day: Learning Java Programming Language – Part I

In 1995 when c++ programming language were widely used. An employee of Sun Microsystem working on a platform called ‘Green‘ Developed a programming language and named it as ‘oak‘.

The name was inspired by an oak tree which he use to see outside of his office windows. Later the name oak was replaced by Java.

Java Programming language was developed by James Gosling and hence James Gosling has been honoured as the Father of Java Programming Language.

James Gosling - Father of Java Programming
James Gosling – Father of Java Programming

Now the question is, if there already was such a functional programming language (c++) available, why Mr. Gosling and his team needed a different programming language.

Java was intended with the Features:
  1. Write once, run anywhere
  2. Cross Platform Program Development i.e., Architecturally Neutral
  3. Security
  4. Class based
  5. Object oriented
  6. Support for web technologies
  7. Robust
  8. Interpreted
  9. Inheritance
  10. Threaded
  11. Dynamic
  12. High Performance

Before Java was developed, The program written on a computer or for an architecture won’t run on another computer and architecture, hence while developing Java the team focus mainly on cross platform functionality and from there the concept of write once, run anywhere came, which remains the quote of sun microsystem for a long time.

Java program runs inside JVM (Java Virtual Machine) which adds an extra layer between System and program, which further means extra security. Other programming language prior to Java was not having such feature which means a code being run could be malicious can infect a system or other systems attached to it, however Java maintained to overcome this issue using JVM.

Java is a OOP (Object Oriented Programming) Language. By object oriented feature, it means all the entity is a object which further suggest Real World Object.

When Java was being developed at Sun, coincidentally web technologies has started to take take shape and the Java development was highly influenced with this, and even today web world uses Java more than any other language. Java is strictly an interpreted language, which means Java executes the source code directly by translating the source code in an intermediate form.

Java is robust in nature i.e., it can cope up with errors be in input or calculation. When we say Java is dynamic programming language, we mean to say that it is capable of breaking complex problems into simple problems and then execute them independently.

Java supports threading. Threads are small processes that can be managed independently by operating system scheduler.

Java Support Inheritance, which means relation can be established between classes.

No doubt! Java was developed as a successor to ‘c‘ and ‘c++‘ programming Language hence it inherit a number of features from its predecessor viz., c and c++ with a number of new features.

Learning Java from the point of view of carrier is highly appreciated and one of the most sought after technology. The best way to learn any programming language is to start programming.

Before we go to programming, one more thing we need to know is: the class name and program name should be same, however it can be different in certain condition but by convention it is always a good idea to rename the program as it’s class name.

Javac is the compiler of Java Programming Language. Obviously you should have Java installed and environment variable set. Installing Java on RPM based system is just a click away as on Windows and more or less on Debian based system.

However Debian Wheezy don’t have Java in its repo. And it is a little messy to install Java in Wheezy. Hence a quick step to install on debian is as below:

Installing Java in Debian Wheezy

Download correct Java version for your System and architecture from here:

  1. http://www.oracle.com/technetwork/java/javase/downloads/index.html

Once you’ve downloaded , use the following commands to install in Debian Wheezy.

# mv /home/user_name/Downloads /opt/
# cd /opt/
# tar -zxvf jdk-7u3-linux-x64.tar.gz
# rm -rf jdk-7u3-linux-x64.tar.gz
# cd jdk1.7.0_03
# update-alternatives --install /usr/bin/java java /opt/jdk1.7.0_03/bin/java 1
# update-alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_03/bin/javac 1
# update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.7.0_03/jre/lib/amd64/libnpjp2.so 1
# update-alternatives --set java /opt/jdk1.7.0_03/bin/java
# update-alternatives --set javac /opt/jdk1.7.0_03/bin/javac
# update-alternatives --set mozilla-javaplugin.so /opt/jdk1.7.0_03/jre/lib/amd64/libnpjp2.so

For RHEL, CentOS and Fedora users can also install latest version of Java by going to below url.

  1. Install Java in RHEL, CentOS and Fedora

Let’s move to programming section to learn few basic Java programs.

Program 1: hello.java

class hello{
public static void main (String args[]){
System.out.println("Sucess!");
}
}

Save it as: hello.java. And Compile it and run as shown.

# javac hello.java
# java hello

Sample Output

Sucess!

Program 2: calculation.java

class calculation { 
public static void main(String args[]) { 
int num; 
num = 123;
System.out.println("This is num: " + num); 
num = num * 2; 
System.out.print("The value of num * 2 is "); 
System.out.println(num); 
} 
}

Save it as: calculation.java. And Compile it and run as shown.

# javac calculation.java
# java calculation

Sample Output

This is num: 123
The value of num * 2 is 246

Do it Yourself:

  1. Write a program that ask for your first name and last name and then address you with your last name.
  2. Write a program with three Integer values and perform addition, Substraction, Multiplication and Division and gets the custom output.

Note: This way of learning will make you know and learn something. However if you face problem in writing programs of ‘Do it Yourself‘ you can come up with your codes and problems in comments.

This Section ‘Day to Day‘ is a concept of Tecmint.com and from here we will be giving you tutorials of every kind. This Article will be extended with programs of entry level to advanced level, article by article.

We will soon be coming up with the next article of this series. Till then stay tuned.

Like and Share Us and Help Us to Spread.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Avishek
A Passionate GNU/Linux Enthusiast and Software Developer with over a decade in the field of Linux and Open Source technologies.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 Comments

Leave a Reply
  1. Well, I have one thing to tell you.

    Since the version 7, Java is based on OpenJDK, so you don’t need Oracle Java to run Java applications if you have OpenJDK 1.7. Currently I can run the official NetBeans under OpenJDK and I don’t have any problem.
    https://blogs.oracle.com/henrik/entry/moving_to_openjdk_as_the

    I think that Debian Wheezy uses OpenJDK 1.7, so you don’t need to install Oracle Java to work those technology on Linux.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.