SUBJECT-COMPUTER CLASS-12 CHAPTER 9 – Compiling and Running Java Programs
Total Page:16
File Type:pdf, Size:1020Kb
SUBJECT-COMPUTER CLASS-12 CHAPTER 9 – Compiling and Running Java Programs Introduction to Java programming JAVA was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language. Writing, compiling and debugging a program is easy in java. It helps to create modular programs and reusable code. Bytecode javac compiler of JDK compiles the java source code into bytecode so that it can be executed by JVM. The bytecode is saved in a .class file by compiler. Java Virtual Machine (JVM) This is generally referred as JVM. Before, we discuss about JVM lets see the phases of program execution. Phases are as follows: we write the program, then we compile the program and at last we run the program. 1) Writing of the program is of course done by java programmer. 2) Compilation of program is done by javac compiler, javac is the primary java compiler included in java development kit (JDK). It takes java program as input and generates java bytecode as output. 3) In third phase, JVM executes the bytecode generated by compiler. This is called program run phase. So, now that we understood that the primary function of JVM is to execute the bytecode produced by compiler. Characteristics of Java Simple Java is very easy to learn, and its syntax is simple, clean and easy to understand. Multi-threaded Multithreading capabilities come built right into the Java language. This means it is possible to build highly interactive and responsive apps with a number of concurrent threads of activity. Platform Independence Java has a philosophy called WORA (Writing Once, Run Anywhere). Java code is compiled into an intermediate format, called bytecode, which is to be executed in the JVM (Java Virtual Machine). Any system that runs a JVM is able to execute the Java code. Truly Object-Oriented Build upon C++ which is semi object-oriented, Java extends the functionality to become a fully object-oriented programming language. Some of the most important features that make it an object-oriented puritan are: • Abstraction • Encapsulation • Inheritance • Polymorphism Robust Robust simply means strong. Java is robust because: o It uses strong memory management. o There is automatic garbage collection in java which runs on the Java Virtual Machine to get rid of objects which are not being used by a Java application anymore. o There are exception handling and the type checking mechanism in Java. All these points make Java robust. Secured Java is best known for its security. With Java, we can develop virus-free systems. Java is secured because: o No explicit pointer o Java Programs run inside a virtual machine sandbox Bytecode Verifier: It checks the code fragments for illegal code that can violate access right to objects. Simple java program: MyClass.java public class MyClass { public static void main(String[] args) { System.out.println("Hello World"); } } NOTE- All the answers should be given in your notebook Q1- Explain Bytecode. Q2- Explain Jvm. Q3- Explain characteristics of Java. --------------------- .