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

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

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

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

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

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 .

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

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

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

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

//new line } } } Output: 268 6 8 10 .4}. //adding and printing addition of 2 matrices for(int i=0.print(c[i][j]+" ").3. int b[][]={{1.4}.i++){ for(int j=0.4. System.out.{3.3.5}}.println().4. } System.5}}. //creating another matrix to store the sum of two matrices int c[][]=new int[2][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.{3.j<3.i<2.out.j++){ c[i][j]=a[i][j]+b[i][j].

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

System. a = in.out. } } 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 .println("You entered float "+b).out.nextLine().nextInt(). System.out. System. System.util. class GetInputFromUser { public static void main(String args[]) { int a.println("Enter a float"). s = in. b = in.Scanner.println("You entered integer "+a).println("Enter an integer").in). Scanner in = new Scanner(System.println("You entered string "+s). System.out. System.println("Enter a string").out. String s. import java.out.nextFloat().Write a program in java to take input from user. float b.

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.