Lab Report
Lab Report
History of Java
In the early 90s, extending the power of network computing to the activities of
everyday life was a radical vision. In 1991, a small group of Sun engineers
called the "Green Team" believed that the next wave in computing was the
union of digital consumer devices and computers. Led by James Gosling, the
team worked around the clock and created the programming language that
would revolutionize our world Java.
The Green Team demonstrated their new language with an interactive,
handheld home-entertainment controller that was originally targeted at the
digital cable television industry. Unfortunately, the concept was much too
advanced for the them at the time. But it was just right for the Internet, which
was just starting to take off. In 1995, the team announced that the Netscape
Navigator Internet browser would incorporate Java technology.
Today, Java not only permeates the Internet, but also is the invisible force
behind many of the applications and devices that power our day-to-day lives.
From mobile phones to handheld devices, games and navigation systems to e-
business solutions, Java is everywhere!
2.JRE:- The Java Runtime Environment (JRE) is a set of software tools for
development of Java applications. It combines the Java Virtual Machine (JVM),
platform core classes and supporting libraries.
JRE is part of the Java Development Kit (JDK), but can be downloaded
separately. JRE was originally developed by Sun Microsystems Inc., a wholly-
owned subsidiary of Oracle Corporation.
Features OF Java
There is given many features of java. They are also known as java buzzwords.
2.object-oriented:-
Object-oriented means we organize our software as a combination of
different types of objects that incorporates both data and behaviour.
Object-oriented programming(OOPs) is a methodology that simplify
software development and maintenance by providing some rules.
Basic concepts of OOPs are:
1. Object
2. Class
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
C++ vs JAVA
Both c++ and java are object oriented programming language ,but java is
slightly different from c++ in following ways
1. class Simple{
2. public static void main(String args[]){
3. System.out.println("Hello Java");
4. }
5. }
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
Extend Keyword:- The extends keyword indicates that you are making a
new class that derives from an existing class. The meaning of "extends" is to
increase the functionality.
Syntax:
class Subclass-name extends Superclass-name
{
//methods and fields
}
Example:
class Employee{
float salary=40000;
int bonus=10000;
OUTPUT
Programmer salary is:40000.0
Bonus of Programmer is:10000
Consider a scenario where A, B and C are three classes. The C class inherits A
and B classes. If A and B classes have same method and you call it from child
class object, there will be ambiguity to call method of A or B class.
Since compile time errors are better than runtime errors, java renders compile
time error if you inherit 2 classes. So whether you have same method or
different, there will be compile time error now.
class A{
void msg(){System.out.println("Hello");}
class B{
void msg(){System.out.println("Welcome");}
C obj=new C();
OUTPUT
Compile time error
Write a program in java using single-dimensional array
class Testarray{
public static void main(String args[]){
//printing array
for(int i=0;i<a.length;i++)//length is the property of array
System.out.println(a[i]);
}
Output:
10
20
70
40
50
Write a program for addition of 2 matrices in java
class Testarray5{
public static void main(String args[]){
//creating two matrices
int a[][]={{1,3,4},{3,4,5}};
int b[][]={{1,3,4},{3,4,5}};
Output: 268
6 8 10
Abstract class
Abstract classes may or may not contain abstract methods, i.e., methods
without body ( public void get(); )
But, if a class has at least one abstract method, then the class mustbe
declared abstract.
OUTPUT
running safely..
Write a program in java to take input from user.
import java.util.Scanner;
class GetInputFromUser
{
public static void main(String args[])
{
int a;
float b;
String s;
System.out.println("Enter a string");
s = in.nextLine();
System.out.println("You entered string "+s);
System.out.println("Enter an integer");
a = in.nextInt();
System.out.println("You entered integer "+a);
System.out.println("Enter a float");
b = in.nextFloat();
System.out.println("You entered float "+b);
}
}
OUTPUT
Enter a string
Hello Java
You entered string Hello Java
Enter an integer
123
You entered integer 123
Enter a float
1.23
You entered float 1.23