1. Why is Java often termed as a
platform ?
Ans.
Java is a programming language and a platform. Java is a high level, robust,
secured and object-oriented programming language. Any hardware or software
environment in which a program runs, is known as a platform. Since Java has its
own run time environment (JRE) and API, it is called platform.
2. What is byte code ?
Ans.
Byte
codes are the machine language of the Java virtual machine. When a JVM loads a
class file, it gets one stream of byte codes for each method in the class.
3. How is Java platform independent
?
Ans. Java is a platform independent programming
language, Because when you install jdk software on your system then
automatically JVM are installed on your system. For every operating system
separate JVM is available which is capable to read the .class file or byte
code. When we compile your Java code then .class file is generated by javac compiler
these codes are readable by JVM and every operating system have its own JVM so
JVM is platform dependent but due to JVM java language is become platform
independent.
4. What is JVM ?
Ans.
JVM (Java Virtual Machine) is an abstract machine. It is a specification that
provides runtime environment in which java byte code can be executed.
5. Describe ordinary compilation
process.
Ans.
Compilation
for a language such as C or C++ creates machine code that is executable by the
computers CPU.
6. Describe Java compilation
Ans.
Compilation
for Java creates Byte Code that is interpreted by the Java Virtual Machine
(JVM) (it is not run directly by the CPU) The Java Virtual Machine is run
directly by the CPU and it is that program that interprets the compiled Java
Byte Code.
7. How to java byte code executed ?
Ans.
Bytecodes are the machine language of the Java virtual machine. When a JVM
loads a class file, it gets one stream of bytecodes for each method in the
class. The bytecodes streams are stored in the method area of the JVM. The
bytecodes for a method are executed when that method is invoked during the
course of running the program. They can be executed by intepretation,
just-in-time compiling, or any other technique that was chosen by the designer
of a particular JVM.
8. What are Java APIs?
Ans.
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.
9. Write a simple Java program that
prints your name. Compile and run it on Bluej environment.
Ans.
class Javaexample{
public
static void main(String args[]){System.out.println(“Shib Shankar”);} }
10. Add comments to your previous
program. Once again compile and run it.
Ans.
//Print the name…
class
Javaexample{
public
static void main(String args[])
{
System.out.println(“Shib
Shankar”);
}
//end the main
}//end
the class
11. Java is both a programming
language and a platform. Comment .
Ans.
Java compiler converts Java source code to byte code. This byte code is further
converted into machine code to make it applicable for the specific platform by
using interpreter.
12. Briefly tell the history of
Java.
Ans.
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language
project in June 1991. The small team of sun engineers called Green Team.
Firstly,
it was called "Greentalk" by James Gosling and file extension was
.gt. After
that, it was called Oak and was developed as a part of the Green project. In
1995, Oak was renamed as "Java" because it was already a trademark by
Oak Technologies.
13. How are byte code and platform
independence interlinked ?
Ans.
Platform independent means the process in which the certain language is capable
of running on all types of operating system. Java is a platform
independent language cause of the byte code magic of java. In java, when we
execute the source code, it generates the .class file comprising the byte codes.
Byte codes are easily interpreted by JVM which is available with every type of
OS we install.
14.What is the role of JVM in
platform independence ?
Ans.
The Java Virtual Machine (JVM) is an executable that is itself is platform
dependent: that is, there is a unique JVM that must be implemented for any
particular platform to which it is deployed.
The
JVM creates an environment that can load and run Java code. JVM is platform
independent, because it covert’s the Java code into Byte code. Byte code is
same for every machine.
15. What are different
characteristics of Java?
Ans.
1. Write once Run anywhere 2. Light weight code 3. Security 4. Built in
Graphics 5. Object Oriented Language 6. Support Multimedia 7. Platform
Independent .
16. Create a Java program in Bluej
having a function Sayna() that prints JAVA IS EASY TO LEARN WITH BLUEJ
Ans.
class Example{
public static void Sayna(){
System.out.println("JAVA IS EASY
TO LEARN WITH BLUJEJ");
}}
18. Add another class (given below)
in the same program
public class Two
{
public static void display()
{
System.out.println(“Hi There !!”);
System.out.println(“I am in class
Two”);
}
}
Ans.
class Example{
public static void Sayna(){
System.out.println("JAVA IS EASY
TO LEARN WITH BLUJEJ");
}}
public
class Two
{
public
static void display()
{
System.out.println("Hi
There !!");
System.out.println("I
am in class Two");
}
}
19. Now add following code in the
method SayNa() before statement
System.out.println(“JAVA IS EASY TO
LEARN WITH BLUEJ”);
Two.display();
Recompile and run your program. See
what happens.
Ans.
Output:
Hi
There !!
I
am in class Two
20. Now create another program with
following class in it :
Class Three{
public static void main(String
args[]){
System.out.println(“I am in class
there”);
}} compile and run it . See what
happens.
Ans.
class Example{
public static void Sayna(){
System.out.println("JAVA IS EASY
TO LEARN WITH BLUJEJ");
Two.display();
}}
public class Two{
public
static void display(){
System.out.println("Hi
There !!");
System.out.println("I
am in class Two");
}}
class
Three{
public
static void main(String args[]){
System.out.println("I
am in class there");
}}
Output:
Hi
There !!
I
am in class Two