1st Assignment Answer
1st Assignment Answer
3. What is the name of the tool that is used for compiling a Java program?
(a) javap (b) java
(c) javah (d) javac
4. What is the name of the tool that is used for interpreting a Java program?
(a) javap (b) java
(c) javah (d) javac
5. What process automatically removes objects that are not being referenced?
(a) Multithreading (b) Object Reclamation
(c) Garbage collection (d) Object collection
6. What is the name of the tool that is used for running Applets?
(a) javap (b) javac
(c) java (d) appletviewer
Ans. Option (a) public static void main(String args[]) , (d) public static void main(String a[])
Ans. Option (a) String in switch case, (d) automatic resource management
Review Questions
Ans. Platform independent language means once compiled you can execute the program on any platform (OS).
Java is platform independent. Because the Java compiler converts the source code to bytecode, which is Intermidiate Language. Bytecode can be
executed on any platform ( OS ) using JVM( Java Virtual Machine). Every platform have their own JVM with it.
2. Explain the security model of Java that makes it more secured than other languages.
Ans. The Java security model, introduced in Java 2, is the basis of highly secured and distributed enterprise Java applications. The model is based on a
customizable "sandbox" in which Java software programs can run safely, without potential risk to systems or users. Java security technology
includes a large set of APIs, tools, and implementations of commonly used security algorithms, mechanisms, and protocols.
3. Why is Java known to be multithreading? How does it help Java in its performance?
Ans. Java is desinged to meet the real world requirement of creating interactive , networked program. To accomplish this, java supports multi-threading
programming, which alloow you to write program that do many task. Java run time system comes with an elegent yet sopheticated solution for
multipurpose synchronization that allow you construct smooth running intreacting system.
4. C++ is an object-oriented language older than Java, then why did Java replace C++ in most of the application development?
Ans. Java is a general purpose, object oriented programming language. Both C and C++ has limitations of reliability and portability whereas Java is very
simple, portable and highly reliable. The most striking feature of Java is that it is platform neutral language. It is the first programming language that
is not tied to any particular hardware or operating system. Some more feature of java which playes great role in replacing C++ are as follow-
Ans. The following are the reasons why java were used in internet-
security:
Prior to Java, most users did not download executable programs frequently, and those who did scanned them for viruses prior to execution.
When you use a Java-compatible Web browser, you can safely download Java applets without fear of viral infection or malicious intent.
Java achieves this protection by Confining a Java program to the Java execution environment and not allowing it access to other parts of
the computer.
portability:
Many types of computers and operating systems are connected to the Internet. For programs to be dynamically downloaded to all the
various types of platforms connected to the Internet. some means of generating portable executable code is needed.
Robust :
memory management mistakes and mishandled exceptional conditions.
Multithreaded:
Java supports multithreaded programming, which allows you to write programs that do many things simultaneously.
Distributed:
Java is designed for the distributed environment of the Internet.
Dynamic:
java programs carry with them substantial amounts of run-time type information that is used to verify and resolve accesses to objects at
run time.
Ans. A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages
that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation.
Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java
Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.
Ans.
public class Test // 1
{ // 2
public static void main( String args[ ] ) // 3
{ // 4
// this is the basic structure of a java program. // 5
} // 6
} // 7
1- declaration of the class “Test” is mentioned in first line. This class is a public class, as the access permittion is “public”.
2- “ { “ opening braces indicate the starting/begning of the body of class “Test”.
3- declaration of main method of “Test” class, the method is having the public access permission and is static in nature[i.e it doesn’t need a
object to get called], and its return type is void [i.e it dosen’t return anything ].
4- “ { “ opening braces indicate the starting/begning of the body of class “main”.
5- This line is not compulsory in any program. Its just a comment which is not considered to be code and the compiler ignores it during
execution of code.
6- “ } “ closing braces indicate the ending of the body of method “main”.
7- “ } “ closing braces indicate the ending of the body of class “Test”.
10. What is the importance of setting environment variables such as Path and Classpath?
Ans. When a user enters a particular command in Command Prompt[Windows] or Terminal [Unix/Linux], the Operating System [OS] searches for the
executable file of that command in the current directory [ From where user enters the command ]. If it is not there, OS checks the values stored in
PATH environment variable . These values are nothing but a list of directories with their absolute paths. OS checks for the executable files of that
particular command one by one in these directories and if it fails to find it in any of these directories, an error will be displayed.
11. Discuss the tools available in JDK. How do they help in application development?
Ans.
1. Write a program to print ‘Welcome’ followed by your name and ‘How are you?’
Program-
import java.util.Scanner;