1 / 10

Lecture 2: Do you speak Java?

Lecture 2: Do you speak Java?. From Problem to Program. Last Lecture we looked at modeling with objects! Steps to solving a business problem Investigate current problem (Analysis) Transform this model to logical models (Design) Transform this model to software (implementation)

kent
Download Presentation

Lecture 2: Do you speak 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. Lecture 2: Do you speak Java?

  2. From Problem to Program • Last Lecture we looked at modeling with objects! • Steps to solving a business problem • Investigate current problem (Analysis) • Transform this model to logical models (Design) • Transform this model to software (implementation) • Need to translate model to something computers can understand (mathematical equations)

  3. Parlez Vous Binary? • 1001110000010101010000001111 • How do we translate our business problem into machine code? • Initially, a programmer writes a program in a particular programming language. This is called source code!!!!! • To execute the program however, the programmer must translate it into machine language……the language that the computer understands. How do we do this? • A COMPILER does this!!!!!

  4. Compiler • A compiler converts source code into machine level instructions • Almost every programming language comes with a compiler • In effect, the compiler is the language because it defines which instructions are acceptable

  5. Javac • The Java compiler (javac) is the component of the Java Developers kit (JDK) USED TO TRANSFORM Java source code files into bytecode (not machine code) • Javac phil.java • Bytecode is the compiled format for Java programs. Once a Java program has been converted to bytecode, it can be transferred across a network and executed by Java Virtual Machine

  6. Java Virtual Machine • Bytecode is not really machine code and cannot be used by a computer – it must be interpreted • The Java Virtual Machine (JVM) is an interpreter, it interprets byte code and can thus execute quickly • The Java interpreter is built into Java compatible web browsers such as Netscape navigator which enables applets to run

  7. Why Compile and Interpret? • Because byte code is used instead of machine code, a java program can be executed on any machine that has a Java interpreter • This makes java extremely portable……a program can be compiled on one machine and executed on any • Java used extensively on web sites • Java not only offers portability but identical behaviour on different systems • “WRITE ONCE, RUN EVERYWHERE”

  8. Compiling and interpreting • Java source code is written with a text editor and saved in plain ASCII text with file extension .java • These files are compiled using the javac compiler • E.g. javac Examplehelloworld.java • Executable bytecode class files have the extension .class and they represent a Java class in its usable form • The Java compiler generates exactly one .class file for each class you create. It is possible to define more than one class in a single source file, it is therefore possible for the compiler to generate multiple class files from a single source file.

  9. Java and the Web • Applet written and compiled in exact same way as Java application • Applets downloaded when user navigates to page • Browsers contain Java virtual machine and applet is executed on client machine

  10. Java Applets • Applets were originally small applications but there is no size restriction on Applets • As applets are downloaded, there is a risk that they may • Contain Bugs • Be written maliously • However, browsers are usually configured to prevent applets from accessing files on the machine on which they execute • Applets can access files on the server from which they were downloaded • Java applications will be covered in this course but applets will be revisited

More Related