Java is a pure object-oriented programming language developed by the chief programmer of Sun Microsystems James Gosling and his team-mates for controlling consumer electronic devices. It shares many superficial similarities with C, C++, and Objective C (for instance for loops have the same syntax in all four languages); but it is not based on any of those languages, nor have efforts been made to make it compatible with them. Java has following important features:


1.    Simple – Java is simple to learn. If you already have a bit knowledge of object oriented programming like C++ then it will be some easier to learn Java because Java inherits the

C/C++ syntax and many of the object-oriented features of C++.

2.    Object-Oriented – Java is a pure object-oriented programming language. Java believes – everything is an object. It provides the features of abstraction, encapsulation, inheritance and

polymorphism. Any thing in Java is embedded into a class.

3.    Compiled and Interpreted – Java source programs are translated into bytecode by java compiler and this bytecode is interpreted by the Java interpreter, thus Java is both compiled

and interpreted. When a Java source program is compiled, it lists all the errors occurred in a program, if any. And when this program is error free, it is interpreted by the interpreter

which executes it line by line. Only when the execution reaches with an error is the error reported. Of course it takes some extra time for debugging a program.

4.    Portable – The bytecode, produced by a Java compiler, can be run on any platform that has Java interpreter. Thus java code is portable.

5.    Robust – Java is a strictly typed language. It checks your code at compile time as well as run-time. Thus java programs are less error prone.

6.    Multithreaded – Java supports multithreading programming environment, which allows you to write programs that do many things simultaneously. Even the core of Java is

multithreaded.

7.    Secure – Java does not allow a programmer to manipulate the memory of a system.

8.    Distributed – Java programs can access data across a network, therefore it is distributed.

9.    Architecture Neutral and Portable – Java first converts a source program into bytecode which can be run on a variety of computers having different operating systems.

10.    A High Performance Programming Language – Java programs are   faster as compared to programs written in other interpreter-based programming languages.

11.   Dynamic – Java provides an efficient way for maintaining different versions of an application.

 

 

/* IMPLEMENT SIMPLE JAVA PROGRAM  */




class lohit
{
public static void main(String arr[])
{
System.out.println("Welcome To My Java World:Lohit");
}
}

 

OUTPUT :

 

alt

 

 

/* IMPLEMENT PROGRAM OF JAVA USING CONSTRUCTOR */

 


class nesting
{
int m,n;
nesting(int x,int y)
{
n=x;
n=y;
}     
int largest()
{
if(m>=n)
return(m);
else
return(n);
}
void display()
{
int large=largest();
System.out.println("largest value="+large);
} }
class nestingtest
{
public static void main(String args[])
{
nesting nest=new nesting(50,40);
nest.display();
}
}                  

 

OUTPUT:

 

alt

 

 

 

/* IMPLEMENT PROGRAM OF JAVA USING INHERITANCE */

 


class room
{
int length,breadth;
room(int x,int y)
{
length=x;
breadth=y;
}
int area()
{
return(length*breadth);
} }
class broom extends room
{
int height;
broom(int x,int y,int z)
{
super(x,y);
height=z;
}
int volume()
{
return(length*breadth*height);
} }
class test
{
public static void main(String args[])
{
broom room1=new broom(15,10,20);
int area1=room1.area();
int volume1=room1.volume();
System.out.println("area1="+area1);
System.out.println("volume1="+volume1);
}
}



OUTPUT:

 

alt

 

 


/*  IMPLEMENT JAVA PROGRAM USING MULTITHREADING  */

 

 

class A extends Thread
{
public void run()
{
for (int i=0; i<=2;i++)
{
System.out.println("\t From thread a"+i);
}}}
class B extends Thread
{
public void run(){
for (int j=0;j<=2;j++)
{
System.out.println("\t From thread b"+j);
}}}
class Thread1
{
public static void main(String args[])
{
new A().start();
new B().start();
}}

 

 

OUTPUT:

alt

 


/* IMPLEMENT JAVA PROGRAM USING EXCEPTION HANDLING  */

 


class Error4
{
public static void main(String args[])
{
int a[]={5,10};
int b=5;
try
{
int x=a[2]/b;
}
catch(ArithmeticException e)
{
System.out.println("Division by zero");
}
catch(Exception e)
{
System.out.println("ArrayIndexOutofBound");
}
finally
{
System.out.println("Finally executed");
}}}

 


OUTPUT:

 

alt

 

 

 

/* IMPLEMENT JAVA PROGRAM USING INTERFACES */

 


interface area
{
final static float pi=3.14f;
float compute(float x, float y);
}
class rectangle implements area
{
public float compute(float x, float y)
{
return(x*y);
}
}
class circle implements area
{
public float compute(float x, float y)
{
return(pi*x*x);
}
}
class interfacetest
{
public static void main(String args[])
{
rectangle rect=new rectangle();
circle cir=new circle();
area are;
are=rect;
System.out.println("Area of  rect="+are.compute(10,20));
are=cir;
System.out.println("Area of cir="+are.compute(10,0));
}
}

 

 

OUTPUT:

 

alt

 

 

 

/* IMPLEMENT JAVA PROGRAM USING APPLETS */

 



import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/**/
public class tools extends Applet implements ActionListener
{
String msg=" ";
Button b1,b2,b3;
TextField t1,t2,t3;
Label l1,l2,l3;
public void init()
{
b1=new Button("sum");
b2=new Button("multiply");
b3=new Button("divison");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
l1=new Label("enter ist no");
l2=new Label("enter 2nd no");
l3=new Label("result");

add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(b2);
add(b3);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
t1.addActionListener(this);
t2.addActionListener(this);
t3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String msg =ae.getActionCommand();
int x,y,z;
x=Integer.parseInt(t1.getText());
y=Integer.parseInt(t2.getText());
if(msg.equals("sum"))
{
z=x+y;
}
else if (msg.equals("multiply"))
{
z=x*y;
}
else
{
z=x/y;
}
t3.setText(" "+z);
repaint();
}
public void paint (Graphics g)
{
g.drawString(msg,20,20);
}
}

 

 

OUTPUT:

 

alt

 

 

 

 

 


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet

Which of the following Faculty Members will you like always?

No answer selected. Please try again.
Please select either existing option or enter your own, however not both.
Please select minimum 0 answer(s) and maximum 4 answer(s).
/polls/education/6614-which-of-the-following-faculty-members-will-you-like-always.json?task=poll.vote
6614
radio
[{"id":"23006","title":" One who uses film projector along with the proper use of the board","votes":"30","type":"x","order":"1","pct":66.67,"resources":[]},{"id":"23007","title":"One who uses board occasionally","votes":"6","type":"x","order":"2","pct":13.33,"resources":[]},{"id":"23008","title":"One who uses motion picture as a last resort","votes":"1","type":"x","order":"3","pct":2.22,"resources":[]},{"id":"23009","title":"One who uses chart and maps","votes":"8","type":"x","order":"4","pct":17.78,"resources":[]}] ["#ff5b00","#4ac0f2","#b80028","#eef66c","#60bb22","#b96a9a","#62c2cc"] ["rgba(255,91,0,0.7)","rgba(74,192,242,0.7)","rgba(184,0,40,0.7)","rgba(238,246,108,0.7)","rgba(96,187,34,0.7)","rgba(185,106,154,0.7)","rgba(98,194,204,0.7)"] 350
bottom 200
No married couple wants to end up getting divorced. It is not like they have planned for it. They try to put up with their partners for as long as they
Due to our modern lifestyle, we feel that digestion related disorders are a common problem. Thus, we neither give importance to them nor seek any help
The bond of marriage brings the two people together. Initially, everything may seem okay and both of them slowly start discovering each other in the journey.
Why to choose Java? In the computer market, being able to use Java is a crucial knowledge. Java is a development terminology used to build compelling
DATABASE CONNECTIVITY This articles explains the need of database connectivity, the way it is achieved through Java using the JDBC(java database connectivity)
  Write your first simple java program.   First of all we need is a placewhere we can write your Java code. All Java programs are written using
Array of objects in Java Arrays are defined as block of continous memory locations which are arranged in one after another. Elements of the Array can
Synchronized block is alternative mechanism for "synchronized" methods.If we inherihate the non synchronized blocks either from base class or interface