Assignment Final
Assignment Final
. History of java
Ans. James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in
June 1991. Java was originally designed for interactive television, but it was too advanced for the
digital cable television industry at the time. The language was initially called Oak after an oak tree
that stood outside Gosling's office. Later the project went by the name Green and was finally
renamed Java, from Java coffee. Java name was chosen by James Gosling while having a cup of
coffee nearby his office. PSun Microsystems released the first public implementation as Java 1.0 in
1996. was created on the principles like Robust, Portable, Platform Independent, High Performance,
Multithread, etc. and was called one of the Ten Best Products of 1995 by the TIME MAGAZINE.
Currently, Java is used in internet programming, mobile devices, games, e-business solutions, etc.
It promised Write Once, Run Anywhere (WORA), providing no-cost run-times on popular platforms.
Now Java is being used in Windows applications, Web applications, enterprise applications, mobile
applications, cards, etc. Each new version adds new features in Java.
C JAVA
C is a middle-level language Java is a high-level language
2
C is a structural and procedure- Java is an object-oriented
oriented programming language. programming language
It follows the top-down approach to It follows the bottom-up approach
design the application. to design the application.
It is a compiled language. It is an interpreted language.
It is platform dependent. It is platform-independent.
The file is saved with extension .c File is saved with extension .java
It translates the code into machine It translates the code into a
language so that the machine can bytecode that is executed by the
understand the code. JVM.
1
It supports the concept of the It does not support the concepts of
pointer.
It does not support the concepts of
3
pointer. pointers because of security
. Class
. Object
. Inheritance
. Polymorphism
. Abstraction
. Encapsulation
. Class
A class is a user-defined blueprint or prototype from which objects are created. It represents the
set of properties or methods that are common to all objects of one type.
. Objects
An object is a basic unit of Object-Oriented Programming that represents real-life entities. A typical
Java program creates many objects, which as you know, interact by invoking methods.
. Abstraction
Data Abstraction is the property by virtue of which only the essential details are displayed to the
user. The trivial or non-essential units are not displayed to the user.
. Encapsulation
It is defined as the wrapping up of data under a single unit. It is the mechanism that binds together
the code and the data it manipulates
. Inheritance
Inheritance is an important pillar of OOP. It is the mechanism in Java by which one class is allowed
to inherit the features of another class.
. Polymorphism
. Oops principal
Same as question 3 but only starting from there are six concepts of oops
. Encapsulation
It is defined as the wrapping up of data under a single unit. It is the mechanism that binds together
the code and the data it manipulates
Program:
class Area {
int length;
int breadth;
Area(int length, int breadth) {
this.length = length;
this.breadth = breadth;
}
public void getArea() {
int area = length * breadth;
System.out.println("Area: " + area);
}
}
class Main {
public static void main(String[] args) {
Area rectangle = new Area(5, 6);
rectangle.getArea();
}
}
Output:
Area: 30
. Inheritance
Inheritance is an important pillar of OOP. It is the mechanism in Java by which one class is allowed
to inherit the features of another class.
Program:
class Employee{
float salary=40000;
}
class Programmer extends Employee{
int bonus=10000;
public static void main(String args[]){
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
}
Output:
. Polymorphism
Program:
class Bike{
void run(){System.out.println("running");}
}
class Splendor extends Bike{
void run()
{
System.out.println("running safely with 60km");
}
public static void main(String args[]){
Bike b = new Splendor();//upcasting
b.run();
}
}
Output:
. Developer names
Java was developed by sun microsystem by James Gosling, Patrick Naughton, Chris Warth, Ed
Frank, and Mike Sheridan.