Static Variable In Java

Java variable types

The Java programming language defines the following kinds of variables:

  1. Instance Variables
  2. Static Variables
  3. Local Variables

Instance Variables (Non-Static Fields)

  1. Non-Static Variables are called as Instance Variable.
  2. Instance variables are variables within a class but outside any method.
  3. Whenever we create an object of class then we can have certain attributes of the class that are unique for each object , that attribute variable is called as “Instance Variable“.
  4. Individual states of objects is stored in  “non-static fields”. (instance variable).
  5. Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words).

Sample Example

Class Person
String name;
int    age;
String gender;

Person P1,P2,P3;

In the above example we have created class “Person”. We can have different Attributes of Class Person such as name,age,gender . These attributes are unique for different objects. Such as for object P1’s name can be different from P2’s name. Such variables that are unique for individual object is called Instance Variable.

Class Variables (Static Fields)

  1. A class variable is any field declared with the static modifier.
  2. Exactly one copy of static or class variable is created , regardless of how many times the class has been instantiated.
  3. Suppose we have created 5 objects then all of the objects can share same variable.

Example :

Class Person
String name;
int    age;
String gender;

static String city = "Pune";

Person P1,P2,P3;

Static Variable In Java

Local Variables

  1. In order to store Temporary state we use local variables.
  2. Generally local variables are declared in the methods,constructors,blocks.
  3. “count” is local variable in following code snippet.
  4. Destroyed when method gets executed completely.

Example :

int counting(int n1,int n2)
  int count;
  count = n1 + n2;
Variable in Java

Java variable naming rules

Variables in Java Programming

[one_half last=”no”]Variable in Java[/one_half]Variables in Java Programming is something that can be changed, such as a characteristic or value. If we consider programming concept then we can say that variable is something which can store a value. It is container for storing a value.Variable name may be given by programmer.

Some Rules of Variable Naming Convention :

  1. Variable names are case-sensitive.
  2. A variable’s name can be any legal identifier.
  3. It can contain Unicode letter,Digits and Two Special Characters such as Underscore and dollar Sign.
  4. Length of Variable name can be any number.
  5. Its necessary to use Alphabet at the start (however we can use underscore , but do not use it )
  6. Some auto generated variables may contain ‘$‘ sign. But try to avoid using Dollar Sign.
  7. White space is not permitted.
  8. Special Characters are not allowed.
  9. Digit at start is not allowed.
  10. Subsequent characters may be letters, digits, dollar signs, or underscore characters.
  11. Variable name must not be a keyword or reserved word.


Some Standard Conventions Used :

1. Never Use Dollar Or Underscore as First Letter

  • Dollar Sign and Underscore as First Character in Variable name is allowed but still its not good programming Style to use it as First Character.
  • Generally we use Underscore in “Constant Value” variable.
static final int TOTAL_NUM = 10;

static final int MAX_COUNT = 20;

*Final is nothing but constant value in Java (In c we use const)

2. Capitalization of First Character of Second Word

  • If variable name contain two words then write first letter of second word in Capital Case.
  • If variable name contain single word then write that word in small case.


Example : Multiple Words in Variable Name




Example : Single Word in Variable Name




Eclipse IDE

Java development IDE

Most Popular Java Editors :

While surfing web i come across this site . This site provides detailed explanation of all the popular editors for creating java applications. [Here]
List of Some Useful Java Editors are :
Most Popular Java IDE's that Every Programmer should know

Eclipse 3.0FreeOpen Source (CPL)
Netbeans 3.xFreeSun Micro System
JBuilder X (Borland)$499Borland
IntelliJ IDEA$499IntelliJ IDEA

5 Most Popular Free Java Editors for Beginners !!

1. Eclipse IDE

Eclipse IDE

2. Netbeans

3. Notepad++

Notepad plus plus IDE

4. Editplus

5. Jcreator

Java download

Steps to Download Latest Version of Java :

  1. Navigate to Link : Download JDK
  2. Click on the Download Java [Java Platform (JDK) 7u17]

Downloading Java

  1. After Clicking on the Java Logo it will redirect you to the actual download page.
  2. On the download page you have to click on radio button to accept terms and conditions of oracle.

Downloading Java - 2

  1. Select appropriate version as per requirement.
  2. Click on download link after that downloading will be started . Setup is nearly about 75-80 mb.

[box]I am running java on Window 7 (64-bit) therefor i will select suitable version for me – [ jdk-7u17-windows-x64.exe ][/box]
In the next tutorial we are going to see how to install JDK.

Java characteristics & features

11 Features of Java Programming Language

Simple :

  • Java is Easy to write and more readable and eye catching.
  • Java has a concise, cohesive set of features that makes it easy to learn and use.
  • Most of the concepts are drew from C++ thus making Java learning simpler.

Secure :

  • Java program cannot harm other system thus making it secure.
  • Java provides a secure means of creating Internet applications.
  • Java provides secure way to access web applications.

Portable :

  • Java programs can execute in any environment for which there is a Java run-time system.(JVM)
  • Java programs can be run on any platform (Linux,Window,Mac)
  • Java programs can be transferred over world wide web (e.g applets)

Object-oriented :

  • Java programming is object-oriented programming language.
  • Like C++ java provides most of the object oriented features.
  • Java is pure OOP. Language. (while C++ is semi object oriented)

Robust :

  • Java encourages error-free programming by being strictly typed and performing run-time checks.

Multithreaded :

  • Java provides integrated support for multithreaded programming.

Architecture-neutral :

  • Java is not tied to a specific machine or operating system architecture.
  • Machine Independent i.e Java is independent of hardware .

Interpreted :

  • Java supports cross-platform code through the use of Java bytecode.
  • Bytecode can be interpreted on any platform by JVM.

High performance :

  • Bytecodes are highly optimized.
  • JVM can executed them much faster .

Distributed :

  • Java was designed with the distributed environment.
  • Java can be transmit,run over internet.

Dynamic :

  • Java programs carry with them substantial amounts of run-time type information that is used to verify and resolve accesses to objects at run time.

Java is portable – reason

How java is Considered as Platform Independent and Portable ?

In this tutorial we have covered step by step discussion about –

  1. Which features makes java Platform Independent ?
  2. Why Java is Platform Independent ?
  3. Why Java is considered as Secure and Portable Language ?

Why Java is Portable ?

A. Java is considered as Portable because –

Java is Considered as Platform independent because of many different reasons which are listed below –

  1. Output of a Java compiler is Non Executable Code i.e Bytecode.
  2. Bytecode is a highly optimized set of instructions
  3. Bytecode is executed by Java run-time system, which is called the Java Virtual Machine (JVM).


Important Note :

As the output of Java Compiler is Non Executable Code we can consider it as Secure (it cannot be used for automated execution of malicious programs).


  1. JVM is an interpreter.
  2. JVM accepts Bytecode as input and execute it.
  3. Translating a Java program into bytecode makes it much easier to run a program in a wide variety of environments because only the JVM needs to be implemented for each platform.
  4. For a given System we have Run-time package , once JVM is installed for particular system then any java program can run on it.
  5. However Internal details of  JVM will differ from platform to platform but still all understand the Same Java Bytecode.

How Java Program is Platform Independent ?

How Java Program is Platform Independent ?

B. Why Java Code is Safe ?

  1. Java program is executed by the JVM.
  2. The JVM prevent java code from generating side effects outside of the system.
  3. Safety is also enhanced by certain restrictions that exist in the Java language.

C. Interpreter are slower than Compiler

Java Code is Executed by JVM (interpreter).Other programming language uses compiler which can create executable code much faster then why we are using Interpreter.

  1. When a program is interpreted, it generally runs slower than the same program would run if compiled to executable code.
  2. In Java Compiler will generate ByteCode which is highly optimized.
  3. Thus running highly optimized code using interpreter makes execution of java program faster.

Reference : Image 1 | Image2

Congratulations !! You have completed First Chapter.

We have learned –

Next Chapter is About Setting up Java Environment and IDE. Carry on !!

Java contribution to www

Java’s Contribution to the Internet (World Wide Web):

  1. Great feature of the java is that java is platform independent.
  2. It can word on any network,any operating system thus making programs more flexible.
  3. In addition to simplifying web programming in general, Java innovated a new type of networked program called the applet that changed the way the online world thought about content.
  4. Portability and Security of java makes World wide web to spread across globe.

A. Java Applets :

  1. An applet is a special kind of Java program that is designed to be transmitted over the Internet and automatically executed by a Java-compatible web browser.
  2. Applet can be downloaded on demand.
  3. Applet programs can be run on ant java compatible browser.
  4. Applets are intended to be small programs.
  5. They are typically used to display data provided by the server, handle user input, or provide simple functions, such as a loan calculator, that execute locally, rather than on the server.
  6. In essence, the applet allows some functionality to be moved from the server to the client.

B. Security :

  1. Applets can be downloaded to user PC .
  2. They are executed independently without accessing other parts of user’s PC.
  3. The ability of Java provides security and thus Java prove itself more secure.

C. Portability :

  1. Java Programming is Portable.
  2. Java Program is Operating System Independent.
  3. Java Program is converted into byte code and byte code is executed by JVM. [ See how Java Code is Portable ? ]
  4. Java Applets are thus portable and can be downloaded from any place in globe and can be executed on java compatible browser thus making java programs portable.

In the next chapter we are going to see How Java Programming is Platform Independent ? Which Aspects of Java make it to behave independently regardless of hardware use ?

Java vs C#

How Java Related to C# ?

  1. After the creation of Java, Microsoft developed the C# language and C# is closely related to Java.
  2. Many of C#’s features directly parallel Java. Both Java and C# share the same general C++-style syntax, support distributed programming, and utilize the same object model.
  3. Though there are some differences between Java and C#, but the overall feel of these languages is very similar.
  4. If you already know C#, then learning Java will be easy and vice versa
  5. Java and C# are optimized for two different types of computing environments.
  6. C# and Java Both Languages are drew from C++.
  7. Both Languages are capable of creating cross platform portable program code.

[box]Important : How do Java & C# create cross-platform portable Code ?[/box]

Consider Scenario of Java Programming Language

  1. Java is created by Sun Micro System.
  2. Java Compiler produces Intermediate code called Byte Code.
  3. Byte Code i.e intermediate code is executed by the Run Time Environment.
  4. In Java Run Time Environment is called as “JVM” [ Java Virtual Machine]
  5. If we have JVM already installed on any platform then JVM can produce machine dependent Code based on the intermediate code.

Java Vs C Sharp

Here are some differences between Java and C Sharp.

DevelopmentSun MicrosystemMicrosoft
Development Year19952000
Data TypesLess Primitive DTMore Primitive DT
Struct ConceptNot SupportedSupported
Switch CaseString in Switch Not AllowedString in Switch Allowed

Re-commanded Reading :

External ArticleLink
Difference between Java and C#CodeProject
Similarities Between C# and JavaMSDN

Our next Chapter is based on contribution of Java Programming to Internet Evolution. How java contribute to Internet ?

What is java

What is Java ?

Java is widely used programming language which has wide verity of applications such as desktop applications, Mobile Applications, Enterprise applications etc.
Java is a –

  1. Class Based and Object Oriended Programming Language
  2. Computing platform
  3. Fast, Secure, and Reliable.
  4. Free
  5. General Purpose
  6. Concurrent


Five primary goals in the creation of the Java language :

  1. It should be “simple, object-oriented and familiar”.
  2. It should be “robust and secure”.
  3. It should be “architecture-neutral and portable”.
  4. It should execute with “high performance”.
  5. It should be “interpreted, threaded, and dynamic”.

Goals in Creating Java

Some of the Versions of Java :

Java VersionRelease DateYear
JDK 1.0January 21 1996
JDK 1.1February 19 1997
J2SE 1.2December 8 1998
J2SE 1.3May 8 2000
J2SE 1.4February 6 2002
J2SE 5.0September 30 2004
Java SE 6December 11 2006
Java SE 7July 28 2011

Java history

About Java and Hostory :

  1. Java was designed by Sun Microsystems in the early 1990s.
  2. Basic aim of java was to solve the problem of connecting many household machines together.
  3. Project was unsuccessful because no one wanted to use it.
  4. Earlier Name of Java : OAK
  5. Creator of Java :  James Gosling  (the father of Java)
  6. As there was another language called Oak , they decided to rename OAK. New name was given to OAK , OAK was renamed Java in 1994
  7. Java was publicly released on : May 27, 1995
  8. Java was targeted at :  Internet development
  9. Applets Had early support from companies : Netscape Communications

James Gosling - Father and Creator of Java Programming Language

Language was created with 5 main goals:

  1. It should be object oriented
  2. A single representation of a program could be executed on multiple operating systems
  3. It should fully support network programming
  4. It should execute code from remote sources securely
  5. It should be easy to use


Designed BySun Microsystems
Designed Inearly 1990s
Basic AimFor Communicating Between Household things
Earlier Name of JavaOAK
Creator of JavaJames Gosling
First Public Release27 May 1995
Java was targeted atInternet Development

In the next chapter we are going to see difference between two major and most widely spread languages – C# and Java.