KRITIK BANSAL - 1802911018 - WT - Assignment - 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

KIET Group of Institutions

Department of Information Technology


B.Tech., V SEM
Assignment -1 (2020-21) Even Semester
Web Technologies (KIT 501)

KRITIK BANSAL
18202911018
CSI

Q.
Questions Marks BL
No.
1. Differentiate between applets and Java program application. 2 BL-4

ANS APPLETS: -
1. Applets are small Java programs that are designed to be included with the HTML
web document. They require a Java-enabled web browser for execution.
2. Applet does not require a main function for its execution.
3. Applets don’t have local disk and network access.
4. Applets can only access the browser specific services. They don’t have access to
the local system.
5. Applets cannot execute programs from the local machine.
6. An applet program is needed to perform small tasks or the part of it.

JAVA APPLICATION PROGRAM: -


1. Applications are just like a Java programs that can be execute independently
without using the web browser.
2. Application program requires a main function for its execution.
3. Java application programs have the full access to the local file system and
network.
4. Applications can access all kinds of resources available on the system.
5. Applications can execute the programs from the local system.
6. An application program is needed to perform some task directly for the user.

2. Justify the statement, “Java is a platform Independent Language”. 2 BL-3

ANS When the Java program runs in a particular machine it is sent to java compiler,
which converts this code into intermediate code called bytecode. This bytecode is
sent to Java virtual machine (JVM) which resides in the RAM of any operating
system. Hence java is called platform independent language.

3. Write the java program to find addition of two numbers given from the 5 BL-4
keyboard. Using exception handling, display appropriate message if the input are
not valid numbers.
ANS package javaapplication3;
import java.util.InputMismatchException;
import java.util.Scanner;

public class JavaApplication3 {


public static void main(String[] args){
Scanner sc = new Scanner(System.in);
try{
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println("Sum = "+ (a+b));
}catch(InputMismatchException e){
System.out.println("Invalid Input It must be an integer");
}
}
}

4. Discuss the various categories of Packages. What is the importance of Packages? 5 BL-3
Also, show how packages are created and imported in Java.

A java package is a group of similar types of classes, interfaces and sub-


ANS packages.

Package in java can be categorized in two form, built-in package and user-
defined package.

There are many built-in packages such as java, lang, awt, javax, swing, net, io,
util, sql, rmi, nio, applet, text, security, time, math, net, beans, etc.

The Importance of Packages are :-

1) Java package is used to categorize the classes and interfaces so that they
can be easily maintained.

2) Java package provides access protection.

3) Java package removes naming collision.

The package keyword is used to create a package in java.

1. //save as Simple.java
2. package mypack;
3. public class Simple{
4. public static void main(String args[]){
5. System.out.println("Welcome to package");
6. }
7. }
You need to use fully qualified name e.g. mypack.Simple etc to run the
class.

To Compile: javac -d . Simple.java

To Run: java mypack.Simple


5. Discuss the importance of applet in java and discuss its life cycle. Discuss the two 10 BL-5
standard ways to run applet using example.

Applet is a special type of program that is embedded in the webpage to


ANS generate the dynamic content. It runs inside the browser and works at client
side.

The Importance of applet are as follows:

1. It works at client side so less response time.


2. Secured
3. It can be executed by browsers running under many platforms,
including Linux, Windows, Mac Os etc.

Lifecycle of Java Applets: -

1. Applet is initialized.

2. Applet is started.

3. Applet is painted.

4. Applet is stopped.

5. Applet is destroyed.

There are two standard ways in which you can run an applet:-
1.
2. 1. Executing the applet within a Java-compatible web browser.
3. 2. Using an applet viewer, such as the standard tool, applet-viewer.
An applet viewer executes your applet in a window. This is generally the fastest
and easiest way to test your applet.
4.

You might also like