Indicate whether the following statements are true or false
Source code is also called an object program.
JVM converts byte code to machine code.
Keywords are also referred to as reserved words.
Multi line comments are same as documentation comments.
Java is a menu based approach.
There is no difference between print() and println() statement.
Java language can use applications as well as applets.
Java language is developed by Sun Micro-systems.
Java language uses compiler but not an interpreter.
Byte code and machine code are synonyms.
Fill in the blanks with the appropriate word/words
A program of Java that can be developed and executed by the users, is known as Java application.
The inventor of Java is James Gosling.
Java Virtual Machine (JVM) is a Java interpreter.
Keywords can also be called Java reserved word.
BlueJ is a window based platform to execute Java programs.
We can write comments in a Java language by three ways.
Debugging is the term used to correct the error in a program.
JDK 1.5 is a DOS based platform for Java programs.
Write short answers
What is Java? What was it called initially?
Java is an Object Oriented programming language developed in 1991 by James Gosling at Sun Microsystems. It was initially called 'Oak'.
What are the features of Java?
The features of Java are:
- It is an Object Oriented Programming Language.
- It is platform independent. It provides us Write Once, Run Anywhere (WORA) feature.
- It uses a compiler as well as an interpreter.
- It is case sensitive.
- It is a multithreaded language.
Name a Java package, which is imported by default.
Explain briefly about the development of Java language.
In 1991, at Sun Microsystems, Green team led by James Gosling started working on a new technology for consumer electronic devices. Over the next 18 months, in 1992 the team created a new programming language which they called “Oak”. By 1994 the team refocussed their efforts towards internet programming with Oak as it didn't find much traction in consumer electronics space. Oak was renamed to Java and on 23rd of May 1995, Sun microsystems made its first public release.
What are the different ways to give comments in Java Programming?
There are three ways to write comments in Java:
- Single Line comment.
- Multi line comment.
- Documentation comment.
Explain the significance of the following Java library packages.
It provides classes that are fundamental to the design of the Java programming language. Some of the important classes it contains are Object, which is the root of the class hierarchy, Class, instances of which represent classes at run time, Wrapper classes and Math class, which provides commonly used mathematical functions such as sine, cosine, square root, etc.
It contains the classes that handle fundamental input and output operations in Java.
java.math package provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal). Refer to the official documentation for more details.
Clarification: Mathematical Library Functions like min(), max(), abs(), avg(), floor(), ceil(), round(), sqrt(), pow(), etc. are present in Math class of java.lang package. java.lang.Math class should not be confused with java.math package.
Give an example of each with reference to Java programming:
(a) Single Line comment
// This is my first program.
(b) Multi Line comment
/* This is my first program.
It calculates the sum of two numbers.*/
Define the terms:
(a) Source code
A set of statements written in a High-Level programming language like Java, C++, Python, etc. is called as Source Code.
(b) Machine code
Machine code is a low-level programming language. Instructions in machine code are written as a sequence of 0s and 1s. It is directly understood and executed by the processor.
(c) Byte code
Java compiler converts Java source code into an intermediate binary code called Bytecode. Bytecode can't be executed directly on the processor. It needs to be converted into Machine Code first.
(a) Compiler and Interpreter
|It converts the whole source program into object program at once.||It converts the source program into object program one line at a time.|
|It displays the errors for the whole program together after compilation.||It displays the errors of one line at a time and after debugging the control goes to the next line.|
(b) Java (JDK 1.5) and BlueJ
|JDK or Java Development Kit is the set of tools required to compile and run Java programs||BlueJ is an IDE or Integrated Development Environment for developing Java programs.|
|JDK includes tools like Compiler, Interpreter, Java libraries, etc.||BlueJ provides tools like Code Editor, Debugger, Syntax Highlighting, etc.|
|JDK is essential for developing Java programs.||IDE isn't essential for developing Java programs but it makes the process easier and efficient.|
What is BlueJ? What are the features of BlueJ?
BlueJ is an integrated development environment for Java. It was created for teaching Object Oriented programming to computer science students. Features of BlueJ are:
- Simple beginner friendly graphical user interface.
- It allows creating objects of the class dynamically, invoking their methods and also supplying data to the method arguments if present.
- 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.)
- It facilitates easier debugging as lines causing compilation errors are marked clearly and the error is displayed at the bottom of the window.
- It provides a code editor, compiler and debugger integrated into a single tool.
Write down the syntax of output statement in Java programming with an example
We commonly use two output statements in Java. There syntax are:
- System.out.println(<output value>); — This statement prints data on the console. The data to be printed is passed to the println method as a String. After printing the string, it places the cursor at the start of the next line. So the next printing happens at the start of the next line.
- System.out.print(<output value>); — This statement also prints data on the console. The data to be printed is passed to the print method as a String. After printing the string, the cursor remains on the same line at the end of the printed string. So the next printing starts in the same line just after the end of the previous printed string.
As an example, the below statements will generate the following output:
System.out.println("JVM stands for"); System.out.print("Java "); System.out.print("Virtual "); System.out.print("Machine");
JVM stands for Java Virtual Machine
What do you understand by Java reserved words? Name at least five Java reserved words which are commonly used in Java programming.
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:
Write down all the steps to compile and execute a Java program.
- Right click on the class icon in the BlueJ main window.
- Select the compile option from the menu that appears.
- Again right click on the class icon in the BlueJ main window and select the option void main(String args).
- Click OK on the method call window that appears on the screen.
- The desired output of the program will be shown on the screen.
'Java interpreter is also called Java Virtual Machine'. Justify the statement.
Java Virtual Machine takes Bytecode as input and converts it into Machine Code one line at a time. This Bytecode can be generated by compiling source code written in any JVM language like Scala, Kotlin, etc not just Java. Hence, Java interpreter is called Java Virtual Machine.
A 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.
Distinguish between System.out.print() and System.out.println() with an example.
|It prints data to the console and places the cursor in the next line.||It prints data to the console but the cursor remains at the end of the data in the same line.|
|Next printing takes place from next line.||Next printing takes place from the same line.|
How can you modify a Java program on BlueJ platform?
To modify a Java program on BlueJ platform we will double click the class icon to open the source code of the class. Now we will make the required modification to this Java program.