Oop lecture2

322 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
322
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Oop lecture2

  1. 1. Lecture 2Java compilation process Object Oriented Programming Eastern University, Dhaka Md. Raihan Kibria
  2. 2. Source-to-machine codeSteps: Java source—ClassDemo.java Compiler (javac) – output is bytecode ClassDemo.class Run (java) – ClassDemo.class is interpreted and converted into executable
  3. 3. 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
  4. 4. 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
  5. 5. 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 1s and 0s Machine/OS dependent Byte code: Has an extension *.class regardless of operating system Produced by java compiler The byte-code is still not in 1s and 0s. Rather JVM needs to convert the .class files into 1s and 0s Byte code is machine/OS independent
  6. 6. 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
  7. 7. Example of a java desktop application Also called java swing application import 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); } }
  8. 8. Output

×