Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

An Introduction to Java

An Introduction to Java

Uploaded by

akshadadevkar8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

An Introduction to Java

An Introduction to Java

Uploaded by

akshadadevkar8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1

An Introduction to Java

1. A Short History of Java

is an old name of Java?


Q1. What
Ans: Earlier java was known as Oak.

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

Q3. Explain any two features of Java. [Oct 2010,2 Marks]


OR
of Java in detall.
04. Explain features Apr 2016,5 Marks]
DR

Q5. Discuss any four java features. Apr 2015,4 Mark]


Ans.
1) Simple
Java is a simple programming language because syntax is based on Ct+
Many confusing features like poínters, operator overloading, multiple inheritance etc are removed.
I t contains no goto statements.

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

Java is called purely object oriented programming language.

Everything in java (program code and data) is associated with class.

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

Java is not fully object oriented language.


F o r any language to be object oriented everything should be considered as objects, but java u
uses
primitive data types.
I t doesn't support multiple inheritances fully

3) Platform Independent
09) Explain how Java language is platform independent List any four features of Java.

[oct 2015, Marks


Ans:

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

Architecture-Neutral means that Java program does not depend


of the machine upon the specific architecture
on which the run.

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

I t does not have explicit pointers.

.Ithas Access specifiers like private, protected etc.


.Java programs atter compilation are converted into class file which contains bytecode which is not
readable.

7) High performance ,

It have high performance because of following reasons..

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

Java has Automatic Garbage Collectlon which prevents memory leaks.

There are lack of pointers that avoids security problem.

I t also has Exception Handling to handle runtime erors and type checking mechanism.

A l l the above points make java Robust.

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

10) complled and Interpreted language.


Q11) Why Java needs compller and interpreter? [1 Mark)
OR
Q12) What are roles of compller and interpreter? 1 Mark]
Ans:
Java compiler compiles java source code and converts it into bytecode which is an executable code for

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-

Hence. java is compiled and interpreted language.


11)Distributed
ava uses internet protocols like TCP/IP,UDP and HTP for network access.
a v a programs be
can distributed and accessed over the network.
Remote methods can be invoked by RMI and Socket
programiming
1.3
Comparison of Java and C+

Q1. Give the difference between C++ and Java.


Ans:

r
No. Java C++

Java does not


support pointers etc. C++ supports pointers and pointer arithmetic.
2
Java support automatic garbage collection.| C++ Support destructors, which is
It does not
support destructors as C++ automatically invoked when the object is
does.
destroyed.
Java doesn't provide multiple inheritance C++ does support multiple inheritance.
Java is
platform independent language. C++ is
depends upon operating system
Java is both compiled and interpreted. C++ is only
compilled.
There is no goto statement in Java.
*nas goto statement
Java supports multi threading C++ doesnt
8
support muli threading
Java doesnt support operator overloadingC++Supports operator
9 Java doesn't support templates, unions,
overloading
C** Supports templates, unions,, structures
structures
10 Java doesn't provide header files C++ has header files
11 Bound checking is done on arrays No bound checking on
12 All methods are part of class arrays
Can have methods without class
13
main method can not return a value main method can return a value
14 Supports Documentation comments
with single line and multiline
alongOnly two types of comments
Single line and
comments
15 No typedef Multiline
Supports typedef
16
Doesn't support enums Supporisenums
1.4 Java Environment

Q-A
Q1. What is bytecode?7
[1 Mark)

MS Publications
O Simple Solutons
1- Introduction to Java 1-5

Ans: Bytecode is a code generated after compilation of Java program.

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.

Bytecode is VM dependent not platform dependent.


VM will execute this bytecode and will generate code to run on specific operating system.
S o , even if the operating system is changed no need to change bytecode.

Q4. Justify True/False


When any Java program is complled, the compller generates executable code?

Apr 2016, 1 Mark]

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.

Q5. What is VM? [1 Mark]


OR
Q6.JVM is platform dependent.State True/False. [Ans: True 1 Mark
OR
[Apr 2014, 1 Mark]
Q7. What is the role of]VM7
OR

Q8.1VM Is platform Independent State true/false. Justify. [Ans: False


[Oct2015,1 Mark]
Ans:
V M ie. Java Virtual Machine is an abstract computing machine that provides runtime environment in

which bytecodes can be executed.


I t i s platform dependent though Java language is platform Independent
Each platform has its own JVM in which bytecodes can be executed

MS Publications O Simple Solutions


I-6 Programming in Java

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

nested classes (but not anonymous inner


describing (by default) the publíc and protected classes,
API documentation from Java source
classes), interfaces, constructors, methods, and fields to create
files.
6) Java Debugger: The Java Debugger, jdb is the utlity program that helps a programmer to find and ix
bugs in java program.

7) Java Applet Viewer: This is used to view the Java applets.

1.6 Java Tools-jdb, javap, javadoc

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

Javadoc API documentation generator.

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.

Q4. Give syntax of Javap command. (1Mark] or [5 Mark]

DR

Q5. What is the use of javap command.


R

Q6. State the use of javap tool. [Oct 2011,1 Mark]


Ans:

The javap command disassembles one or more class files.

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.

MS Publications O Simple Solutions


1-8 Pogramming in Java
prOcessed for annotatins
Classes: List of one or
more classes (separated by spacesj
t o De

ations
path, by its file
be found in the class name.
nan
class that can

(such as DocFooter.class). You may specify a

Explain with example use of Javap Command in Java. 1 Mark)


7.
ns

class javap_demo

args[)
public static void main (String

System.out.println("hello java");

Give the command on terminal as


Input:
javap javap_demo

Output:
Compiled from ".java"
class Simple

Simple();
public static void main (java.lang.String[]);

Q8. State any two optlons of Javap tool. [1 Mark)


Ans
The important options of javap tool are as follows.

Option Description

-help prints the help message.

prints line number and local variable

disassembles the code

prints internal type signature

sysinfo|shows system info (path, size, date, MD5 hash)

-constantsshows static tinal constants


-version shows version information
Q9. Explaln Javap c command with
example.

MS Publications
O Simple Solutions
introduction to Java 1-9

Ans

The Javap * command to see disassembled code


T h e code that reflects
the java bytecode
.Synta

avap class name

For Example
class javap_demo

publit static void main(String args[])

System.out.println("hello java");

Input: Gve the command on terminal as

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

Q10. Glve syntax of Jdb command. (1 Mark or 5 Marks]


OR

Q11. What is the use of Jdb command.

Ans:

MS Publications Simple Solutions


1-10 Programming in Java-i

bugs in Java programs.


is the Java Debugger helps to find and fix
ab
classes.
The. Jdb, is a simple command-line debugger for Java
demonstration of the Java Platform
Debugger
Architecture att
tha
provides inspection
provides inspecti
and
It is a

Machine.
debugging local or remote Java Virtual
of a

SYNTAX

jdb options [ class)| arguments


Where,
below.
Command-line options, as specified
options :
class
Name of the class to begin debugging
of class.
passed to the mainO method
arguments: Arguments
[Apr 2012, 1
Mark]
Q12. State the use of javadoc tool

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:

T h e javadoc tool is used to create the document API


It Generates HTML pages describing (by default) the public and protected classes, nested classes (but
constructors, methods, and fields to create API
intertaces,
not anonymous inner classes),
documentation from Java source files.

Q15. Explain javadoc tags. I5 Marks)


OR
Q16. Name any four tags of Javadoc. [Apr 2016, 1 Mark]

Ans:

Tag Description Syntax


uthor Describes an author of a class @author name-text

@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

@param Describes method parameter


description
@return
|Describes the return type of a method @return descriptio

Sumpie Solvtios

MS Publications
1-Introduction to Java 1-11

see Provides a link to other element of documentation |®see reference

Describes when this functionality or a change has


@since since release
first existed specified by the release

@version Adds a version information of a software @version version-text

@deprecated Describes an outdated method.


@deprecated description
Q17. What is the use of varlable CLASSPATH?
Oct 2013,1 Mark]
Ans: CLASSPATH Is an environment variable which tells VM and other java aplications and tools to find

class libraries including user-defined class libraries.


Q18. Write difference between java and javaw tools provided by Java. [Oct 2013, 1 Mark]

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

You might also like