Java-Basic Concepts

In Java-Basic Concepts on July 7, 2009 at 4:52 PM


What is Java?

Java is an Object Oriented Programming Language.

What is meant by Object Orientation?

Object Orientation means, everything is object. confusing? The programming simulates into different objects to simplify the programming and avoid tight coupling.

Each object have some characterstics and some features.

Ex: take a person is a real-world object have some characterstics like name,designation etc…and some features like walk,read,eat etc…

got my point….like that..DOG,CAT etc are different objects.

Like this in JAVA we will deal everything with Objects.

How can we differentiate the Object Orientation Programming and Procedural Programming?

In procedural program ,programming logic follows certain procedures and the instructions are executed one after another.

In OOPs program,unit of program is object,which is nothing but combination of data and code.

In procedural program,data is exposed to the whole program where as in OOP’s program ,it is accesible within the object and which in turn assures the security of the  code.

Is there any other features in OOPs?

Yes, we have some features called Object Oriented Concepts.

  • Data Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism

What is Data Encapsulation?

Encapsulation means, in simple terms, Putting all the data at one place.

Ex 1: The Medicine capsule have the main medicine powder capsuled in a sugar coated capsule box. Like that put all the elements under one palce called ‘Data Encapsulation’. we can learn more about this in next chapters.

Ex 2: Put all your books in one box.

What is Abstraction?

Abstraction is a kind of data hiding. “Showing essential data and hiding non-essential data”.

Ex: If you go to a jewellary shop and ask for pearls, the person will show you only pearls, put all the gold items in the show cases or in their respective places.

What is Inheritance?

Inheritance means, “Acquiring properties from super class”.

Ex: Acquiring land properties of your father to you….

What is Polymorphism?

the word itself says the definition. Poly-menas Many Morphism- forms.

Means an object work in many forms.

Ex: you are only once. But if you are a student, you are student in your college. you are a gym trainer in gym after your college.

 you are brother to your sister, friend to your friend, lover to your GF . 🙂


 Why Java treated as a Object Oriented?

As we discussed previously, in OOP, everything acts as an object.Also JAVA adopt to the OOPs concepts like data encapsulation,abstraction,Inheritance,Polymorphism.

So it’s called “Object Oriented Programming Language”.

How Java Diffent from Other Object Oriented Program Languages?

 Other languages like C++, would have the OOPs concepts. but they are plotform dependent.

Java is Plotform Independent language. Not understanding???

If you write a program in one plotform (windows), you can run the program on different plotform (Linux,Unix). It will run in different plotform.

only thing we need to do is set up the path, classpath settings.

How Java is Plotform Independent?

To answer this question, we need to know little bit about java program compilation.

Java have 2 step process for complie and run the application. that is 1) Compilation 2) Interpretation

Compilation: once you write the program, and compiles the program, it will creat a .class file (Byte Code).

Interpretation: After getting the .class file, the interpreter interprets the code (Checking line-by-line) and creates the executable file.

Once we get the byte code (.class file), we can take that code and run on any plotform, it will run the java program.

That’s why java compile once and run anywhere….so it is plotform independent.

How can we compile and Run a Java program?

To Compile a java program, we require JDK (Java Development ToolKit). Which contains both Java Compiler and JRE (Java run time Environment).

We need to install the JDK to write a java program and compile the program. we need to set up the path. (we will check in next chapter).

Is JDK also Plotform Independent?

 No, JDK is plotform Dependent. Because JRE is plotform dependent. the JRE is different for different plotforms.

Is it necessary to have JDK in every machine to run the Java Application/Program?

 No, It’s not necessary to have install JDK in every machine to run the application. if we have the Byte code of an application and want to run the program, we need to set up the path  and run the program.

JRE will come with Every Operating System. we need set the path to JRE to run the java program.



In Previous chapter, we have discussed about path and classpath…but what is this path and classpath and why we need to set these variables. what is thier role?? we have to learn that…

What is path?

An environment variable that lists the directories the command processor searches for *.exe.

If you do not set the PATH variable, you need to specify the full path to the executable every time you run it, such as:

C:\Program Files\Java\jdk1.6.0\bin\javac

What is classpath?

The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes. (Classes that are part of the JRE, JDK platform, and extensions should be defined through other means, such as the bootstrap class path or the extensions directory.)

 The default value of the class path is “.”, meaning that only the current directory is searched. Specifying either the CLASSPATH variable or the -cp command line switch overrides this value.

To set classpath, the process is: MyComputer –>(right click): properties –>Advanced –> Environmental variables . You can create classpath variable or modify if already.

same thing for path setting as well.

You will get more info regarding path and classpath in below link.



In This Chapter we will learn about the basic java programming. And also compilation and running of a basic java program.

The Basic Structure of a java program is look like this.

class  Helloworld
    public static void main(String[] args)
       System.out.println(”Hai Welcome to learning Java”);

We will learn about step-by-step:

First check the line #1: class Helloworld.

     In java the program start with a block (which is having ‘{’ and ‘}’) called class. Helloworld is the name of the class. you can give any name in this place. This is the name of the class.


public static void main(String[] args)

we will learn about each and every word in next few chapters. This is the main method. this is as like main() in ‘C’ language.

Any java program contains only one main method. The Program Execution follows from the main. So main is the starting point of a java program execution.


System ==> This is Java built in class used for get some system properties like input stream, outputstream, path etc…

out==> this is the output stream.

println() ==> this method will print the message in console.This will print the message with in it.

Ex: Here it will print as “Hai Welcome to learning Java

This is same as printf in ‘C’.

So how to compile this program and run this program.

Do follow the steps:

1. Set the path first (see previous chapter-III)

2. Create a folder name “JavaPrograms”  in C:\  in your Computer (you can create any wher. may be in D:\ or E:\ and the folder name will be any thing.Just for reference i put Java Programs).

3. Save your program in thsi folder with

4. Go to Start–>run–>type ‘cmd’ (it will open the command prompt)

5. Type cd.. and then type as cd javaprograms

then it will look like C:\javaprograms> in command prompt.

6. javac (This is called java compilation)

    it will create a Helloworld.class file i nyour C:\Javaprograms folder.

7. After that

    java Helloworld (run the java program)

8. it will print “Hai Welcome to learning Java“.



In Last chapter we learn about the simple java program. In this chapter we will learn about how the compilation and interpretation happened internally.

Once you write the program and try to compile it using Javac command… the JVM will complile the program.

What is JVM?

JVM: Java Virtual Machine, which contains the JDK as well as JRE. it provides the java environment.

JDK: Java Development toolkit. have compiler.

JRE: Java Runtime environment. this is for run the application or program


To develop and run a java program we require JVM. but for running a java program JVM need not be required (As JRE come with OS). We already discuss about this in previous chapters.

Once the compilation successfully done, a .class file will generated… we can run this .class file using interpreter, after interpretation, the .exe file will be generated.

Why JVM is Plotform Dependent?

Java “the language” is platform-independent. To make it so, there is a platform-specific JRE that knows how to run the platform-independent Java code on a specific platform. So JVM is plotform dependent.



  •  Java is OOPs programming language and plotform independent language.
  • Java compilation and running is a two step process called compilation+interpratation
  • Java is secure becasue of byte code as well as interpretation.
  • To develop a java application we require JVM
  • JVM = JDK+JRE.
  • JVM is plotform dependent.
  • The file should be saved with same name as classname.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: