[email protected] +91 9175287066
This website is always under updation with new contents
Java Tutorials
Importance of Java
History of Java
Java Application
Java Features
OOP’s Principal
Constant in Java
Type Casting
Control Statement
Access specifiers
Super Keyword
Final keyword
Static keyword
this keyword
Dynamic Binding
Object Cloning
Command line argument
Exception handling
Hierarchy of exception
Method overriding
Method overloading
Process based
Thread based
Creating a thread
Thread life cycle
Life Cycle Method
Java Programming Language
Importance of Java

The Java programming language was originally created in 1995 by James Gosling from Sun Microsystems (currently a subsidiary of Oracle Corporation). Java is a general-purpose programming language that’s used in all industries for almost any type of application.

If you master it, your chances of getting employed as a software developer will be higher than if you specialize in some domain-specify c programming languages.

There are around six million professional Java developers in the world and the majority of them are ready to share their knowledge by posting blogs and articles or simply answering technical questions online.

History of Java

JAVA is a distributed technology developed by James Gosling, Patric Naugton, etc., at Sun Micro System has released lot of rules for JAVA and those rules are implemented by JavaSoft Inc, USA (which is the software division of Sun Micro System) in the year 1990.

The original name of JAVA is OAK (which is a tree name). In the year 1995, OAK was revised and developed software called JAVA (which is a coffee seed name) and basically OAK is the symbol of strength.

Father of Java

JAVA released to the market in three categories J2SE (JAVA 2 Standard Edition), J2EE (JAVA 2 Enterprise Edition) and J2ME (JAVA 2 Micro/Mobile Edition).

  1. J2SE is basically used for developing client side applications/programs.
  2. J2EE is used for developing server side applications/programs.
  3. J2ME is used for developing server side applications/programs.

Introduction of Java

Java is a general purpose object orient programming language it was developed at sun microsystem in 1991. Java is programming language and platform. a platform means any hardware and software environment in which a program runs. since java has its own runtime environment and API so it is called platform.

Java runs on more than 3 billion of devices. These are many devices where java is currently used some of them as follows.

  1. Desktop application such as acrobat reader, media player and antivirus
  2. Web application Such as our railway site
  3. Enterprises such as banking application
  4. Mobile
  5. Embedded system
  6. Smart card
  7. Game

Types of Java Application

We can create four types of application in java.

  1. Standalone application
  2. Web application
  3. Enterprises application
  4. Mobile application

Features of Java
  1. Simple
  2. Object oriented
  3. Platform independence
  4. Secured
  5. Robust
  6. Architectural neutral
  7. Portable
  8. Dynamic
  9. Interpreted
  10. High performance
  11. Multithreaded
  12. Distributed
  13. Networked
1 Simple

Java was designed to be easy for the professional programmer to learn and use effectively. Assuming that you have some programming experience, you will not find Java hard to master. If you already understand the basic concepts of object-oriented programming, learning Java will be even easier. Best of all, if you are an experienced C++ programmer, moving to Java will require very little effort. Because Java inherits the C/C++ syntax and many of the object-oriented features of C++.

2 Object oriented

Java is an object-oriented language, which means that it has constructs to represent objects from the real world. Each Java program has at least one class that knows how to do certain things or how to represent some type of object. For example, the simplest class, HelloWorld, knows how to greet the world.

3 Platform independence

A program or technology is said to be platform independent if and only if which can run on all available operating systems.

The languages like C, Cpp are treated as platform dependent languages since these languages are taking various amount of memory spaces on various operating systems The language like JAVA will have a common data types and the common memory spaces on all operating systems and the JAVA software contains the special programs which converts the format of one operating system to another format of other operating system.

4 Secured

Java provide high security compare to other languages. Because there are lots of concept is available in java and these all are the concept and features provide high security.

5 Robust

To gain reliability, Java restricts you in a few key areas, to force you to find your mistakes early in program development. At the same time, Java frees you from having to worry about many of the most common causes of programming errors. Because Java is a strictly typed language, it checks your code at compile time. However, it also checks your code at run time.

6 Architectural neutral

A language or technology is said to be architectural neutral which can run on any available processors in the real world. The languages like C, Cpp are treated as architectural dependent can run on any of the processor. The Java designers made several hard decisions in the Java language and the Java Virtual Machine in an attempt to alter this situation. Their goal was “write once; run anywhere, any time, forever.” To a great extent, this goal was accomplished.

7 Portable

A portable language is one which can run on all operating systems and on all processors The languages like C, Cpp are treated as non-portable languages whereas the language JAVA is called portable language.

8 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. This makes it possible to dynamically link code in a safe and expedient manner.

9 Interpreted

Java is a compiled and interpreted language java first compiled the source code and produce bytecode And these bytecode is interpreted by java interpreter and produce native code that is our output. Java has used interpreter for achieving a platform independence , because bytecode can run on any platform.

10 High performance

There are many reason why java performance is high java can run on any platform , java is both compiled and interpreted language , java bytecode can run on any platform , different kind of application can made by java language etc.

11 Multithreaded

Java was designed to meet the real-world requirement of creating interactive, networked programs. To accomplish this, Java supports multithreaded programming, which allows you to write programs that do many things simultaneously. A program is said to be multi threaded program if and only if there exist n number of programs. For each and every such programs there exist a separate flow flow of controls are executing concurrently. Such flow of control is known as threads. Such type of application is known as multi threading application. Java, however, was designed to perform well on very low-power CPUs. As explained earlier, while it is true that Java was engineered for interpretation, the Java bytecode was carefully designed so that it would be easy to translate directly into native machine code for very high performance by using a just-in-time compiler. Java run-time systems that provide this feature lose none of the benefits of the platform-independent code. “High-performance.

12 Distributed

Java is designed for the distributed environment of the Internet, because it handles TCP/IP protocols. In fact, accessing a resource using a URL is not much different from accessing a file. a service is said to be distributed service which runs on multiple servers and that services can be access by n number of clients across the globe. in ordered to develop distributed application we must require architecture called trusted networked architecture.

13 Networked

In a real world we have two types of networks. They are un-trusted network and trusted networks.

Un-trusted networks: A network is said to be untrusted network in which there exist n number of inter connected non autonomous architecture un trusted network is also known as LAN. Using these network architecture, we can develop centralize application.

Trusted network:A networks is said to be trusted network in which there exist n number of inter connected non autonomous architecture un trusted network is also known as WAN. Using these network architecture , we can develop distributed application.

OOP’S Principal
  1. class
  2. Object.
  3. Data Abstraction.
  4. Data Encapsulation.
  5. Inheritance.
  6. Polymorphism.
  7. Dynamic Binding.
  8. Message Passing.
1 class

Any JAVA program if we want to develop then that should be developed with respective to class only, i.e without class there is no java program. “A class is a way of binding the data and associated methods in a single unit”.Here class is a keyword which is use for developing or creating user define datatypes.

2. Object

Think of an object as a fancy variable; it stores data, but you can “make requests” to that object, asking it to perform operations on itself. In order to store the data for the data members of the class, we must create an object. By using object we can access data member and member function of class.

3. Data Abstraction

Abstraction is a process to show only essential thing and hide the complexity of system this abstraction is used for achieving the concept of user friendly. An essential element of object-oriented programming is abstraction. Humans manage complexity through abstraction. For example, people do not think of a car as a set of tens of thousands of individual parts. They think of it as a well-defined object with its own unique behavior. This abstraction allows people to use a car to drive to the grocery store without being overwhelmed by the complexity of the parts that form the car. They can ignore the details of how the engine, transmission, and braking systems work. Instead they are free to utilize the object as a whole.

4. Data Encapsulation

Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. One way to think about encapsulation is as a protective wrapper that prevents the code and data from being arbitrarily accessed by other code defined outside the wrapper. Data encapsulation is basically used for achieving data or information hiding i.e security.

5. Inheritance

Inheritance is the process by which one object acquires the properties of another object. This is important because it supports the concept of hierarchical classification. Inheritance is the process of taking features from one class to another class. The class which is giving the features is known as Base or parent class. The class which is taking the features is known as derived , chilled or sub class.

6. Polymorphism

Polymorphism is the process of representing one form in many forms. For e.g) ’ +’ operator when apply on integer type of data then plus operator produce addition of two number i.e sum . and when we apply plus operator on string then we get concatenate of two string. We have two types of polymorphism . First compile time polymorphism and second is run time polymorphism.

7. Dynamic Binding

Dynamic binding is a mechanism of binding an appropriate version of a derived class which is inherited from base class with base class object.

8. Message Passing

Exchanging the data between multiple object is in called as message passing i.e when multiple object sending or receiving the data is called as message passing.

Java Virtual Machine (JVM)

It is name given to the storage area and it’s value change during programming execution. The variable is the basic unit of storage in a Java program. A variable is defined by the combination of an identifier In Java, all variables must be declared before they can be used. The basic form of a variable declaration is shown here:

Rules for writing variables
  1. First letter must be an alphabet.
  2. The length of the variable should not exceed more than 32 characters.
  3. No special symbols are allowed except underscore.
  4. No keywords should use as variable names.
type identifier [ = value][, identifier [= value] ...] ;
int a, b, c; // declares three ints, a, b, and c.
int d = 3, e, f = 5; // declares three more ints, initializing
// d and f.

Types of Variables
Java support three types of variable
1) Local Variable
A variable that is declared within a bracket is called local variable
2) Instance Variable
A variable that is declared inside the class but outside the method is called as instance variable. it is not declared as static.
3) Static Variable
A variable that is declared as static is called static variable. It can not be local
Dynamic Initialization of variable

Java allows variable to be initialized dynamically using any expression valid at the time the variable is declared.

int a=10; //Static
int  a=2*2+10-8;
class DynamicIniti
 public static void main(String args[])
    double a=3.0, b=4.0;
    //c is dynamically  initialized
    double c=Math.sqrt(a*a+b*b);
    System.out.println("squar is"+c);
g:\java>javac DynamicIniti
g:\java>java Dynamic
squar  is 5.0

The Scope and lifetime of variable
Whenever any variable declared within a scope or a bracket then it is known only within that bracket.
class Scope
  public static void main(String args[])
  int x;     //known to call within main
  if(x==10)  //start new  scope
    int y=10; //known only to this bracket
   //x and y both are known here
    System.out.println("x and y"+x+" "+y);
 //  y=100;
   System.out.println("x is"+x);
g:\java>javac  Scope.java
g:\java>java  Scope
x and y  10 10
x  is 20 

Constant in Java

Constant is an identifier whose value can not be changed during program execution.

In java if you want to make the identifier as constant so you have to use the final keyword. Final is a keyword which is very important foe three things. And they are variable, method , class.

If we want to make something non changeable during program execution so for that we have to make it as final.

Final data type v1=val1, v2=val2.. ;
final int a=20;
          a=a+30; //invalid

How java differs from C and C++
Here is an example that tries to declared two separate variable with the same name in java this is illegal in c and c++ it would be legal
class ScopeError
 public static void main(String args[])
   int bar=1;
     int bar=2; //compile time eroor
g:\java>javac  ScopeError.java
ScopeError.java:7: Error: variable bar is already defined  in method main(String[])
int  bar=2
1 error

For accessing computer programs go to TECHNOLOGY