Oop lecture2
-
Upload
shahriar-robbani -
Category
Education
-
view
215 -
download
0
Transcript of Oop lecture2
Java compilation process
Lecture 2
Object Oriented Programming
Eastern University, DhakaMd. Raihan Kibria
Source-to-machine code
Steps: Java source—ClassDemo.java Compiler (javac) – output is bytecode
ClassDemo.class Run (java) – ClassDemo.class is interpreted
and converted into executable
Java Virtual Machine
It is a piece of software also called JVM Understands byte code produced by javac Interprets the byte code and runs program Cross-platform (windows, linux, mac)
compatibility
Difference between JDK and JRE
JDK is Java Development Kit Needed to compile (javac)
JRE is Java Run-time environment Needed to run programs/byte-code
Difference between object code and byte code
Object code: Typically has an extension *.exe (in windows) Produced by compiler During run-time no more interpretation is needed
because output is already in 1's and 0's Machine/OS dependent
Byte code: Has an extension *.class regardless of operating
system Produced by java compiler The byte-code is still not in 1's and 0's. Rather JVM
needs to convert the .class files into 1's and 0's Byte code is machine/OS independent
Advantage of byte code representation
Machine/OS independent Can be compiled “Just In Time” (JIT) Can run on browsers as applets Can be made faster by JIT compiler
optimization techniques
Example of a java desktop application
Also called java swing applicationimport java.awt.FlowLayout;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;
public class SwingDemo { public static void main(String[] args) { JFrame jframe = new JFrame(); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setBounds(0, 0, 300, 200); jframe.getContentPane().setLayout(new FlowLayout());
JButton jbutton = new JButton("Test button"); jframe.getContentPane().add(jbutton);
JTextField jtext = new JTextField(); jframe.getContentPane().add(jtext); jtext.setText("Hello"); jframe.setVisible(true); }}
Output