1 / 13

CS413: Java

CS413: Java. Programming language Applications Applets Conceived by Sun Microsystems Benefits

cliffordb
Télécharger la présentation

CS413: 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. CS413: Java Programming languageApplicationsApplets Conceived by Sun Microsystems Benefits Runs on any Java enabled Web BrowserNo installation or setup adjustmentsNo need to scan for virusesCan create large graphics (charts, tables) on the fly No need to download large graphics Increase download speed Security Features Runtime examination: program is examined line-by-line for valid Java only code Restricted Interactivity: Built-in restrictions on establishing connections to other computers The Java applet can only connect to the Internet location it came from Restricted Access Rights: Built in restrictions on a program being able to read and write data A program can only access the parts of a computer where it has received advance permission to access

  2. CS413: Java Usage samplesInteraction with a userCalculate information of a web pageAdminister a quiz‘Dress’ a web pageControl animation on a web pageControl GUI interfaces Open System Any hardware or software product that matches the published specifications Published specifications establish a shared definition of how components must work together Sun Microsystems has published detailed specifications for Java A program written in Java can run on any Java-enabled system with no adaptation required Permits programs to be: More widely distributed More easily easily used

  3. CS413: Java Java Applet (Internet Web Page) Manipulate words, numbers, and pictures Create and control GUI interface Display windows, buttons, and menus User to point and click with a mouse to control actions Information displayed in a variety of colours, styles, and sizes Graphical User Interface (GUI) Enables the user to do all of the above to make the web page/site easier and more interesting to use

  4. CS413: Java • Java Applet • A mini program written Java and attached to a web pageFast to download • Enhance the web page display • Enable the user to interact with the web page • Enable the user to complete specific tasks • Manipulates data • Creates graphics

  5. CS413: Java Text file Extension of .java Java compiler Executable Java applet.class HTML page Java enabled browser anyname.html Programmer Source Codeanyname.java Java compilerjavac Applet file‘Bytecode’anyname.class HTML pageanyname.html HTML pageJava translatoranyname.html User

  6. CS413: Java • Assembler • Creates a machine language executable file (program) • Programs written in Assembler language • Each Assembler language instruction generates one machine language instruction • Fast execution • Compiler • Creates a machine language executable file (program) • Programs written in higher level languages COBOL, PL1, RPG, FORTRAN • Each programming language instruction generates one or more machine language instructions • Fast execution

  7. CS413: Java • Translator • DOES NOT create machine language executable file (program) • Limited instruction set (compared to Assembly and Compiler languages) • Slow processing Every instruction is read from the input file and processed individually 1. Instruction is read into the translator 2. Converted by the ‘Translator’ to 1 or more machine language instructions 3. Instruction is executed 4. Cycle starts again with next instruction • Slow processing due to • Loops • Decision blocks

  8. CS413: Java • Java creation/compile/execution (translation)Using DOS • Create the Java code in a text editor • Save the file somename.java extension • Open a DOS window • Enter path command at the c:\windows> promptpath=c:\jdk1.2.2\bin • Change DOS directory to where the .java file is located • Enter javac somename.javaTo compile the Java code to a .class file • Fix any errors and re-compile (Step 6) • When no more errors - continue • Enterjava somenameTo execute the compiled version

  9. CS413: Java Java creation/compile/execution (translation)Using Java Development Kit (JDK)

  10. CS413: Java LAB I: Java program import java.applet.*; import java.awt.*; /** This is a comment block */ public class HelloWorld extends Applet { Label helloLabel = new Label(“Yo, you lookin’ at me?”); public void init() { setBackground(Color.yellow); add(helloLabel); } }

  11. CS413: Java • Java code in a Web page • Create an HTML document in a text editor Save as .htm or .html file • Insert the following Java code in the <body> area of the HTML file • <APPLET CODE= “somename.class” width=300 height = 50></APPLET> • Open the .htm/.html file in a browser Basic HTML Document <HTML> <HEAD> <TITLE></TITLE> </HEAD> <BODY> </BODY> </HTML>

  12. CS413: Java Java Program Description import java.applet.*;Reference a Java library of pre-written code* = make all library code members accessible import java.awt.*;Reference a Java library of pre-written code* = make all library code members accessible /**begin comment area This is a comment block */end comment area public class HelloWorld extends Applet {public = the applet is accessible by outside programsclass = defines this applet as a Java classHelloWorld = name of the Java classextends Applet = required for a Java class declaration Label helloLabel = new Label(“Yo, you lookin’ at me?”);Label = Java code from the Java.awt library Display something on the screenhelloLabel = programmer name of the Labelnew Label = Java definition creating the Label( ….) = Text to be displayed on the screen

  13. CS413: Java Java Program Description public void init() { Define what is to happen at applet initalization setBackground(Color.yellow);Set the background color to yellow add(helloLabel); Add the data from helloLabel to the graphic } end of ‘public void’ method } end of entire applet

More Related