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.
Published byModified over 6 years ago
Presentation on theme: "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."— Presentation transcript:
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)
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!!!!!
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
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) 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 the Java Virtual Machine
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 Internet Explorer
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”
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.