0% found this document useful (0 votes)
21 views

Test 3 Java 2023

Noyes of java programming and interfacing for it

Uploaded by

abhihm79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Test 3 Java 2023

Noyes of java programming and interfacing for it

Uploaded by

abhihm79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

USN 1 R N

RN SHETTY TRUST®
RNS INSTITUTE OF TECHNOLOGY
Affiliated to VTU, Recognized by GOK, Approved by AICTE, New Delhi
(NAAC ‘A+ Grade’ Accredited, NBA Accredited (UG - CSE, ECE, ISE, EIE and EEE))
Channasandra, Dr. Vishnuvardhan Road, Bengaluru – 560 098
Department of Electronics & Instrumentation Engineering

SEM: VI SEMESTER Date: 03/07/2023


SUB: Java Programming Time: 1.5 Hrs
SUB CODE: 18EI63 Max. Marks: 50
THIRD INTERNAL TEST (2022-23 academic year)
Answer FIVE FULL Questions Choosing at least ONE from Each Part
PART 1
Q.no Marks *L CO
1a What is a package? Differentiate Java API & user defined packages 4 L3 1
1b Explain with an example, the procedure to create a package and access a package. 6 L2 1
OR
2a List and explain the different Java API Packages (at least 4 in detail). 4 L2 1
2b Explain with an example how a class can be added to a package. 6 L2 1

PART 2
3a What is a thread? 2 L1 3
3b Illustrate a single-threaded program and a multi-threaded program with figures. 4 L2 3
3c Explain the creation of a new thread with example. 4 L2 3
OR
4 Describe the complete life cycle of a thread. 10 L2 3

PART 3
5a Write a Java program illustrating the use of the Thread Methods - yield, stop & sleep. 6 L2 3
5b How are threads synchronized? 4 L2 3
OR
6a Discuss how thread exceptions are handled. 3 L2 3
6b How do we set priorities for threads? 3 L2 3
6c Explain how threads are created by implementing the ‘runnable interface’. 4 L2 3
PART 4
7a Define an applet. How do applets differ from application programs? 3 L2 4
7b What are the steps involved in developing and testing an applet in Java environment? 4 L2 4
7c Sketch the transition diagram of the lifecycle of an applet. 3 L1 4
OR
Describe how an applet displays numerical values and gets input from the user. Use a suitable
8 10 L4 5
Java code.
PART 5
9a Briefly describe three major sections involved in designing a webpage. 4 L2 5
9b Describe the applet tag features / attributes 3 L1 5
9c Explain a few important HTML Tags and their functions 3 L1 5
OR
10a Provide the syntax/general format of the applet code with an example (say HelloJava applet). 4 L2 4
10b Explain the designing of a web page using applets. 6 L2 5
*L – Bloom’s Cognitive Level - BCL: L1 – Remember, L2 –Understand, L3 - Apply, L4 – Analyze, L5 – Evaluate, L6 – Create
CO - Course Outcomes: After studying this course, students will be able to:
CO1: Explain the object-oriented concepts and JAVA. CO2: Develop computer programs to solve real world problems in Java.
CO3: Develop multithreaded applications with synchronization. CO4: Develop applets for web applications.
CO5: Design GUI based applications.
Test 3 Syllabus Mapping of Java Programming – 18EI63 ; VI EI ; Faculty: Dr. Andhe Pallavi
Syllabus (Test Question Number)
Module -4 – Q 1a.b 2a, b
Packages: JAVA API Packages (1a), Using System packages, (1b) Naming conventions, Creating, Accessing
(1b) and Using a package, Adding a class to a Package (2b), Hiding Classes.
Module -4 Q 3 , 4, 5, 6
Multithreaded Programming : (3a, 3b) Creating and Extending Thread Class (3c), Stopping, Blocking and
Life Cycle of Thread (4), Using Thread Methods (5a), Thread Exceptions and Priority (6a, 6b),
Synchronization (5b), Implementing runnable Interface (6c).
Module -5 Questions 7 - 10
Applet Programming: Introduction (7a), How Applets Differ from Applications (7b), Preparing to write
Applets, Building Applet Code (7b), Applet Life Cycle (7c), Creating an Executable Applet (10a), Designing
a Web Page (9a), Applet Tag (9b), Adding Applet to HTML File (10b), Running the Applet, Passing
Parameters to Applets, Aligning the Display, More about HTML Tags (9c), Displaying Numerical Values (8),
Getting Input from the User (8), Event Handling.

‘Test 3 Answer Scheme’ of Java Programming – 18EI63; VI EI ; Faculty: Dr. Andhe Pallavi

1a What is a package? Differentiate Java API & user defined packages 4


Packages are Java's way of grouping a variety of classes and/or interfaces together. The grouping is usually done according to
functionality. In fact, packages act as “containers” for classes.
Java API : sets of classes for the internal representation of our program's data, and
user defined packages : sets of classes for external representation purposes, build our own classes for handling our data and use
existing class libraries for designing user interfaces.
1b Explain with an example, the procedure to create a package and access a package. 6
Creating a package:
1: Declare the package at the beginning of a file using the form: package packagename
2. Define the class that is to be put in the package and, declare it public.
3. Create a subdirectory under the directory where the main source files are stored.
4. Store the listing as the classname.java file in the subdirectory created.
5. Compile the file. This creates .class file in the subdirectory.
Accessing a Package
A Java system package can be accessed by 2 methods.
i) using a fully qualified class name: This is done by using the package name containing the class and then appending the class
name to it using the dot operator.
“java.awt.Color” refers to the class Color in the awt package.
ii)using the import statement.
import packagename.classname; example of importing a particular class.
‘OR” import packagename.*; imports every class contained in the specified package.
2a List and explain the different Java API Packages (at least 4 in detail). 4
Package Name Contents
java.lang Language support classes. These are classes that Java compiler itself uses and therefore they are automatically
imported. They include classes for primitive types, strings, math functions, threads and exceptions
java.util Language utility classes such as vectors, hash tables, random numbers, date etc.
java.io Input/ Output support classes. They provide facilities for the input and output of data.
java.awt Set of classes for implementing graphical user interface. They include classes for
Windows, buttons, lists, menus and so on.
java.net Classes for networking. They include classes for communicating with local computers as well as with
internet servers.
java.applet Classes for creating and implementing applets.

2b Explain with an example how a class can be added to a package. 6


Consider a package p1 containing a public class by name A. To add another class B to this package, the following can be done:
1. Define the class and make it public.
2. Place the package statement package p1; before the class definition as follows:
package p1
public class B
{ //body of B }
3. Store this as B.java file under the directory p1.
4. Compile B.java file. This will create a B.class file and places it in the directory p1.
3a What is a thread? 2
A thread is a subprogram (similar to a program) which has a single flow of control. It has a beginning, a body and an end ; and
executes commands sequentially.
3b Illustrate a single-threaded program and a multi-threaded program with figures. 4

3c Explain the creation of a new thread with example. 4

4 Describe the complete life cycle of a thread. 10

5a Write a Java program illustrating the use of the Thread Methods - yield, stop & sleep. 6
5b How are threads synchronized? 4
It is done by using the keyword ‘synchronized’ with the method or block of code. Java creates a ‘monitor’ and hands it over to
the first thread accessing the ‘synchronized’ method. As long as this thread has the key, the other threads cannot access this
method.
6a Discuss how thread exceptions are handled. 3
Using ‘try-catch’ block when the thread is in ‘blocked” state due to sleep, suspend, wait. Else Java run system will throw
‘IllegalThreadStateException’ as the exception can not be handled by the thread.
6b How do we set priorities for threads? 3
Using the setPriority() method. ThreadName. setPriority(intNumber)
intNumber is a constant between 1 & 10. ‘Thread’ class defines the priority constants as:
MIN_PRIORITY = 1 ; MAX_PRIORITY = 10 ; NORM_PRIORITY = 5
6c Explain how threads are created by implementing the ‘runnable interface’. 4

7a Define an applet. How do applets differ from application programs? 3


Applets are small Java programs that are primarily used in Internet computing. It can perform arithmetic
operations, display graphics, play sounds, accept user input, create animation, and play interactive games.
Although both the applets and stand-alone applications are Java programs, Applets are not full-featured
application programs. They are usually written to accomplish a small task or a component of a task. Since they are
usually designed for use on the Internet, they impose certain limitations and restrictions in their design.
7b What are the steps involved in developing and testing 7c Sketch the transition diagram of the
an applet in Java environment? 4 lifecycle of an applet. 3
Before we try to write applets, we must make sure that Java is
installed properly and also ensure that either the Java
appletviewer or a Java-enabled browser is available steps
involved in developing and testing in applet. They are:
1. Building an applet code (java file)
2. Creating an executable applet (.class file)
3. Designing a Web page using HTML tags
4. Preparing <APPLET> tag
5. Incorporating <APPLET> tag into the Web page
6. Creating HTML file
7. Testing the applet code
8.Describe how an applet displays numerical values and gets input from the user. Use a suitable Java code. 10
an applet displaying numerical values

gets input from the user

9a Briefly describe three major sections involved in designing a webpage. 4


Comment, Head & Body sections – explain
9b Describe the applet tag features / attributes 3
Attributes of Applet Tag Meaning
Specifies the name of the applet class to be loaded. That is, the name of the already
CODE = AppletFileName.class compiled class file in which the executable Java bytecode for the applet is stored. This
attribute must be specified.
CODEBASE = codebase_URL Specifies the URL of the directory in which the applet resides. If the applet resides in the
(Optional) same directory as the HTML file, then the CODEBASE attribute may be omitted entirely.
WIDTH = pixels These attributes specify the width and height of the space on the HTML page that will
HEIGHT = pixels be reserved for the applet.
NAME = applet_instance_ name A name for the applet may optionally be specified so that other applets on the page may
(Optional) refer to this applet.
This facilitates inter-applet communication. This optional attribute specifies where on
ALIGN= alignment
the page the applet will appear. Possible values for alignment are: TOP, BOTTOM,
(Optional)
LEFT, RIGHT, MIDDLE, ABSMIDDLE, ABSBOTTOM, TEXTTOP, and BASELINE
Used only when ALIGN is set to LEFT or RIGHT, this attribute specifies the amount of
HSPACE=pixels (Optional)
horizontal blank space the browser should leave surrounding the applet.
Used only when some vertical alignment is specified with the ALIGN attribute (TOP
VSPACE=pixels (Optional) BOTTOM, etc.) VSPACE specifies the amount of vertical blank space the browser
should leave surrounding the applet.
Non-Java browsers will display this text where the applet would normally go. This
ALT=alternate_text (Optional) attribute is optional.
9c Explain a few important HTML Tags and their functions. 3
HTML Tags Function
<HTML> … </HTML> Signifies the beginning and end of a HTML file.
<HEAD> … </HEAD> This tag may include details about the Web page. Usually contains <TITLE> tag within it.

<TITLE> … </TITLE> The text contained in it will appear in the title bar of the browser.
This tag contains the main text of the Web page. It is the place where the <APPLET> tag is
<BODY> … </BODY>
declared.
<H1> … </H1> Header tags. Used to display headings. <H1> creates the largest font header, while <H6>
<H6> … </H6> creates the smallest one.
<CENTER> … </CENTER> Places the text contained in it at the center of the page.
<APPLET …> <APPLET...> tag declares the applet details as its attributes.
<APPLET> … </APPLET> May hold optionally user-defined parameters using <PARAM> Tags.
Supplies user-defined parameters. The <PARAM> tag needs to be placed between the
<PARAM …> <APPLET> and </APPLET> tags. We can use as many different <PARAM> tags as we
wish for each applet.
<B> … <B> Text between these tags will be displayed in bold type.
<BR> Line break tag. This will skip a line. Does not have an end tag.
Para tag. This tag moves us to the next line and starts a paragraph of text. No end tag is
<P>
necessary.
<IMG …> This tag declares attributes of an image to be displayed.
<HR> Draws a horizontal rule.
<A…> </A> Anchor tag used to add hyperlinks.
We can change the color and size of the text that lies in between <FONT> and </FONT>
<FONT…> … </FONT>
tags using COLOR and SIZE attributes in thetag<FONT...>.
Any text starting with a < ! mark and ending with a > mark is ignored by the Web browser.
<! ….>
We may add comments here. A comment tag may be placed anywhere in a Web page.
10a Provide the syntax/general format of the applet code with an example (say HelloJava applet). 4

10b Explain the designing of a web page using applets. 6


Step 1: Create an executable applet – say HelloJava.class and store in the same directory where the source code
of the applet (say HelloJava.java file) is present.
Step 2: In the same directory create a HTML file (HelloJava.html) to which the applet is to be added.
Step 3: The HTML file has 3 sections – Comment, Head and Body. These sections are created with the appropriate
html tags (opening and closing tags).
Step 4: In the body section add the applet using the applet tag and a few attributes such as CODE = name of the
applet (HelloJava.class); WIDTH ; HEIGHT of the applet space in pixels (say WIDTH = 400 & HEIGHT = 200)
Step 5: Run the .html file using the appletviewer or Java enabled browser to view the output.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy