CLASS-11 SUBJECT – COMPUTER CHAPTER 4- INTRODUCING

Introduction to Java programming

JAVA was developed by Inc in 1991, later acquired by . It was developed by 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 (JDK). It takes java program as input and generates 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 (). Any system that runs a JVM is able to execute the Java code.

Truly Object-Oriented Build upon ++ 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");

}

}

Types of Program Errors

Syntax Errors

Just like human languages, computer languages have grammar rules. But while humans are able to communicate with less-than-perfect grammar, computers can’t ignore mistakes, i.e. syntax errors. Logic Errors

Logic errors can be the hardest to track down. Everything looks like it is working; you have just programmed the computer to do the wrong thing. Technically the program is correct, but the results won’t be what you expected.

Semantic Errors

A semantic error is also called a "logic error;" however, some programmers believe a logic error produces erroneous data, whereas a semantic error yields nothing meaningful at all. Or, perhaps "it's just semantics!"

NOTE- All the answers should be given in your notebook

Q1- Explain Bytecode and Jvm. Q2- Explain characteristics of Java. Q3- Explain types of program errors.

------