An Introduction to Java
An Introduction to Java
An Introduction to Java
or buzzwords of Java
12 Features
features of java.
1. Explain 5 Marks
OR
Q2. Describe any 2 features of the Java Programming Language. Apr 2012, 1Mark]
OR
Java supports automatic garbage collection hence no need to remove unreferenced objects.
2) Object Orlented
06] Why Java ls called as purely object orlented programming language?
[OCT 2012, 1 Mark]
OR
java is a pure object oriented language". State whether True/False and justify.
[Apr 2011, 1 Mark]
1-2 Proramming in Java-i
\ns
lava contains an extensive class library available in the core programming packages
and polymo
. t supports all 00Ps features such as abstraction, encapsulation, inheritance and polymorphism,
object. classes etc.
Q8) Justify True/False: Java is not fuly object-orlented. Apr 2012,1 Mark
Ans: False
3) Platform Independent
09) Explain how Java language is platform independent List any four features of Java.
Java code can be run on multiple platforms e.g. Windows, Linux, Sun Solaris, Mac OS etc.
Java code compiled by the compiler and converted into bytecode. This bytecode can be run on
is
multiple platforms i.e. Write Once and Run Anywhere (WORA) without changing its source
code.
Thus Java is called a platform independent.
4) Architecture-Neutral
Q10] Java is called platform-neutral language. Give one reason
supporting the glven argument.
Ans:
[1 Mark
Java compiler generates bytecode which ís intermediate between source and native machine code
which is neutral.
JVM converts the bytecode into native code
for a particular processor
Unlike C/C+*, in Java the size
of the primitive data are types platform independent. For
int inJava is always a 32-bit integer. example, an
5) Portable
Java class file can be execute in
any platform which has
java run time system i.e. JVM.
For example Mobile, Computer has its own JVM to execute
Java programs can java programs.
be run on
any platform (Linux, Window, Mac)
MS Publications
O Simple Solvtios
Introduction to Java 13
. Java programs can be transterted over world wide web (eg applets)
Since Java language supports platform independent and architectural neutral, it is known as portable.
6) Secure
Is seue because:
Java
. I t run4side VM and hence almost null interaction with OS
7) High performance ,
Java uses bytecode which is faster than traditional interpretation are highly optimized.
So performance of this language is high.
.Unused memory space is collected by Garbage Collector automatically. It improves the performance
of application.
Java provides many-high performance features such as Just-In-Time compiling, native code usage
and better resource utilization.
B) Robust
I t also has Exception Handling to handle runtime erors and type checking mechanism.
9) Multdthreaded
This java feature makes it possible to write programs which perform many tasks simultaneously
I t shares memory and resources which increases performance
VM.
and converts it into machine specific code whích can
Then VM interpreter interprets t ytecode
be executed on any operating system.
O Simple Solutions
MS Publicatons
T4Programming in Java-
r
No. Java C++
Q-A
Q1. What is bytecode?7
[1 Mark)
MS Publications
O Simple Solutons
1- Introduction to Java 1-5
Q2. "Bytecodes are what make java platform independent". State whethar True/False and Justity.
[Oct 2010, 1 Mark]
Ans: True.
Platform independence means java programs can run on any platform like Windows, Mac 05, LAnux.
Java compiler compiles java code and generates a.class file. This class file contains bytecodes.
These bytecodes are JVM dependent not platform dependent
Because VM is available for many different platforms such as Windows, Mac OS, Linux, a same.class
file can run on any of these platforms.
03. If the operating system is changed, the bytecode of a java program should also be changed'.
State whether True/False and justfy. [Apr 2011, 1 Mark)
Ans: False.
Ans: False.
I t generates bytecode which can be run on any platform having ]VM.
JVM converts bytecode to executable code for specific operating system.
executes l t
tioads the bytecode from class file, verifies it and
|1 Mark)
Q9. What is JRE?
Ans
runs.
which JvM
the environment in
Environment is
I R E L. Java Runtime of java
needed tor h e
execuuon
program.
It contains |VM, Class libraries and other supportive files
environment
[Oct 2015,4 Mark
Q10. Explaln varlous component of Java
are :
Ans: Various Components of Java Environment
tool
1) Java Compiler: Java compiler is javac
is used to interpret thee .class java nies tnat nave been compiled by
2 Java Interpreter: Java interpreter
Java compiler (javac).
disassembles one or more class files.
command is the tool that
3) ava Disassembler: The javap
File Generator javah command-line tool) generates C
4) Java Header File Generator: Java Header
header and source files that are needed to implement native methods.
5) Java Documentatton: Java Documentation helps to maintain code. It Generates HTML pages
Q1. State and explain vartous java tools used [Any two for 1 Mark]
Ans:
Tool
Description
javac It is java compiler used to compile java program.
java It is the launcher for java application
Javap This command disassembles one or more class files.
Jdb Jdb is the Java Debugger helps to find and fix bugs in Java programs.
avaw tis similar to javaw except console window is not associated with it
MS Publications
O Simple Solutions
1- Introduction to Java 1-7
Tool
Descriptlon
appletviewer Run and debug applets without a web browser
Q2. Glve syntax of Javac command.
1 Mark)
OR
03. What is the use ot javac command.
Ans.:
. The javac is the java compiler which takes name ofsource file as input.
i. It reads class and intertace definítions, written in the Java
into bytecode class files.
programming language, and compiles them
iii. It can also process annotations in Java source files and class.
v. Syntax
javac[ options][ sourcefiles] [ classes|[ @argfiles
Where,
Optlons: Command-line options.
Sourceflles: Name
of source file/s to be compiled
Classes: One or more classes to be processed for annotations
(such as MyPackage.MyClass)
@argfles: One or more files t lists options and source files. The-J options are not
allowed in these files.
DR
The javap command displays information about the fields,constructors and methods present in a
class file.
Syntax:
Javap [options ] classes
Where,
optdons: Command-line options.
ations
path, by its file
be found in the class name.
nan
class that can
class javap_demo
args[)
public static void main (String
System.out.println("hello java");
Output:
Compiled from ".java"
class Simple
Simple();
public static void main (java.lang.String[]);
Option Description
MS Publications
O Simple Solutions
introduction to Java 1-9
Ans
For Example
class javap_demo
System.out.println("hello java");
Javap -c javap_demo
Output:
Comp1led from ".java"
class javap_demo
Simple()
Code
e: aload_0
1: 1nvokespecial #1 I/ Method java/lang/0bject. "<init>": OV
4 return
public static void main (java. lang. String[);
Code
: getstatic #2 1/ Field java/lang/System. out: Ljava/io/PrintStream;
3: ldc II String hello java
5: invokevirtual #4 // Method java/io/PrintStream.println: (Ljav
a/lang/String; )V 8: return
Ans:
Machine.
debugging local or remote Java Virtual
of a
SYNTAX
OR
[Apr 2015, 1 Mark]
is the purpose ofjavadoc tool?
Q13. What
OR
tags. [Apr 2011, 2 Marks)
tool ? List any two Javadoc
Q14. What is the purpose of the javadoc
Ans:
Ans:
@exception classname
@exceptiont describes an exception that may be thrown from
this method
description
@throws @throws classname description
p a r a m parameter-name
Sumpie Solvtios
MS Publications
1-Introduction to Java 1-11
Ans:
Iva Javaw
Java application is associated with a console java application is not associated with a console.
to display outputs/erTors.
java.exe you will get a command prompt With javaw.exe there is no command prompt
window. windows associated.
Q19. Name the Java utility that helps a programmer find and fix bugs in java language programs.
Give its syntax. [Apr 2016,1 Mark]
Ans: jdb is the utility program that helps a programmer to find and fix bugs in java program.
MS Publications
Simple Solutions