Introduction to Java
[Link] developed Java? What was it initially called?
James Gosling developed Java programming language. It was initially called Oak.
[Link] a brief historical development of Java.
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.
[Link] 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 compiler as well as an interpreter.
4. It is case sensitive.
[Link] 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 machine code and executes it. As it reads the program line by line so the errors
are reported one by one.
(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.
[Link] is Java Virtual Machine (JVM)?
Java Virtual Machine (JVM) is a software 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.
6. Name three packages of Java Class Library.
Three packages of Java Class Library are:
1. [Link]
2. [Link]
3. [Link]
[Link] 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:
1. public
2. class
3. int
4. double
5. char
[Link] between:
(a) Source code and Object code
Source code
§ It is a set of statements in a High-Level programming language.
§ It is understood by human/programmer.
Object code
§ It is a set of statements in Machine Language.
§ It is understood by the processor.
(b) Compiler and Interpreter
Compiler
§ It translates the whole source program into target program at once.
§ All the errors found during compilation are displayed together at once
Interpreter
§ It translates the source program into target program one line at a time.
§ Errors are displayed line by line as each line is translated and executed.
(c) JDK 1.3 and BlueJ
JDK 1.3
§ JDK or Java Development Kit is the set of tools required to compile and run
Java programs
§ JDK includes tools like Compiler, Interpreter, Java libraries, etc.
§ JDK is essential for developing Java programs.
BlueJ
§ BlueJ is an IDE or Integrated Development Environment for developing Java
programs.
§ BlueJ provides tools like Code Editor, Debugger, Syntax Highlighting, etc.
§ IDE isn't essential for developing Java programs but it makes the process
easier and efficient.
9. A compiler is specific to a language. Give your comments.
A compiler translates a source program written in some high-level programming language
into a target program in another low-level programming language. As low-level programming
languages are platform specific hence a compiler is specific to a language.
10. What is the basic format of a Java Program? Explain with an example.
A Java program consists of the following basic components:
1. Comments in a program — Comments are non-executable statements included to
provide notes about the program. They are most commonly used to explain the logic
of the program. Comments are ignored by the compiler.
2. Declaration of class — All Java programs start with a class. The syntax of class
declaration is class { /*class body*/ }
3. Declaration of main function — The main method is the main entry point to the
program. Program execution begins with the main method. The syntax of main
method declaration is public static void main(String args[]) { /*body of main
method*/ }
4. The statements of a Java program are terminated with a semi-colon. Missing a semi-
colon will lead to compilation errors.
Below is an example of a basic Java program:
/*
* Example of a basic Java program
*/
//Class Declaration
public class Add
{
// Main function Declaration
public static void main(String args[]) {
int a = 10, b = 15, c = 0;
c = a + b;
[Link]("Sum = " + c);
}
}
[Link] is BlueJ?
BlueJ is an integrated development environment for Java. It was created for teaching Object
Oriented programming to computer science students.
[Link] five features of BlueJ.
Five features of BlueJ are:
1. Simple beginner friendly graphical user interface.
2. It allows creating objects of the class dynamically, invoking their methods and
also supplying data 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 debugging 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.
[Link] a package that is invoked by default.
[Link]
[Link] 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, underscore 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.
[Link] is a case sensitive. Explain.
Java is case sensitive means that it distinguishes between upper case and lower case
characters. Consider the below code snippet:
int studentMarks;
StudentMarks = 85;
This will give a compilation error as Java will treat studentMarks and StudentMarks as two
different variables because the case of the characters is not same in both.
[Link] 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 make 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.
[Link] 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.
[Link] 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.
[Link] a program in Java to display the following information on the output screen:
Name:
Class:
Roll No.:
Subject:
School:
class StudentInfo {
public static void main(String args[]) {
[Link]("Name: Akshay Anand");
[Link]("Class: 10");
[Link]("Roll No.: 5");
[Link]("Subject: Computer Applications");
[Link]("School: KnowledgeBoat");
}}
[Link] 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:
class BioData {
public static void main(String args[]) {
[Link]("Name: Shweta Nayak");
[Link]("Father's Name: Arvind Nayak");
[Link]("Date of birth: 12/12/2005");
[Link]("Blood Group: O+");
[Link]("Aadhar Card No.: 4321 8756 9978");
[Link]("State: Karnataka");