Q. What is java?

Java is general purpose ,high level ,device independent programming
language. Developed in 1995 by James Gosling of Sun Microsystems specifically
for network-heavy environments such as internet and enterprise intranets), it
is a major part of the information infrastructure being developed all over the
world. Like the C++ language (on which it is based) Java is object oriented:
meaning its programs are built with 'modules' of code which can be employed
in building new programs without rewriting the same code.

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!

Terms related to Java
1.JDK:- The Java Development Kit (JDK) is a software development
environment used for developing Java applications and applets. It includes the
Java Runtime Environment (JRE), an interpreter/loader (java), a compiler
(javac), an archiver (jar), a documentation generator (javadoc) and other tools

JRE:. called "bytecode. but can be downloaded separately. A Java virtual machine processes instructions similar to a physical processor.Stands for "Java Virtual Machine. After you've written a Java program. 5. JVMs allow Java apps to run on almost any computer. This binary format. it gets one stream of bytecodes for each method in the class. When a JVM loads a class file. just-in-time compiling. a just-in-time (JIT) compiler is a program that turns Java bytecode (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor. the source language statements are compiled by the Java compiler into bytecode rather than into code that contains instructions . including Windows OS and Linux. 2." can be processed one instruction at a time or compiled into a .The Java Runtime Environment (JRE) is a set of software tools for development of Java applications. or any other technique that was chosen by the designer of a particular JVM. It can be installed on several different operating systems.CLASS file before execution to improve performance.JAVA file must first be converted into instructions the JVM can understand.In the Java programming language and environment. platform core classes and supporting libraries..needed in Java development. The bytecodes streams are stored in the method area of the JVM. 3. a wholly- owned subsidiary of Oracle Corporation.Bytecodes are the machine language of the Java virtual machine. JRE is part of the Java Development Kit (JDK).JIT compiler:.Bytecode:. However." A JVM is a software-based machine that runs Java programs. 4.JVM:. It combines the Java Virtual Machine (JVM). the Java code from a . They can be executed by intepretation. JRE was originally developed by Sun Microsystems Inc. The bytecodes for a method are executed when that method is invoked during the course of running the program.

removed many confusing and/or rarely-used features e. 1. explicit pointers. The bytecode is platform-independent code that can be sent to any platform and run on that platform. Mac/OS etc. . Polymorphism 5. Java code is compiled by the compiler and converted into bytecode.Platform Independent:.g. Abstraction 6. Object 2.According to Sun.Simple:. Class 3. Inheritance 4. an Intel Pentium microprocessor or an IBM System/390 processor). They are also known as java buzzwords. No need to remove unreferenced objects because there is Automatic Garbage Collection in java..object-oriented:- Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behaviour. Encapsulation 3. Windows. Write Once and Run Anywhere(WORA). operator overloading etc.Java code can be run on multiple platforms e.e. Sun Solaris. This bytecode is a platform- independent code because it can be run on multiple platforms i.that match a particular hardware platform's processor (for example. Object-oriented programming(OOPs) is a methodology that simplify software development and maintenance by providing some rules. Features OF Java There is given many features of java. Basic concepts of OOPs are: 1. Java language is simple because: syntax is based on C++ (so easier for programmers to learn it after C++).g. Linux. 2.

Secured:.C++ is platform dependent whereas JAVA is .Robust:. All these points makes java robust. It shares a common memory area.We may carry the java bytecode to any platform.A thread is like a separate program. Java uses strong memory management. int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory for 64-bit architecture. The main advantage of multi-threading is that it doesn't occupy memory for each thread. Web applications etc. Multi-threaded:.c++ is designed to be compiled for a specific target means there is no portability for c++ program. There is automatic garbage collection in java. We can write Java programs that deal with many tasks at once by defining multiple threads.Java is secured because: o No explicit pointer o Java Programs run inside virtual machine sandbox C++ vs JAVA Both c++ and java are object oriented programming language . Threads are important for multi-media. Robust simply means strong.In C programming. it occupies 4 bytes of memory for both 32 and 64 bit architectures. There is exception handling and type checking mechanism in java. executing concurrently. Architecture-neutral:. But in java.but java is slightly different from c++ in following ways 1. Portable:. There are lack of pointers that avoids security problem.

class Simple{ 2. platform independent.C++ is compiler based programming language whereas JAVA is both comiler and intrertreter based programming language. Simple program in java Let's create the hello java program 1. } save this file as Simple. 3.out.C++ supports operator overloading but java don’t. 4.C++ supports pointer but JAVA don’t.println("Hello Java"). public static void main(String args[]){ 3. } 5. 4.java To execute: java Simple Output: Hello Java . System.java To compile: javac Simple. 2.

0f 4 byte double 0.Data types in Java Data Type Default Value Default size boolean false 1 bit char '\u0000' 2 byte byte 0 1 byte short 0 2 byte int 0 4 byte long 0L 8 byte float 0.0d 8 byte .

When a Class extends another class it inherits all non-private members including fields and methods.Inheritance in JAVA Inheritance is one of the key features of Object Oriented Programming. } class Programmer extends Employee{ int bonus=10000. Inheritance provided mechanism that allowed a class to inherit property of another class.The extends keyword indicates that you are making a new class that derives from an existing class.println("Programmer salary is:"+p. The meaning of "extends" is to increase the functionality. Extend Keyword:. System. Inheritance in Java can be best understood in terms of Parent and Child relationship.out. . public static void main(String args[]){ Programmer p=new Programmer().salary). also known as Super class(Parent) and Sub class(child) in Java language. Syntax: class Subclass-name extends Superclass-name { //methods and fields } Example: class Employee{ float salary=40000.

System.println("Bonus of Programmer is:"+p.out. } } OUTPUT Programmer salary is:40000.0 Bonus of Programmer is:10000 Types of Inheritance in Java .bonus).

The C class inherits A and B classes. there will be compile time error now. obj.println("Hello").Q) Why multiple Inheritance is not supported in java? To reduce the complexity and simplify the language. there will be ambiguity to call method of A or B class.msg().//Now which msg() method would be invoked? } } OUTPUT Compile time error .println("Welcome"). Consider a scenario where A.} } class C extends A.out. Since compile time errors are better than runtime errors.out. class A{ void msg(){System. multiple inheritance is not supported in java. java renders compile time error if you inherit 2 classes. B and C are three classes.} } class B{ void msg(){System.B{//suppose if it were Public Static void main(String args[]){ C obj=new C(). If A and B classes have same method and you call it from child class object. So whether you have same method or different.

a[4]=50. //printing array for(int i=0.Write a program in java using single-dimensional array class Testarray{ public static void main(String args[]){ int a[]=new int[5]. a[3]=40.out.length.println(a[i]).i++)//length is the property of array System.//declaration and instantiation a[0]=10. a[2]=70. } } Output: 10 20 70 40 50 .//initialization a[1]=20.i<a.

//creating another matrix to store the sum of two matrices int c[][]=new int[2][3].out.{3.println().5}}.3. int b[][]={{1.3. //adding and printing addition of 2 matrices for(int i=0.//new line } } } Output: 268 6 8 10 .j++){ c[i][j]=a[i][j]+b[i][j].4.j<3.{3.Write a program for addition of 2 matrices in java class Testarray5{ public static void main(String args[]){ //creating two matrices int a[][]={{1.4}.5}}. System.4.4}.print(c[i][j]+" "). } System.out.i++){ for(int j=0.i<2.

it cannot be instantiated.e.  To use an abstract class. methods without body ( public void get().  If a class is declared abstract.out."). i.Abstract class A class which contains the abstract keyword in its declaration is known as abstract class.  Abstract classes may or may not contain abstract methods. you have to inherit it from another class. . then the class mustbe declared abstract.run(). abstract class Bike{ abstract void run(). provide implementations to the abstract methods in it.println("running safely. } } OUTPUT running safely. )  But... if a class has at least one abstract method.} public static void main(String args[]){ Bike obj = new Honda4(). } class Honda4 extends Bike{ void run(){System. obj.. Write a simple example of abstract class.

nextFloat().in).out. b = in.println("Enter a float"). s = in. System.Scanner.out.23 You entered float 1.println("Enter a string"). float b.out. System.println("You entered integer "+a). System.nextLine(). System.out. String s. } } OUTPUT Enter a string Hello Java You entered string Hello Java Enter an integer 123 You entered integer 123 Enter a float 1.out.util.23 .nextInt().println("Enter an integer"). Scanner in = new Scanner(System.Write a program in java to take input from user.out.println("You entered string "+s). class GetInputFromUser { public static void main(String args[]) { int a. System. a = in.println("You entered float "+b). import java. System.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.