<<

Class 9 Unit 2: Introduction to

Answer the following questions

Q 1- Who developed Java? What was it initially called? developed Java . It was initially called Oak.

Q 2- Mention at least four features of Java. Four features of Java are:

1. It is an Object Oriented Programming Language. 2. It is platform independent. It provides us Write Once, Run Anywhere (WORA) feature. 3. It uses a as well as an . 4. It is case sensitive.

Q 3- Define the following: (a) A compiler A compiler is a program that translates a source program written in some high-level programming language into a target program in another low-level programming language without changing the meaning of the program. The compiler processes the complete source program at once and if there are compilation errors, they are all reported together at once. (b) An interpreter An interpreter is a program that reads a source program line by line, converts each line into its equivalent and executes it. As it reads the program line by line so the errors are reported one by one. () Byte code converts Java into an intermediate binary code called . Bytecode can't be executed directly on the processor. It needs to be converted into Machine Code first.

Q 4- What is Java (JVM)? (JVM) is a that takes Bytecode as input, converts it into Machine code of the specific platform it is running on and executes it. JVM is platform specific, each platform has its own JVM.

Q 5- Name three packages of Java Class . Three packages of are: 1. java.lang 2. java.io 3. java.util

Q 6- What are Java reserved words? Name any five. In Java, a reserved word is a word that has a predefined meaning in the language. Due to this, reserved words can’t be used as names for variables, methods, classes or any other identifier. Reserved words are also known as keywords. Five commonly used Java reserved words are: Public, class, int, double, void etc.

Q 7- Distinguish between: (a) Source code and Source code Object code It is a set of statements in a High-Level It is a set of statements in Machine Language. programming language. It is understood by human/. It is understood by the processor. (b) Compiler and Interpreter Compiler Interpreter It translates the whole source program into It translates the source program into target target program at once. program one line at a time. All the errors found during compilation are Errors are displayed line by line as each line is displayed together at once. translated and executed. (c) JDK 1.3 and BlueJ JDK 1.3 BlueJ JDK or is the set of BlueJ is an IDE or Integrated Development tools required to compile and run Java Environment for developing Java programs. programs JDK includes tools like Compiler, Interpreter, BlueJ provides tools like Code Editor, Debugger, Java libraries, etc. , etc. JDK is essential for developing Java IDE isn't essential for developing Java programs programs. but it makes the easier and efficient.

Q 8- What is the format of a Java Program? Explain with an example. The basic format of a Java program with example . /* First Program of KnowledgeBoat's Applications course Name this "HelloJava.java" */ class HelloJava {

//Your program starts with a call to main()

public static void main(String args[]) {

System.out.println("Hello Java!!!");

} } This is a short and simple Java program which prints Hello Java!!! on the console.

Q 9- Mention five features of BlueJ. Five features of BlueJ are:

1. Simple beginner friendly . 2. It allows creating objects of the class dynamically, invoking their methods and also supplying to the method arguments if present. 3. It supports syntax highlighting. (Syntax highlighting means showing the different tokens of the program like keywords, variables, separators, etc. in different colours so that they show up more clearly.) 4. It facilitates easier as lines causing compilation errors are marked clearly and the error is displayed at the bottom of the window. 5. It provides a code editor, compiler and debugger integrated into a single tool.

Q 10- Name a package that is invoked by default. java.lang

Q 11- What are the points to be taken care while naming a class in a Java program? A class name should be a valid Java identifier i.e. it should follow the below three rules:

1. Name of the class should be a sequence of alphabets, digits, and dollar sign characters only. 2. It should not start with a digit. 3. It should not be a keyword or a boolean or null literal.

Q 12- Java is a case sensitive. Explain. Java is case sensitive means that it distinguishes between upper case and lower case characters. Consider the below code : int studentMarks; StudentMarks = 85; This will give a as Java will treat studentMarks and StudentMarks as two different variables because the case of the characters is not same in both.

Q 13- The main function in a Java program is declared as: public static void main (String args[]) What is the significance of the words public, static and void? public — The public keyword is an access specifier. It controls the visibility of class members. We can access public class members outside the class where we declare them. We need to the main method public because it will be called by code outside of its class when the program is started. static — When we declare a method inside a class as static, we can call it without creating the object of that class. We need to make the main method static because Java Virtual Machine (JVM) will call it to start the program even before any objects of the class are created. void — The void keyword tells the compiler that the main method will not return any value.

Q 14- What does the term 'Compilation' mean? The process of converting a source program written in some high-level programming language into a target program in another low-level programming language without changing the meaning of the program is called Compilation.

Q 15- Java program uses compiler as well as interpreter. Explain. Java compiler compiles Java source code to Bytecode. Bytecode cannot run on the processor directly as processor only understands Machine Code. Java Virtual Machine (JVM) takes this Bytecode as input and converts it into Machine Code line by line. So, JVM acts as an interpreter for converting Bytecode to Machine Code. In this way, a Java program uses both a Compiler as well as an Interpreter to get executed on the processor.

Q 16- Why Java is called Platform Independent Language? Java is known as platform independent language because its bytecode can run on all . Whenever, a program is written in JAVA, the java compiler compiles it. The result of the JAVA compiler is the . class file or the bytecode and not the machine code and bytecode can be run on any OS.

Q17- What is WORA? Write once, run anywhere (WORA) is a term that refers to a particular program's supposed ability to run on all common OSs (operating systems). The term, sometimes also expressed as write once, run everywhere (WORE), was originally coined by in reference to Java.

Q18- What is the meaning of Robust in Java? Robust simply means strong. Java is robust because: It uses strong . There is a lack of pointers that avoids security problems. 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.

Q19-What is Multithreading in Java? Multithreading is a process of executing multiple threads simultaneously. is basically a lightweight sub-process, a smallest unit of processing. The main purpose of multithreading in Java is to provide simultaneous of two or more parts of a program to utilize the CPU to the maximum.

Q20- What makes Java Architecture Neutral? In Java there are no implementation dependent features. In most of other languages you need to know features that are hardware or OS dependent. For example in a high-level language called C the int occupies 2 bytes of memory for 32- architecture and 4 bytes of memory for 64-bit architecture. But in java, it occupies 4 bytes of memory for both 32 and 64 bit architectures.

Q21. Name two types of Java programs. Application and Applet

Q22. What is Java API? An application programming interface (API), in the context of Java, is a collection of prewritten packages, classes, and interfaces with their respective methods, fields and constructors.

Q23-State the difference between Applet and Application. The fundamental difference between the two Java programs is that an application program is designed to run on a stand-alone machine whereas an applet is a web-version of an application which is used to run a program on a web browser.

Q 24- Design a program to display the following information on the output screen: Name: Class: Roll No.: Subject: School:

Answer class StudentInfo { public static void main(String args[]) { System.out.println("Name: Akshay Anand"); System.out.println("Class: 10"); System.out.println("Roll No.: 5"); System.out.println("Subject: Computer Applications"); System.out.println("School: KnowledgeBoat"); } }

Q 25- You want to display your bio-data on the output screen. Write a program in Java to perform the task in the given format: Name: Father's Name: Date of birth: Blood Group: Aadhar Card No.: State:

Answer class BioData { public static void main(String args[]) { System.out.println("Name: Shweta Nayak"); System.out.println("Father's Name: Arvind Nayak"); System.out.println("Date of birth: 12/12/2005"); System.out.println("Blood Group: O+"); System.out.println("Aadhar Card No.: 4321 8756 9978"); System.out.println("State: Karnataka"); } }

Fill in the blanks with appropriate words 1. Java is a case sensitive language. 2. In Java, the package used to find power raised to any base is java.lang. 3. The words which are preserved with the system are called keywords/reserved words, that can not be used as variable names in Java programming. 4. A single line comment is represented by the // in Java programming. 5. BlueJ is a window based platform to operate Java program. 6. James Arthur Gosling is called the father of Java programming language. 7. Java was formerly known as Oak. 8. A Java program written in a is called the Source code. 9. Bytecode is a set of pseudo machine language instructions that are understood by the JVM. 10. Java is independent of the underlying hardware and software and is therefore called platform independent. 11. The process of converting a source code to byte code is called compilation. 12. A platform is the hardware/software environment in which a program remains. 13. The byte code file in Java has the .class extension. 14. JVM is a microprocessor that is implemented in software and runs using the capabilities provided by your operating system and . 15. Multi-threading is a process of executing multiple threads simultaneously.

Write True or False: 1. Java application is a Java program which is developed by users.T 2. James Gosling developed Java programming language. T 3. Machine codes are expressed using alphanumeric characters.F 4. Byte code is the program in binary form. F 5. JVM is Java Visual Management. F 6. The byte code when compiled gives source code. F 7. A Java program can execute only in Windows machine. F 8. A Java API is a collection of prewritten packages, classes, and interfaces with their respective methods, fields and constructors. T 9. Source Code in Java has the .class extension. F 10. Java is simple to learn. T

Tick () the correct option. 1. What was Java initially called? a Oak b. C c. C++ . None of these Ans. a. Oak

2. What is Java Programming Language? a. A b. A set of development tools. c. An Application Programming Interface (API) d. All of these Ans. d. All of these

3. Name the process that converts source code to bytecode. a. Interpretation b. Compilation c. All of these d. None of these Ans. b. Compilation 4. A Virtual Processor that is implemented in software and runs using the capabilities provided by your operating system and computer hardware. a. Byte Code b. Compiler c. Interpreter d. Java Virtual Machine(JVM) Ans. d. Java Virtual Machine(JVM)

5. Which among the following is not a language feature in Java? a. Robust b. Secured c. Platform Independent d. Procedure Oriented Ans. d. Procedure Oriented

5. Name the programs that can be developed in such a way that it remains embedded in a web page and runs on the viewer’s machine in a secured manner by Java compatible browsers. a. Applets b. Applications c. Both a and b d. None of these Ans. a. Applets

6. Name the Application program that is written and compiled which may then be executed in any machine provided it contains the JVM. a. Applets b. Applications c. Both a and b d. None of these Ans. b. Applications

8. What is the extension of a source code in Java? a. .java b. .class c. Both a and b d. None of these Ans. a. .java

9. What is the extension of the byte code in Java? a. .java b. .class c. Both a and b d. None of these Ans. b. .class

11. What is a set of pseudo machine language instructions that are understood by the Java Virtual Machine and are independent of the underlying hardware called? a. JVM b. Source Code c. Compilation d. Bytecode Ans. d. Bytecode