1 / 105

JAVA

JAVA. Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform.

ashley
Download Presentation

JAVA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVA • Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. • The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities than either C or C++. • JAVA is Platform Independent Pure object oriented Programming Language. It is also called Write Once Run Anywhere(WORA). • Java is CASE SENSITIVE!! • Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Sunil Kumar Sahu, Lecturer RCET

  2. Definition of Java (As per Sun MicroSystem) A simple, Object Oriented, distributed, interpreted, robust, secure architecture, neutral, protable, high performance, mutithread, and dynamic language. • In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines. Sunil Kumar Sahu, Lecturer RCET

  3. History • James Gosling began developing Java beginning in 1991 • It was first called “Project Green” and ‘Oak” • First developed for remote cable TV boxes • Sun Microsystems released to a select group on the Website wicked.neato.org as Java 1.0 in 1995 • James Naughton creates “HotJava” in 1995. it’s a web,browser that lets you run “Applets”. The entire browser iswritteninJava. • Java currently released version JDK7 or Java SE 7.0 Sunil Kumar Sahu, Lecturer RCET

  4. History... • 1. JDK 1.0 (January 23, 1996) • 2. JDK 1.1 (February 19, 1997) • 3. J2SE 1.2 (December 8, 1998) • 4. J2SE 1.3 (May 8, 2000) • 5. J2SE 1.4 (February 6, 2002) • 6. J2SE 5.0 (September 30, 2004) • 7. Java SE 6 (December 11, 2006) • 8. Java SE 7 (July 28, 2011) Sunil Kumar Sahu, Lecturer RCET

  5. Version of java Java Language vs Java Platform - Current version of the language is JKD7 - Core language plus additional APIs is called the Java 2 platform - Three versions of the Java 2 Platform, targeted at different uses Java 2 Micro Edition (J2ME) - Very small Java environment for smart cards, pages, phones, and set-top boxes - Subset of the standard Java libraries aimed at limited size and processing power Java 2 Standard Edition (J2SE) - The basic platform, which this course will cover Java 2 Enterprise Edition (J2EE) - For business applications, web services, mission-critical systems - Transaction processing, databases, distribution, replication Sunil Kumar Sahu, Lecturer RCET

  6. Java Basic Tools Tool Name Brief Description javac The compiler for the Java programming language. Java The launcher for Java applications. javadoc API documentation generator. Appletviewer Run and debug applets without a web browser. jar Create and manage Java Archive (JAR) files. Jdb The Java Debugger. javah C header and stub generator. Used to write native methods. javap Class file disassembler extcheck Utility to detect Jar conflicts. Sunil Kumar Sahu, Lecturer RCET

  7. JAVA vs JAVA SCRIPT Java • A complete programming language developed by Sun • Can be used to develop either web based or stand-alone software • Many pre-created code libraries available • For more complex and powerful programs Java Script • A small language that’s mostly used for web-based applications (run through a web browser like Internet Explorer, Firefox, Safari, Chrome) • Good for programming simple special effects for your web page e.g., roll-overs Sunil Kumar Sahu, Lecturer RCET

  8. How it works Sunil Kumar Sahu, Lecturer RCET

  9. Characteristics of Java Java is partially modeled on C++, but greatly simplified and improved. Some people refer to Java as "C++--" because it is like C++ but with more functionality and fewer negative aspects. • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Sunil Kumar Sahu, Lecturer RCET

  10. Characteristics of Java Java is inherently object-oriented. Although many object-oriented languages began strictly as procedural languages, Java was designed from the start to be object-oriented. Object-oriented programming (OOP) is a popular programming approach that is replacing traditional procedural programming techniques. One of the central issues in software development is how to reuse code. Object-oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism. • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Sunil Kumar Sahu, Lecturer RCET

  11. Characteristics of Java Distributed computinginvolves several computers working together on a network. Java is designed to make distributed computing(e.g. Web Services) easy. Since networking capability is inherently integrated into Java, writing network programs is like sending and receiving data to and from a file. • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Sunil Kumar Sahu, Lecturer RCET

  12. Characteristics of Java You need an interpreter to run Java programs. The programs are compiled into the Java Virtual Machine code called bytecode. The bytecode is machine-independent and can run on any machine that has a Java interpreter, which is part of the Java Virtual Machine (JVM). • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Sunil Kumar Sahu, Lecturer RCET

  13. Characteristics of Java Java compilers can detect many problems that would first show up at execution time in other languages. Java has eliminated certain types of error-prone programming constructs found in other languages. Java has a runtime exception-handling feature to provide programming support for robustness. • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Sunil Kumar Sahu, Lecturer RCET

  14. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Java implements several security mechanisms to protect your system against harm caused by stray programs. Sunil Kumar Sahu, Lecturer RCET

  15. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Write once, run anywhere With a Java Virtual Machine (JVM), you can write one program that will run on any platform. Sunil Kumar Sahu, Lecturer RCET

  16. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled. Sunil Kumar Sahu, Lecturer RCET

  17. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Because Java is architecture neutral, Java programs are portable (moveable). They can be run on any platform without being recompiled. Sunil Kumar Sahu, Lecturer RCET

  18. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Multithread programming is smoothly integrated in Java, whereas in other languages you have to call procedures specific to the operating system to enable multithreading. Sunil Kumar Sahu, Lecturer RCET

  19. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Java was designed to adapt to an evolving environment. New code can be loaded on the fly without recompilation. There is no need for developers to create, and for users to install, major new software versions. New features can be incorporated transparently as needed. Sunil Kumar Sahu, Lecturer RCET

  20. Creating ,Compiling and Executing Programs • On command line • javac file.java • Executing Applications • java classname Sunil Kumar Sahu, Lecturer RCET

  21. Simple Java Program public class hello { public static void main (String args[]) { System.out.println(“This is first java program“); } } • Save as hello.java Sunil Kumar Sahu, Lecturer RCET

  22. How to compile and run java Program • Save java program with .java(dot java) extension • Compile java program- - javac hello.java • Run java program- - java hello Output- Sunil Kumar Sahu, Lecturer RCET

  23. Writing Java Applet • An applet is a Java program that runs in a Web browser and embedded within an HTML page. • All applets are subclass of APPLET,thus all applets must import java.applet. Applets also import java.awt. • Applets are not executed by the console-based java run time interpreter,rather they are executed by either a web browser or an applet viewer. • There are some important differences between an applet and a standalone Java application, including the following: 1.An applet is a Java class that extends thejava.applet.Appletclass. 2.A main() method is not invoked on an applet, and an applet class will not define main(). Sunil Kumar Sahu, Lecturer RCET

  24. 3.Applets are designed to be embedded within an HTML page. 4.When a user views an HTML page that contains an applet, the code for the applet is downloaded to the user's machine. 5.A JVM is required to view an applet. The JVM can be either a plug-in of the Web browser or a separate runtime environment. 6.The JVM on the user's machine creates an instance of the applet class and invokes various methods during the applet's lifetime. Sunil Kumar Sahu, Lecturer RCET

  25. Example of Applet (SimpleApplet.java) import java.awt.*;  import java.applet.*; /*<applet code=“SimpleApplet” width=200 height=60> </applet> */ public class SimpleApplet extends Applet { public void paint (Graphics g) { g.drawString("Hello World", 25, 50); g.setColor(Color.red); g.drawRect(80,100, 100, 50); g.setColor(Color.blue); g.drawOval(100,120, 90,95); g.fillOval(200,90,30,35); g.fillRect(300,120, 100, 150); } } Sunil Kumar Sahu, Lecturer RCET

  26. Description of Example- This applet begins with two import statements. • 1)The first imports the Abstract Window Toolkit(AWT) classes(import java.awt.*;).Applets interacts with the user through the AWT not through the console based I/O based classes. • The AWT contains support for a window-based graphical interface. 2)The second import statement (import java.applet.*;) imports the applet package which contains the class Applet.Every applet that you create must be a subclass of Applet. Sunil Kumar Sahu, Lecturer RCET

  27. The next line in the the program declares the class SimpleApplet which is declared as public class,because it will be accessed by the code outside the program. • paint() method is defined by AWT and must be overridden by the applet. Paint() is called each time that the applet must redisplay its output. • paint() method has one parameter of type Graphics that contains graphics context,which describes the graphics environment in which the applet is running.This context is used whenever output to the applet is required. • Inside paint() is a call to drawstring(),which is a member of the Graphicsclass.This method outputs a string beginning at the specified X,Y location.It has following form.. void drawString(String message,intx,int y) Sunil Kumar Sahu, Lecturer RCET

  28. After you enter the source code for SimpleApplet, compile in the same way that you have been compiling programs.However running SimpleApplet involves a different process. • There are two ways in which you can run an applet: 1)Using Java compatible web browser. • To execute an applet in a web browser you need to write a short HTML file that contains the appropriate APPLET tag. Example- <applet code=“SimpleApplet” width=200 height=60> </applet> Sunil Kumar Sahu, Lecturer RCET

  29. After you create this file you can execute your browser and then load this file,which causes SimpleApplet to be executed. 2)Using an appletviewer such as standard SDK tool. a)To Execute SimpleApplet with appletviewer, you may also execute the HTML file shown earlier. • For example if the preceding HTML file is called Simple.html then the following command line will run SimpleApplet: C:\>appletviewer Simple.html • Command Prompt Sunil Kumar Sahu, Lecturer RCET

  30. Applet Window b)The simple method is that you can include a comment at the head of java source code file that contains APPLET tag and run with appletviewer like- C:\>appletviewer SimpleApplet.java Sunil Kumar Sahu, Lecturer RCET

  31. Command Prompt Applet Window Sunil Kumar Sahu, Lecturer RCET

  32. Life Cycle of Applet • The Life Cycle of an applet consist of Four methods and one method from AWT(Abstract Window Toolkit) 1)init() 2)start() 3)stop() 4)destroy() 5)paint() Sunil Kumar Sahu, Lecturer RCET

  33. public void init( ) • This is the first method to execute • It is an ideal place to initialize variables • It is the best place to define the GUI Components (buttons, text fields, scrollbars, etc.), lay them out, and add listeners to them • Almost every applet you ever write will have an init() method. public void start( ) • Not always needed • Called after init() • Called each time the page is loaded and restarted • Used mostly in conjunction with stop( ) • start() and stop( ) are used when the Applet is doing time-consuming calculations that you don’t want to continue when the page is not in front Sunil Kumar Sahu, Lecturer RCET

  34. public void stop( ) • Not always needed • Called when the browser leaves the page • Called just before destroy( ) • Use stop( ) if the applet is doing heavy computation that you don’t want to continue when the browser is on some other page • Used mostly in conjunction with start() public void destroy( ) • Seldom needed • Called after stop( ) • Use to explicitly release system resources (like threads) • System resources are usually released automatically Sunil Kumar Sahu, Lecturer RCET

  35. public void paint() • Invoked immediately after the start() method, and also any time the applet needs to repaint itself in the browser. • The paint() method is actually inherited from the java.awt. Sunil Kumar Sahu, Lecturer RCET

  36. init() start() do some work stop() destroy() Methods are called in this order • init and destroy are only called once each • start and stopare called whenever the browser enters and leaves the page • do some workis code called by your listeners • paint is called when the applet needs to be repainted Sunil Kumar Sahu, Lecturer RCET

  37. Example- import java.awt.*; import java.applet.*; /*<applet code="SimpleApplet1" width=200 height=60> </ applet>*/ public class SimpleApplet1 extends Applet{ String out; Public void init() { setBackground(Color.blue); setForeground(Color.yellow); out=“init_”; } public void start() { out+=“start_”; } public void stop() { } public void destroy() { } public void paint (Graphics g) { out+=“paint_”; g.drawString (out, 100, 10); }} Sunil Kumar Sahu, Lecturer RCET

  38. Output- • Command Prompt • Applet Window Sunil Kumar Sahu, Lecturer RCET

  39. DOM(Document Object Model) • The DOM defines a standard for accessing HTML and XML documents.It is a platform and language neutral interface that will allow programs and scripts to dynamically access and update the content,structure and style of documents. • The document can be further processed and the results of that processing can be incorporated back into the presented page. • DOM supports navigation in any direction that means you can navigate to the parent,sibling,or the child nodes from the current node. • DOM is useful in cases where you need to access a document multiple times. Sunil Kumar Sahu, Lecturer RCET

  40. convert XML into a tree of objects . • “random access” protocol(User accesses data by traversing the tree) • Can update XML document (insert/delete nodes). • The API allows for constructing, accessing and manipulating the structure and content of XML documents. DOM is divided into 3 parts: 1.The Core DOM:Includes objects that are present in both XML and HTML documents. 2.The HTML DOM:Includes the HTML Objects. 3.The XML DOM:Includes the XML Objects. Sunil Kumar Sahu, Lecturer RCET

  41. The following are levels of DOM: Level 0: Supports an intermediate DOM,which existed before the creation of DOM Level1. For eg. the DHTML Object Model or the Netscape intermediate DOM. Level1: Includes the navigation of DOM document and allows content manipulation. Level2: Supports xml namespace,filtered views and events. Level3: consist of the following 6 specification- • DOM Level3 Core • DOM Level3 Load and Save • DOM Level3 Xpath • DOM Level3 Views and Formatting • DOM Level3 Requirments • DOM Level3 Validation Sunil Kumar Sahu, Lecturer RCET

  42. HTML DOM • The HTML DOM defines a standard way for accessing and manipulating HTML documents. • The DOM presents an HTML document as a tree-structure. • The HTML DOM is W3C standard object model that defines the objects and properties of all HTML elements and the methods to access them. • The HTML DOM is a standard for how to get,change,add or delete HTML elements. Sunil Kumar Sahu, Lecturer RCET

  43. Document • HTML DOM presents an HTML document as a tree –structure as shown below- Root Element <html> Element head Element body Element title Attribute “href” Element <a> Element <h1> Text “My Text” Text “My link” Text “My Header” Fig. Displaying Html document as Tree Structure Sunil Kumar Sahu, Lecturer RCET

  44. Nodes: • Every element in an Html page represents a DOM node. The nodes are related to each other through the parent child relationship. • All nodes in a document make a DOM tree which describes the relationship among elements. • There are several types of nodes- 1)Element node -Represents the basic building blocks of documents known as elements.These elements can contain other elements such as HTML,HEAD,BODY,A,H1 etc. 2)Text Node -Represents the content contained in element nodes such as title1, link1 and header1 etc. 3)Attribute nodes -Provides more information about elements.Attribute node are always contained in Element nodes.eg href is an Attribute node which is contained within the BODY element. Sunil Kumar Sahu, Lecturer RCET

  45. Objects: • When an html document is loaded into a web browser it becomes a document object.In the same way Element object represents an html element. • Html elements have attributes which are represented btAttr objects. Events:- • HTML DOM also contains events that allow JavaScript to register different event handlers on elements in an html document.These events can be mouse events,keyboardevents,frameevents,objectevents,or form events. • Html DOM events are initiated by the event object which various constants,properties and methods. Sunil Kumar Sahu, Lecturer RCET

  46. HTML DOM Example <!DOCTYPE html> <html> <body> <script> function changeImage() { element=document.getElementById('myimage') if (element.src.match("bulbon")) { element.src="pic_bulboff.gif"; } else { element.src="pic_bulbon.gif"; } } </script> <img id="myimage" onclick="changeImage()" border="0" src="pic_bulboff.gif" width="100" height="180"> <p>Click to turn on/off the light</p> </body> </html> Sunil Kumar Sahu, Lecturer RCET

  47. OUTPUT- After Clicking Sunil Kumar Sahu, Lecturer RCET

  48. innerHTML • The term innerHTML is a property that is used to modify an HTML document. • This propertyis used to modify HTML pages content without refreshing the page,so that your website becomes quicker and responsive to user input. • The innerHTML property is used along with the getElementById() method in JavaScript to refer an HTML page and modify its content. • The syntax is- document.getElementById(‘{ID of element}’).innerHTML=‘{content}’ Sunil Kumar Sahu, Lecturer RCET

  49. The innerHTML property is used to get or set the HTML content of an element node. Example- 1)Get the element with the "someElement" id, and give it new content. document.getElementById('someElement').innerHTML = "new content"; 2)Retrieve the content from an element. var content = document.getElementById('someElement').innerHTML; alert( content ); Sunil Kumar Sahu, Lecturer RCET

  50. 3)Change an HTML Attribute <html> <body> <img id=“image” src=“Winter.jpg”> <script type=“text/javascript”> document.getElementById(“image”).src=“Sunset.jpg”; </script> </body> </html> 4)Change an HTML Element <html> <body> <h1 id=“header”>Old Header</h1> <script type=“text/javascript”> Document.getElementById(“header”).innerHTML=“New Header”; <script> </body> </html> Sunil Kumar Sahu, Lecturer RCET

More Related