* Question Paper- 02.
Q 4. Answer any Eight:
a) What is a java program structure?
> To wate a Sava program, we first define dasses_ Pd then
put them together
[pamumentation Section | <2--- Suggested |
Package Statement. <----- Optional
Pare | Import Statements | g----- Optronal |
| aberfince Statements | <----- Optional _
7 | class Definitions <---= Ophonal
| Main method class <---- Essential
—b) Deine this keyword a a
_—>_The “this! is_used inside the method or_construchr-te refer tts
___own object ie. this_is always a reference -te-the object of
the _carrect class’ -type-
“ed Explain in detail the data types in java Q—
— The data types of java areas allows:
3) Primvbive types
G) byte —L) Float.
(i) Short. (viJ_ double.
(ii) int (iJ boolean
list long Luin) chav:
2) Reference Data Types.
+ Referonce data -lypes are made by-the logical grouping of
Ihe logical grouping ©
primitive data ‘lypes Ce ne
* Arrays, classes, enum eke. are Lhe example of reference
data ypeWhat is an Interface Q
| An interface in Java_is a blueprint of
‘static constants and abstract_metheds— only: erface- A
A class can implements mere dhan_one_inter ws ie
| Apter face is nok a class but a set of requirements Ir
the class
a class: Tt hae
(What is the use of Reader a
+) Input stream is cimilar to. rea
Istream_1s_ similar -ty vrrter classes
Ieecies mere gee to read the characters fiom thefile
[Mavitee which can be_used to usr the coolants “te-the le
(© Whi method ig used te specify containers layout wrth syrte, |
7) Flowlayoat Manager te method is used ty spect fy containers
layouk:
| Syntac:- Container container > new Container
|| container. settayout Crew Plowlayout UJ:
nd llriter class 2
der. classes and output
which are designed br
(9) What_is the default layout for frame and Panel 9
—> +The default layout managers for IFrame Cequivalent te Framed
| and Pane) Cequivalent t» Panel) are: 7“
+f TFrame: The default layout manager for a TPrame is
4 Border Layout. — be piety
+ TPanel: The default layout _managet_ “fora TPanel is Flow Lays
(J. Explain Modifiers and Access Contrals. used io java.
+) Modifiers are keqwords tbat Modify the behaviaur_of classes,
_methods and variables:
+ Access Modifiers: Public, prvake, protected and default
i Access Controls determine the aceassibility of classes,
imethods .and variables
contyals :. Public. Access... Private Access,
and default Acess
Access Protected fice
exceptions
ava Uibsanes sdhich exploins
(i) Ust_and explain any 2 ine butt
Jions are_available ind
\lariow built-in exce 3
Array SadexOut oF Bound Pracp on,
Null Pointer Exceptinn. the
~—_ These_eacep’
the error. situation
exception, Pilenlotfound Exception,
. “ ClasstlotfoundException, ToExceptien.
pions are Artthr
ae 9 ek Content Pane () :
zy Explain the purpose
__— > The _getContentPane U_is method of the TErame. and
__ classes Ets maxy- _purpese_isto “Return the contents
__ of the finme_or dialog? The content pane 1s the area here
_add_compenents, suchas, buttons, labels. tert fields. and cther
ayraphical user interface (G05) _ rae
9
ane
Q.2. Attempt any POUR:- a
a) Explain in detail the features of Tava.
tc _ Following are the list of features of Java:
1) Simple» Tava is. a.simple language: There. aie various Conepts
Hat make. the Java asa simple language
2) Secures Tava is aimed tv be. used in networked oF
eee environments Java does not allocate direct pointer
AD. MENON].
4) Portatle +” » 1s port }
ey me mraoalts JA was an. important. goal of !
nies L be portable. so-\bat as new architectures Cdue to {
a operating. ayslem, or both) are developed « the. Jiawa
j a could be .perted tp then
4 ss . wi T°. -
ae Onented: Toa is.on Aruely object-oriented langurge:
cot java is an object: Java has a wide variety of classes aa _ uct 7 rt ° be cause it. pr
a robust Langlais 2 ee Sava. dove
v |
many Safequards th ensure. rel in
not allow pointer which avoids secunty oe a
e). Mulkthreaded «Java wae designed me toe tl
wodd requirement of Creating interactives ne ,
| : roultrthreaded programming,
pro grars -that do many things
i pregrams- Tava supports
which allows you to wate
Simultaneous! y- a er
a 3) Ah tere-tlearal AL central issue Pir_the Tava designe
| was that of code lenge ty and portability. One ofthe
“resin s_cthat_ne_guraniee _
_reain problems faang programmers E_Ne-
‘exists! thab if you write a preqram-ctoday, tt call nun 4
_teommarnw. een _on the Same machine —________-
_4)_ nterpreted.- Taya enables she creation of Cress platfirm
1 programe by compiling. infe.ao iotermediate Tepresentaben
* Eeatted Tava bytecode. ie ie
Fa) High Performance = The java bytecode was carefully designed
__[go-that it would be easy +t» translate directly vot mitre
machine code for vert high performance by Using a just
i dime compiler
19), Distributed - Tava factlities the building of Aistubuted applica
_ bya. collection of classe for use in networked application
Tava is designed for -the th diskibuled environment of the
. Eorernet: :
v) | Dynamics Tava language \s capable of dynamically link in
in new class libranes, methods and objecks Java is imberpreted,
4 Java 1s an extremely dynamic \angquages at runtime.
() What. are the rales ‘for_ method Overloading and methed
overriding 2. Explain it with example.
I =.
4Method Overriding Method Overloading -
~a)| To method overriding. the signaliie Tn method. overloading, we have
of overriding _pethed_rnust be Same_jmore Ahan one-fnclions. with the
‘las overridden method: Fn other words, Jsame Same but orth defferent
/ iYhe_ number of orguments their _|sets of argument Ly pes in
jypes.and the onley_rust be Same different order
\.n__both- overtiding_and overridden 4 ix
6 Wels be
The return type of. overloaded
functions may be same or different:
[he return type of both overriding
and_overtid den enethed must beSame
_3) [Th is an example of run-time Bt ig.an_exampe of comple= Lime
| polymorphism po paly mor phism: drat ©
4) [You cannot make overriding ‘method Overloaded funchons.can have
less_ public. than -lhe overridden metal | drferent actess modifies:
(J piteane betseen interface qad_ahsleact clas.
Seed Interface Abstract _class-
J 3k supports _mulbple Toberrtance: {Sn this multiple inherttane ts.net
Supported
3) [Only static_and Final voriables — Finel, non-final, static & non-state
at used variables can be used
mplementation of abstract |Tmplementation of interface 1s
eee . De ae -
Class members ke private
ee By default members.7¢ public
as can
: ere a Keyword is Used to }" extends"! keyword ig used 0
r extend an ahstine close
|except) an. haodliy
|
| Explain the concept of exception an
Exception: An “exception isan ee dicrupts De parm
Flow of a program's execution: It is usually cause ri
__|.an_errar suchas ing to divide by zero» accessing-a- le
that doesn't exist. or other unexpected _ cond tions ~~
[Enceplion Hardling = Exceptien- bandhing- references
of respending to. exceptions. ip_a_controlled ae ae
of allowing the programs. crash or bebave sopredictably,
| Non handling Jets devel ers_wrvle code to handle errats
_ exception handling Ie velop aches
provides. by the programming. language Su
Baal black : - =
e) What are the drfferent types of streams 9 Expla
Topust streams = purpesete read_data fro a Source ____
Details: These streams are _used +to_read_data From_various
__}oput sources such a files, keyboarck. and network Cnne:
‘Output sbreams « purpsse te wie data too destination.
= __Such_as_-files, display er_network connections. Bt
3) | Byte streams: purpese- to handle tow binary data:
| Details» These Streams. operate. row byte and are_used fir
i reading and twirling binary. data. _
4), character Streams purpose to handle text deta
| Details « character stream. work worth characters. rather “than bits
i making them more Suitable -fr reading and writing text
== sit data in_vattous._characler_ encoding.
5). Buffered Streams = purpose~ 0 | rena.n.cépiiy, fetuct
| Ss purpese- Lo Improve perfor e_by te
the pumber_of I/O opesators pe ee
| write data_in_larger chunks which reduce the number of
i
Thi Jcally involves using Speci ;
gracefully This typically tpv 4 Pe Cg edch onl
“| Details: These streams are used +> write data te destinatisns L i
ctals: Buffered Streams use an ‘inbshndl buPforsto read ‘nd S
clinteractsens. wrth. “the underlying data seurce oF devhinadian
@.3(a) Inte a java program tv dis play alternate character fion a
Java. pe play
given String: :
class. Albe1nate characlers i e
Public static ueid main Cshing args al?
‘ ~ Sting. input= “abe defghiyk
z _ printAernate Characters Goputd:
—
__—_} a lt |
a public _static_voi psinkAlhernate Charnes. (Shing args Je
ik Cstre = Null J str_is Empty UJ f an
rintla (The Input string is empty of Now);
Ent
Jon
For Cok leo, icstr length Os.
ie z System. out proto C str. char AL
_ System. out: pantln
(b) Write Jaya pragram te calculate area of Circle, Triangle &
. Rectangle. Cuse method ovelpadine ‘
TY public. dasa. Areacalculadoe .
public double calewatoy Nea. Celoubte dius t
tedurn Math PI radius * yadiva’, ¥
fablic double CalcalatorAtea (double 7c heights
= boolean’. Iangle t
4 Cictriomle ) t
; return, 0:5 baset heights
spublie=¢ brow naw Sllegal rqunant Bmplion (Inuit. paramebersster triangle aret: caloulation:’d:
3
ublic stobte_vold maa (string args 1) i
Arse CalcalatorRadtus= 5=8; tls
AreaCaleulator Calcalator = net: freaCalealedoe °°
doable cirtuleRadius = 8:0, leRad |
double ciraletrea = calcalator: calealaborhrse Core _ wus),
System-out printla( “Area of cirde: “+ circ efrea.*
| double rectanglelenglh. > 4°.
double rectangle! dth= 6-0: z
nets are Calealator colewlate Area (rectangle
a length, reclangle width), = |
S jotem-oxt: priate (” Prea_of he redangle:# reckanglees
doable trangleBase= 3 0; =
double triangle Height = 4:0, ti
double Was nica: calculator, calculator Criang!eBass
a = LlangleHeight: tue);
_|Systero-out printle (* prea_of the triangle vt Lriangl eftrea):
ae
(Write a java program display ASCEE values of the charatts
from a File. 2
=? {import java: lo BufferedReader,
import Java-lo- FileReader;
‘\mpert je io. LOExceplion.,
ublic class Asclivaluesfiun file
I public stalic veld main (sting args ost
| string Flepath = “\nput-tert";
a Any ( Baflered Reader bre new Buffered Reader Ciao AleRades
a (Blepatbh))% e
i 4 int ch;while (€chs brread OS 420 z
ystem. out: print (" characles.:"+Cchor) cha” ASCTF yalae
x :
F catch (TOEKeptio e) f :
System: out println (" pp_errorccurd while Tedding -the fle
+t _e. getislessages QO):
(a) Witte _java_program to display moultiplication of 4 given num
\nto the list box by clicking on buttr,.
E Amport java Bwing-*; ee
import java. “3____
_Amport java. aust - event. Action Event; —
Lm port java awk event: ActionListener; ;
__-publiic_class_multiplication TableApp extends Frame ¢
“private Test Field_nu mber-Held:,
a pavate —TButwn_displayBu-tton; —
vate Tlist_< String> tablelist;
_ public MultiplicalionTable App Qt
_ sefTille ("Multi plicationtablerpp"S:
a we Q Prame- EX1T-oN-CLOSE J) ;
300,400);
setSize
TPanel_ panel = new j pane (J;
panel. setLayoul Crew Grid Layout (s1)J;
number field = new: ITertfield QO;
displayButtn> new Button ("Display "ds
DefaultLisLModel
labdtlodel = new Default List. Nlodel <> 5
- tgdldict = new: jlist <> Cable mode), A
DisplayButton:add Action Listener Chew, Reionbishener Jt
e @® Override” 1c
public void action Performed.CAclionEvent ¢ Jz
Lablewlodel clear):
String pumberTopul= number field get Text Ui
t CoumberTaput-):
t ay y
\nt number: Joteger pass
2
“2 "+ result Lf
for Cink ie tics toy 1H
\nt_vesult= number * 15 -
table Model-aad Element Coumbex +,"2¢ 14
catch (number frmal Exception ox) t -
lable (lode! add Element (° Tovalid_input pleace entero
valid nombers J
a
anel-add (numborfield J: -
ane! add_ (display Button);
panel add( new-EScrlipane (table Uist);
odd Cpanel ,
ng args ds 3
1%
public. static veld main Cshis
Cun
Swing vtillies Jovokelaler
Mult plicalionTable Apps app» ew. moultiplicationTabl eApe (2s
app out Visible Clrue Js
we}
x
wwclassmate
What. is collection Q Explain. collection -Frame work in Asbailal
“The_collection_is a group of _ objects stored in_ Single unit
tohich canbe operated upen_as_ a_single entity collection
Framework prrvides a set of interfaces 4 dasses for
handling cllech ons of _ objects: tes
Tnterfaces 2
"Collections The rook interface in the csllection va herd The
main methods include add O.remove (J oo
+ Lisk: Extends collection and epee an eee collection.
of Sequence Er, Arraylist . Unkedlist
is Set = Extends collection and represents a collect: on thak
[ 7 doesn't ollow duplicale element Lx: Hashset,Treeset
. Tmplements
“+ Arraylist = Atteszable array implements of Usk. a
+ Linked list Tnglements List and Deque using a. doubly inkelist
- + Masel: Implements set using a hash table _
+ TreeseL: Tmplements sek using a red- black tree
_t HashMap = Tmplements_ Map_using a_ Bach tables | oe
_Agorethms = The collection framework includes al gorthms that
operate _on_collechon, such_as_sorti,
Key Features = © Unified Architecture.
2) Ce
- __@ 5 Performance
ae aS. searching. — :Swing ts a. Java Foundabion
classes LY
a tas :
| Swing libraries for creating
cam?
Swing components. are light-weight
and_ provide better. level and fee!
{consisten
Poundalion
ANT 1s a Java
«
AWT libraries. for creating
ical 4
Abi vebuil n pal
AIT Components. are heavy-
and_depend_.of he nadiverys #1
welght
Vow $ feel $$"
ldlrite a Java pro
femstreng or nob
| import javawtsl: Scanner;
¢ public class Armstrang Number
_ public static ald main
| System: out: println “Er
__num= scan: nertint UW:
demops pumps 2
while (temp. tro)
| tems emp fa lo;
H —yes= rest (rem® rem® tem):
R temps temp 1:10),
| ie Coume = ree
else
\ystam. out print ( "\n frmstrong Number "}
ram > check whether given oumber ts
Use Static keyword.
static int num temps mee rem’ a)
tring args CIS
| Scanner sean > MewScanner CSsysteminds
1 the number:"'J. : f
_l Siystem- out prnele (\n Net an Armstrong Number:"J;(a Dake a java_program bs copy only Non numenc data from
‘one file ts_another file. :
_Amport java.io BufferedReader; mee
__\mport java.io 3ufferedIerbers
. Amport_java- -io: File Readers
_import joven ti. ltt
Tats java io FOBxception,
ublic class _copyAlon Numberic Data
o ablic eaedla main (Shing “aigs eel 3
Cargs length |=: gts oh a, ss
ge -favacepy Numberic Date ___ =
er),
if
| System: out puntln(“y 7