You are on page 1of 21

1.What is java? Explain all its features.

JAVA: Java is the object-oriented programming language,


similar to C++ high-level programming language and
architecture neutral developed by Sun Microsystems in 1995
and later acquired by Oracle Corporation. Java was originally
called OAK. Java is a computing platform for application
development. Object-Oriented meaning the capability to
reuse code. Secondly, it is platform independent, i.e., we
don't have to develop separate applications for different
platforms. It is possible to develop a single application which
can run on multiple platforms like Windows, UNIX, and
Macintosh systems.

FEATURES OF JAVA:

1. Java is Simple:
The Java programming language is easy to learn. Java
code is easy to read and write.
2. Java is an Object-Oriented programming
language:
Unlike C++ which is semi object-oriented, Java is a fully
object-oriented programming language. It has all OOP
features such
as abstraction, encapsulation, inheritance and polymorp
hism.
3. Java is Robust:
With automatic garbage collection and simple memory
management model (no pointers like C/C++), plus
language features like generics, try-with-resources,…
Java guides programmer toward reliable programming
habits for creating highly reliable applications.
4. Java is Secure:
The Java platform is designed with security features
built into the language and runtime system such as
static type-checking at compile time and runtime
checking (security manager), which let you creating
applications that can’t be invaded from outside. You
never hear about viruses attacking Java applications.
5. Java is High Performance:
Java code is compiled into bytecode which is highly
optimized by the Java compiler, so that the Java virtual
machine (JVM) can execute Java applications at full
speed. In addition, compute-intensive code can be re-
written in native code and interfaced with Java platform
via Java Native Interface (JNI) thus improve the
performance.
6. Java is Multithreaded:
The Java platform is designed with multithreading
capabilities built into the language. That means you can
build applications with many concurrent threads of
activity, resulting in highly interactive and responsive
applications.
7. Java is Platform Independence:
Java code is compiled into intermediate format
(bytecode), which can be executed on any systems for
which Java virtual machine is ported. That means you
can write a Java program once and run it on Windows,
Mac, Linux or Solaris without re-compiling. Thus, the
slogan “Write once, run anywhere” of Java.
2.Program to take input of two integer number thru
keyboard and display their sum.

PROGRAM:

import java.io. *;
class sum
{
public static void main (String are [])
{
DataInputStream x=new DataInputStream(System.in);
try
{
int a,b,c;

System.out.println("enter 1st no:");


a=Integer.parseInt(x.readLine());

System.out.println("enter 2nd no:");


b=Integer.parseInt(x.readLine());

c=a+b;
System.out.println("SUM="+c);
}
catch(Exception e)
{
System.out.println("I says error is="+e);
}
}
}

OUTPUT:
3.Program to take input of radius of circle.Calculate &
print the area and circumference of circle.

PROGRAM:

import java.io.*;
class circle
{
public static void main(String ar[])
{
DataInputStream x=new DataInputStream(System.in);

try
{
float r,c,a;

System.out.println("enter radius:");
r=Float.parseFloat(x.readLine());

a=3.14f*r*r;
c=2*3.14f*r;

System.out.println("area of circle="+a);
System.out.println("circumference of circle="+c);
}
catch(Exception e)
{
System.out.println("I says error is="+e);
}
}
}

OUTPUT:
4.Program to take input of age of user,check and print
whether use can cast the vote or not.

PROGRAM:

import java.io.*;
class vote
{
public static void main (String args[])
{
DataInputStream x=new DataInputStream(System.in);
try
{
int age;
System.out.println("Enter age of user:");
age=Integer.parseInt(x.readLine());

if(age>=18)
System.out.println("eligible to vote");

else
System.out.println("Not eligible to vote");
}
catch(Exception e)
{
System.out.println("I says error is="+e);
}
}
}

OUTPUT:
5.Program to take input of integer number,calculate
and print its table.

PROGRAM:

import java.io.*;
class table
{
public static void main(String ar[])
{
DataInputStream x=new DataInputStream(System.in);
try
{
int n,i;
System.out.print("Enter number: ");
n=Integer.parseInt(x.readLine());
for(i=1;i<=10;i++)
System.out.println(n+" * "+i+" = "+n*i);
}
catch(Exception e)
{
System.out.println("I says error is="+e);
}
}
}
OUTPUT:
6.Program to take input of integer number,calculate
and print its factorial.

PROGRAM:

import java.io.*;
class factorial
{
public static void main(String ar[])
{
DataInputStream x=new DataInputStream(System.in);
Try
{
int n,i,f=1;
System.out.print("Enter number: ");
n=Integer.parseInt(x.readLine());
for(i=1;i<=n;i++)
f = f * i;
System.out.println("factorial="+f);
}
catch(Exception e)
{
System.out.println("I says error is="+e);
}
}
OUTPUT:
7.Program to take input of character,check and print
whether it is lowercase or not.

PROGRAM:

import java.io.*;
class check
{
public static void main(String ar[])
{
DataInputStream x=new DataInputStream(System.in);
try
{
char ch;
System.out.println("enter any character:");
ch=(char)System.in.read();

if(ch>='a' && ch<='z')


System.out.println("CHARACTER IS LOWERCASE");

else
System.out.println("CHARACTER IS NOT LOWERCASE");
}
catch(Exception e)
{
System.out.println("I says error is="+e);
}
}
}

OUTPUT:
8.Program to declare a class named student with
attributes as rollno,name,percentage.take input for
them and display them.

PROGRAM:

import java.io.*;

class student
{
int roll;
String n;
float per;

DataInputStream x=new DataInputStream(System.in);

void get()
{
try
{

System.out.print("enter roll no:");


roll=Integer.parseInt(x.readLine());

System.out.print("enter name:");
n=x.readLine();

System.out.print("enter percentage:");
per=Float.parseFloat(x.readLine());

System.out.println("*************************");
}
catch(Exception e)
{
System.out.println("I says error is="+e);
}
}
void disp()
{
try
{

System.out.println("student roll no:"+roll);

System.out.println("student name:"+n);

System.out.println("student percentage:"+per);

catch(Exception e)

{
System.out.println("I says error is="+e);
}
}

public static void main(String ar[])


{
student s=new student();
s.get();
s.disp();
}
}

OUTPUT:
9.Explain constructor in java with suitable program.

Constructor:

1.lt is a special member function of class that executes


when we create the instance(object) of that class. In
other word we can say that there is no need to call a
constructor.

2.lts name is same as class name


.
3.It has no return type.

4.lt may be parameterized or non- parameterized.

5.It is used to initialize class level variable.

PROGRAM:

import java.io.*;
class rectangle
{

int height;
int width;
int area;

void rectangle()
{
height=15;
width=25;
area=height*width;
System.out.println ("Area of Rectangle:"+area);
}
public static void main(String ar[])
{
rectangle r=new rectangle ( ) ;
r.rectangle();
}

OUTPUT:
10.What is Applet?Program to take input of two integer
number thru Applet then calculate and print the sum of
given numbers.

APPLET: An applet is a Java program that runs in a


Web browser. An applet can be a fully functional Java
application because it has the entire Java API at its
disposal.Java applets are downloaded automatically and
run by the web browser. Any web-browser that
supports Java, such as Applet Viewer, can be used to
transport applets to the Internet. An applet can perform
many functions such as graphics, play sound, animation,
arithmetic operations, play games etc.

PROGRAM:
import java.awt.*;
import java.applet.*;
public class abc1 extends Applet
{
public void paint(Graphics g)
{
int a=100;
int b=200;
int sum = a+b;
String s = "The Sum is :" + String.valueOf(sum);
g.drawString( s, 200,100);
}
}

OUTPUT:

You might also like