Sei sulla pagina 1di 11

Program 5

Q. Explain the Introduction, History and Features of Java. Differentiate between Java and javascript. Also give the steps to execute a program in Java. Ans.

Javas History
1. 2. 3. 4. 5. 6. 7. 8. Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Oak - In1991 Java - In 1995 Hot Java First Java Enabled Browser Netscape Navigator In 1995 to incorporate Java Technology Based on C/C++ Designed for easy Web/Internet applications

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!

Features of Java
Platform IndependentThe concept of Write-once-run-anywhere (known as the Platform independent) is one of the important key feature of java language that makes java as the most powerful language. Not even a single language is idle to this feature but java is more closer to this feature. The programs written on one platform can run

on any platform provided the platform must have the JVM.

Simple There are various features that makes the java as a simple language. Programs are easy to write and debug because java does not use the pointers explicitly. It is much harder to write the java programs that can crash the system but we can not say about the other programming languages. Java provides the bug free system due to the strong memory management. It also has the automatic memory allocation and deallocation system. Object Oriented To be an Object Oriented language, any language must follow at least the four characteristics. Inheritance : It is the process of creating the new classes and using the behavior of the existing classes by extending them just to the additional features as needed. Encapsulation: : It is the mechanism of combining the information and providing the abstraction. Polymorphism: : As the name suggest one name multiple form, Polymorphism is the way of providing the different functionality by the name based on the signatures of the methods. Dynamic binding : Sometimes we don't have the knowledge of objects about their specific types while writing our code. It is the way of providing the maximum functions having the same reuse the existing code and adding

functionality to a program about the specific type at runtime. Robust Java has the strong memory allocation and automatic garbage collection mechanism.

It provides the powerful exception handling and type checking mechanism as compare to other programming languages. Compiler checks the program whether there any error and interpreter checks any run time error and makes the system secure from crash. All of the above features makes the java language robust. Distributed The widely used protocols like HTTP and FTP are developed in java. Internet programmers can call functions on these protocols and can get access the files from any remote machine on the internet rather than writing codes on their local system. Portable The feature Write-once-run-anywhere makes the java language portable provided that the system must have interpreter for the JVM. Java also have the standard data size irrespective of operating system or the processor. These features makes the java as a portable language. Dynamic While executing the java program the user can get the required files dynamically from a local drive or from a computer thousands of miles away from the user just by connecting with the Internet. Secure Java does not use memory pointers explicitly. All the programs in java are run under an area known as the sand box. Security manager determines the accessibility options of a class like reading and writing a file to the local disk. Java uses the public key encryption system to allow the java applications to transmit over the internet in the secure encrypted form. The bytecode Verifier checks the classes after loading.

Performance Java uses native code usage, and lightweight process called threads. In the beginning interpretation of bytecode resulted the performance slow but the advance version of JVM uses the adaptive and just in time compilation technique that improves the performance. Multithreaded As we all know several features of Java like Secure, Robust, Portable, dynamic etc; you will be more delighted to know another feature of Java which is Multithreaded. Java is also a Multithreaded programming language. Multithreading means a single program having different threads executing independently at the same time. Multiple threads execute instructions according to the program code in a process or a program. Multithreading works the similar way as multiple processes run on one computer.

Difference between Java and Javascript


Java 1. Java is object oriented language 2. It is a compiled language 3. Java is strong type language i.e. variables, data types must be declared 4. Java was created by sun Microsystems 5. Java can stand on its own (i.e standalone language) 6. It follows static type checking 7. Java uses byte code 8. Java is much larger and complicated language that creates standalone applications 9. Difficult for common man to understand 10. Creation of web pages takes longer time Java script 1. Java script is object based scripting language 2. It is not compiled, it is interpreted 3. Java Script is loose type language i.e. variables, data types may not be declared 4. It was created by Netscape 5. Java script must be placed inside the HTML documents 6. It follows dynamic type checking It works directly therefore, no use of changing of byte code 8. It is a text that is fed or encrypted into a browser 9. It is easier to understand 10. It enables faster creation of web pages

Steps to execute a program in Java


To execute a program in java, just follow the following steps:

Create a source file A source file contains code, written in the Java programming language, that you and other programmers can understand. You can use any text editor to create and edit source files.

Compile the source file into a .class file The Java programming language compiler (javac) takes your source file and translates its text into instructions that the Java virtual machine can understand. The instructions contained within this .class file are known as bytecodes. Run the program The Java application launcher tool (java) uses the Java virtual machine to run your application. Example: open a texteditor, type in the code which defines a class (HelloWorldApp) and then save it in a file (HelloWorldApp.java) file and class name are case sensitive and must be matched exactly (except the .java part) compile HelloWorldApp.java by using the following command: javac HelloWorldApp.java It generates a file named HelloWorldApp.class Example Code: HelloWorldApp.java public class HelloWorldApp { } public static void main(String[] args) { } // Display "Hello World!" System.out.println("Hello World!");

Program 6

Q. WAP to print Hello World in java. Ans. class hello { public static void main(String args[]) { System.out.println("Hello World"); } }

Program 7
Q. WAP to print the pattern. 55555 4444 333 22 1 Ans. public class pattern { public static void main(String args[]) { for(int i=5;i>=1;i--) { for (int j=i;j>=1;j--) { System.out.print(i); } System.out.println(" "); } } }

Program 8

Q. WAP to print the pattern.

********* ******** ******* ****** ***** **** *** ** *


Ans. public class pattern2{ public static void main(String args[]) { for(int i=0;i<9;i++) { for (int j=0;j<=i;j++) { System.out.print(" "); } for(int k=9;k>i;k--) { System.out.print("* "); } System.out.println(" "); } } }

Potrebbero piacerti anche