130 likes | 147 Views
CS413: Java. Programming language Applications Applets Conceived by Sun Microsystems Benefits
E N D
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
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
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
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
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
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
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
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
CS413: Java Java creation/compile/execution (translation)Using Java Development Kit (JDK)
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); } }
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>
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
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