Friday, 12 August 2011

UGC NET SOLVED COMPUTER SCIENCE - PAPER II

This section is for all those NET exam aspirants who are looking out for a solution for UGC NET computer science papers. As a person who had taken the examination i have searched the internet incessantly for the solution of paper-II and paper-III of computer science. Since i could not find any solid help(or rather no help at all) in this regard, i had decided to write my own blog posting the solution for each and every paper as and when i complete it. I have posted the solution for paper-II of December 2008(and it was quite a task). Wherever i could, i have given explanation for the answers. If it is too lengthy or too simple, i have left it out. Enjoy your preparation for the NET exam.

I just have one word of advice for all NET aspirants...

"Focus on the journey, not the destination. Joy is found not in finishing an activity but in doing it.”

DECEMBER 2008 PAPER II SOLVED



DECEMBER 2009 PAPER II SOLVED






DECEMBER 2008 PAPER II SOLVED



1. The channel capacity of a band-limited Gaussian channel is given by
(A). B log2 (2+S/N) (B) B log2 (1+S/N)
(C ).B log10(1+S/N) (D). B loge(1+S/N)
Ans : B. Explanation :- C=B log2 (1 + S/N) where C is the capacity in bits per second. B is the bandwidth of the channel in Hertz and S/N is the signal to noise ratio.


2. The graph K 3,4 has _______ edges.
(A). 3 edges (B) 4 edges
(C ). 7 edges (D) 12 edges
Ans : D. A bipartite graph is a complete bipartite graph if every vertex in U is connected to every vertex in V. If U has n elements and V has m, then the resulting complete bipartite graph can be denoted by K n,m and the number of edges is given by n*m.
The number of edges = K 3,4 = 3 * 4 = 12


3. The total number of spanning trees that can be drawn using five labeled vertices is:
(A). 125 (B).64
(C ). 36 (D). 16

Ans : A. According to cayley’s formula for counting spanning trees, for a complete graph Kn,
T(Kn)= n n-2 where n is the number of vertices.
T(k5)=5 5-2=5 3= 5 * 5 * 5=125


4. Extremely low power dissipation and low cost per gate can be achieved in
(A) MOS ICS (B) C MOS ICS
(C ) TTL ICS (D) ECL ICS
Ans : B. CMOS ICS


5. An example of a universal building block is :
(A). EX-OR Gate (B). AND Gate
(C ). OR gate (D). NOR Gate
Ans:- D. Universal gates are the ones which can be used for implementing any gate like AND,OR and NOT or any combination of these basic gates. Apart from the NOR gate, NAND gate is also considered as universal gate.


6. An example of a layer that is absent in broadcast networks is :
(A). Physical layer (B). Presentation layer
(C ). Network layer (D). application layer
Ans : C.

7. The ATM cell is :
(A). 48 bytes long (B). 53 bytes long
(C ). 64 bytes long (D). 69 bytes long
Ans: B. An ATM cell always consists of a 5-byte header followed by a 48-byte payload. So the size is 53 bytes long.

8. Four jobs J1,J2,J3, and J4 are waiting to be run. Their expected run times are 9,6,3 and 5 respectively. In order to minimize average response time, the jobs should be run in the order:
(A). J1 J2 J3 J4 (B). J4 J3 J2 J1
(C ) J3 J4 J1 J2 (D) J3 J4 J2 J1
Ans : D

9. Suppose it takes 100ns to access page table and 20 ns to access associative memory. If the average access time is 28ns, the corresponding hit rate is:
(A). 100 percent (B). 90 percent
(C ). 80 percent (D). 70 percent
Ans : B

10. Transmission of N signals , each band limited to Fm Hz by TDM, requires a minimum band-width of
(A).fm (B) 2 fm
(C ) N fm (D) 2N fm
Ans : C. Minimum transmission band-width of TDM channel is given by the following equation.
Bt=NW
Where N is the total number of channels, which are bandlimited to ‘W’ Hz. In the above problem, the number of signals are N, each band limited to Fm Hz and so the minimum band-width is N fm.


11. If a code is ‘t’ error detecting, the minimum hamming distance should be equal to :
(A). t-1 (B). t
(C ). t+1 (D). 2t+1
Ans: C. To guarantee the detection of upto s errors in all cases, the minimum hamming distance in a block code must be
dmin=s+1
So, the minimum hamming distance for a ‘t’ error detecting must be t+1


12. A relation R in {1,2,3,4,5,6} is given by {(1,2),(2,3),(3,4),(4,4),(4,5)}. The relation is :
(A) Reflexive (B). symmetric
(C ). Transitive (D). not reflexive, not symmetric and not transitive
Ans:- D.


13. The dual of the switching function x+yz is:
(A). x+yz (B). x+yz
(C ). x(y+z) (D). x(y+z)
Ans:- D

14. The characteristic equation of D-flip flop is :
(A). Q=1 (B). Q=0
(C ). Q=D (D). Q=D
Ans: D.


15. If four 4 input mulitplexers drive a 4 input multiplexer we get a :
(A). 16 input MUX (B). 8 input MUX
(C ). 4 input MUX (D). 2 input MUX
Ans:- A


16. The throughput of slotted ALOHA is given by:
(A). S=G (B). S=GeG
(C ). S=Ge-G (D). S=eG
Ans: C


17. Congestion control is done by
(A). Network layer (B). Physical layer
(C ). Presentation layer (D). Application layer
Ans:- A. Addressing, internetworking, error handling, packet sequencing are its other jobs.


18. Assertion(A): Twisted pairs are widely used as transmission medium.
Reasoning(R ): Twisted pairs have adequate performance and low cost.
(A). Both (A) and (R ) are true and (R ) is the correct explanation for (A).
(B). Both (A) and (R ) are true but (R ) is not the correct explanation
(C ). (A) is true but (R ) is false
(D). (A) is false but (R ) is true
Ans:- A. Page No .91 of Tanenbaum book, you will find the following statement. “Due to their adequate performance and low cost, twister pairs are widely used and are likely to remain so for years to come”.


19. An example of a non-adaptive routing algorithm is:
(A). Shortest path routing (B). Centralised routing
(C ). Baran’s hot potato algorithm (D). Baran’s backward learning algorithm
Ans:- A. Shortest path routing.


20. IP address in B class is given by:
(A). 125.123.123.2 (B). 191.023.21.54
(C ). 192.128.32.56 (D). 10.14.12.34
Ans:- B


21. N processes are waiting for I/O. A process spends a fraction of its time in I/O wait state. The CPU utilization is given by:
(A). 1-P –N (B). 1 – P N
(C ). P N (D). P -N
Ans:B. According to the probabilistic model, if a process spends a fraction p of its time in I/O wait state, and if there are N processes in memory, then the CPU utilization is given by 1-PN


22. If holes are half as large as processes, the fraction of memory wasted in holes is:
(A) 2 / 3 (B). 1 / 2
(C ). 1 / 3 (D). 1 / 5
Ans : D


23. An example of a non-premptive scheduling algorithm is:
(A). Round robin (B). Priority scheduling
(C ). Shortest job first (D). 2 level scheduling
Ans: C

24. An example of a distributed OS is:
(A). Amoeba (B). UNIX
(C ). MS – DOS (D). MULTICS
Ans: A

25. Which one of the following correctly describes a static variable:
(A). It cannot be initialized.
(B). It is initialized once at the commencement of execution and cannot be changed during run time.
(C ). It retains its value during the life of the program.
(D). None of the above
Ans: C

26. The output of the program code
main()
{
int x = 0;
while ( x < = 10)
for(;;)
if (++x%10==0)
break;
printf(“x=%d”,x);
}
is:
(A). x = 1 (B). compilation error
(C ). x = 20 (D) none of the above
Ans:- C. For the while statement there is a for loop inside. For the for loop, there is one if condition, based on which there is a break statement. Since the value of x initially is 0, the while condition would be true and the for loop would start executing. The if statement condition would be checked, since ++x would become 1 and 1%10 is not equal to 0, break will not be executed. Since for is infinite x value will go on increasing. Once the value of x reaches 9, ++x would become 10 and 10%10==0 and so break would be executed. So control will come out of the innermost loop and would go to the outer loop. Sinc the value of x is 10, and since it is equal to 10, once again the for loop would start its execution. Once the value of x reaches 20, 20%10 will be equal to 0 and again break will be executed and control would go to the outer for loop. When the condition is checked for x<=10,it is false as the value of x is 20 and so it comes out of the while loop and the printf statement gets executed, printing the value of 20. Whew!!!!! 27. A copy constructor is invoked when : (A). a function returns by value (B). an argument is passed by value (C ). A function returns by reference (D). none of the above Ans:- B 28. When a language has the capability to produce new data types, it is said to be : (A). extensible (B). encapsulated (C ). Overloaded (D). none of the above Ans:-A 29. How many constructors can a class have? (A) Zero (B) 1 (C ) 2 (D) any number Ans:- D 30. An entity has: (i) a set of properties (ii) a set of properties and values for all the properties (iii) a set of properties and the values for some set of properties may non-uniquely identify an entity (iv) a set of properties and the values for some set of properties may uniquely identify an entity Which of the above are valid? (A) (i) only (B) (ii) only (C ) (iii) only (D) (iv) only Ans:- D 31. Aggregation is: (A) An abstraction through which relationships are treated as lower level entities (B) An abstraction through which relationships are treated as higher level entities (C) An abstraction through which relationships are not treated at all as entities (D) None of the above Ans:- B 32. Suppose R is a relation schema and F is a set of functional dependencies on R. Further, suppose R1 and R2 forma a decomposition of R. Then the decomposition is a lossless join decomposition of R provided that : (A) R1∩R2 ->R1 is in F+
(B) R1 ∩ R2->R2 is in F+
(C) Both R1 ∩ R2->R1 and R1 ∩ R2->R3 functional dependencies are in F+
(D)At least one from R1∩R2->R1 and R1 ∩ R2->R2 is in F+
Ans:- D.


33. In a heap, every element is ________________ of all the elements in the subtree.
(A) Maximum (B) minimum
(C ) sum (D) product
Ans:- A


34. If (rear == maxsize – 1) rear=0; else rear=rear+1; is required in :
(A) circular queue (B) linear queue (C) stack (D) deque
Ans:- D

35. A high performance switching and multiplexing technology that utilizes fixed length packets to carry different types of traffic is :
(A) ATM (B) ADSL (C) SONET (D) None of the above
Ans:- A


36. A conventional LAN bridge specifies only the functions of OSI:
(A) Layers 1 and 2 (B) layers 1 through 3 (C) all layers (D) none of the above
Ans:- A.


37. An assembly program contains:
(A) Imperative and declarative statements
(B) Imperative statements and assembler directives
(C) Imperative and declarative statements as well as assembler directives
(D) Declarative statements and assembler directives
Ans:- C. Assembly program consists of three types of statements.
1. Imperative
2. Declarative
3. Assembler directives

38. In which addressing mode, the effective address of the operand is generated by adding a constant value to the contents of a register?
(A) Absolute mode (B) immediate mode (C) indirect mode (D) index mode
Ans:- D


39. Which of the following are Assembler directives?
(i) EQU (ii) ORIGIN (iii) START (iv) END
(A) (ii),(iii) and (iv) (B) (i),(iii) and (iv)
(B) (iii) and (iv) (D) (i),(ii),(iii) and (iv)
Ans:- D


40. Which of the following OS treats hardware as a file system?
(A) UNIX (B) DOS (C) Windows NT (D) none of the above
Ans:- A.

41. In which of the following, ready to execute processes must be present in RAM?
(A) Multiprocessing (B) multiprogramming (C) multitasking (D) all of the above


42. If the executing program size is greater than the existing RAM of a computer, it is still possible to execute the program if the OS supports:
(A) Multitasking (B) virtual memory (C) paging system (D) none of the above
Ans: B


43. Software Quality Assurance (SQA) encompasses:
(A) Verification (B) validation (C) both verification and validation (D) none of the above


44. Which level is called as “defined” in capability maturity model?
(A) Level 0 (B) level 3 (C) level 4 (D) level 1
Ans:- B


45. COCOMO model is used for:
(A) Product quality estimation (B). product complexity estimation
(C) product cost estimation (D) all of the above
Ans: C


46. Font sizes are usually expressed in points. One point is:
(A) 0.0069 inch (B) 0.0138 inch
(C) 0.0207 inch (D0 0.0276 inch
Ans:- B. One point is 1/72 of an inch and so we will get the answer 0.0138 inch.


47. Assertion (A): Cellular telephone systems can handle a multitude of users.
Reasoning(R ): Cellular telephone systems permit extensive frequency reuse in a small local area.
(A) Both (A) and (R ) are true and (R ) is the correct explanation for (A)
(B) Both (A) and (R ) are true but (R ) is not the correct explanation
(C) (A) is true but (R ) is false
(D) (A) is false but (R ) is true
Ans:- A.


48. E-Commerce involves:
(A)Electronic Data Interchange (B) Electronic mail
(C) Electronic Bulletin boards (D) All of the above
Ans:- D. E-commerce involves paperless transactions and usage of EDI(Electronic Data Interchange), electronic mail, bulletin boards, fax transmission and electronic fund transfers.


49. An example of a data mining algorithm which uses squared error score function is:
(A) CART algorithm (B) back propagation algorithm (C) a priori algorithm
(D) vector space algorithm
Ans:- B. Back propagation algorithm uses squared error score function. CART algorithm uses cross-validated loss function.


50. (I) Each object in the active directory of windows 2000 has an access control list.
(II) The scheme is a blueprint of all objects in the domain of windows 2000. Which of the following is true?
(A) Only (I) (B) only (II) (C) both (I) and (II) (d) none of the above
Ans:- C


DECEMBER 2009 PAPER II SOLVED



1. If she is my friend and you are her friend, then we are friends. Given this, the friend relationship in this context is ________________.
(i) Commutative (ii) transitive (iii) implicative (iv) equivalence
(A) (i) and (ii) (B) (iii) (C) (i),(ii),(iii) and (iv) (D) None of these
Ans:- D

2. Circle has ________
(A) No vertices (B) only 1 vertex (C) vertices (D) None of these
Ans :- A

8. The highest noise margin is offered by
(A) BICMOS (B) TTL (C) ECL (D) CMOS
Ans:- B

9. The answer of the operation (10111)2 * (1110)2 in hex equivalence is
(A) 150 (B) 241 (C) 142 (D) 101011110
Ans:- C

10. How many ‘1’ are present in the binary representation of
3 X 512 + 7 X 64 + 5 X 8 + 3
(A) 8 (B) 9 (C) 10 (D) 11
Ans:- B

11. Recursive functions are executed in a
(A) First in first out order (B) Last in first out order
(C ) Parallel fashion (D) Load Balancing
Ans: B

12. What would be the output of the following program, if run from the commandline as “myprog 1 2 3”?
main(int argc,char *argv[])
{
int i;
i=argv[1]+argv[2]+argv[3];
printf(“%d”,i);
}
(A) 123 (B) 6 (C) Error (D) “123”
Ans:- C

13. A ________________ is a special method used to initialize the instance variable of a class.
(A) Member function (B) Destructor (C) Constructor (D) structure
Ans:- C

14. Encapsulation is
(A) Dynamic binding
(B) A mechanism to associate the code and data
(C ) Data abstraction
(D ) Creating new class
Ans:- B

15. Which of the statements are true?
I. Function overloading is done at compile time.
II. Protected members are accessible to the member of a derived class.
III. A derived class inherits constructors and destructors
IV. A friend function can be called like a normal function.
V. Nested class is a derived class.
(A) I,II,III (B) II,III,V (C) III,IV,V (D) I,II,IV
Ans:- D

16. The E-R model is expressed in terms of
I. Entities
II. The relationship among entitites
III. The attributes of the entities.
IV. Functional relationship.
(A) I,II (B) I,II, IV (C) II,II,IV (D) I,II,IV
Ans:- D

17. Specialization is ________________process.
(A) top-down (B) bottom up
(C ) both (A) and (B) (D) none of these
Ans:- A

18. Match the following:
(1) Determinants (a) No attributes
(2) Candidate key (b) Uniquely identified a row
(3) Non-redundancy (c ) A constraint between two attributes
(4) Functional dependency (d) Group of attributes on the left hand side of arrow
of function dependency
(A) 1 – d, 2 – b, 3 – a, 4 – c
(B) 2 – d, 3 – a, 1- b, 4 – c
(C) 4 – a, 3 – b, 2 – c, 1 – d
(D) 3 – a, 4 – b, 1 – c, 2 – d
Ans:- A.

19. A function that has no partial functional dependencies is in _____________ form.
(A) 3 NF (B) 2 NF (C) 4 NF (D) BCNF
Ans:- B

20. Which of the following statement is wrong?
I. 2-phase locking protocol suffer from dead lock.
II. Time stamp protocol suffer from more aborts.
III. A block hole in a DFD is a data store with only inbound flows.
IV. Multivalued dependency among attribute is checked at 3 NF level.
V. An entity-relationship diagram is a tool to represent event model.
(A) I ,II,III (B) II,III,IV (C) III,IV,V (D) II,IV,V
Ans:- A

21. If the number of leaves in a strictly binary tree is an odd number, then what can you say with full conviction about total number of nodes in a tree?
(A) It is an odd number.
(B) It is an even number.
(C ) It cannot be equal to the number of leaves.
(D ) It is always greater than twice the number of leaves.
Ans:- A. Strictly binary tree with N leaves contains 2N-1 nodes. So when the number of leaves is odd number then the total number of nodes in the tree also will be odd if we apply the above formula.

22. The number of edges in a complete graph of n vertices is
(A) n (B) n(n-1)/2 (C ) n(n+1)/2 (D) n2/2
Ans:- B. The complete graph on n vertices has n(n-1)/2 edges.

23. At a hill station, the parking lot is one long drive way snaking up a hill side. Cars drive in and park right behind the car in front of them, one behind another. A car can’t leave until all the cars in front of it have left. Is the parking lot more like
(A) An array (B) A stack (C) A queue (D) A linked list
Ans:- C.

24. With regard to linked list, which of the following statement is false ?
(A) An algorithm to search for an element in a singly linked list requires O(n) operations in the worst case.
(B) An algorithm for deleting the first element in a singly linked list requires o(n) operations in the worst case.
(C ). An algorithm for finding the maximum value in a circular linked list requires o(n) operations.
(D ). An algorithm for deleting the middle node of a circular linked list requires o(n) operations.
Ans:- B

25. A hash function f defined as f(key)=key mod 7, with linear probing used to resolve collisions. Insert the keys 37,38,72,48,98 and 11 into the table indexed from 0 to 6. What will be the location of 11?
(A) 3 (B) 4 (C ) 5 (D) 6
Ans:- C

26. Device on one network can communicate with devices on another network via a
(A) Hub/switch (B) Utility server
( C) File server (D) Gateway
Ans:- D

27. What is the maximum window size in sliding window protocol used in a computer network?
(A) 4 (B) 8 (C ) 15 (D) 16
Ans:- A

28. Which of the following are Data Link Layer standard?
1. Ethernet 2. HSSI 3. Frame Relay
4. 10-Base T 5. Token Ring
(A) 1,2,3 (B) 1,3,5 (C) 1,3,4,5 (D) 1,2,3,4,5
Ans:- C

29. In case of Bus/Tree topology signal balancing issue is overcome by
(A) Modulation (B) Polling
(C ) Segmentation (D) Strong transmitter
Ans:- C

30. Match the following:
(i) Ethernet (a) Deterministic
(ii) Token Ring (b) Utilize the full wire speed
(iii) Cut-through switch (c ) Prevent Looping
(iv) Spanning tree (d) Checking valid address
Codes:
(A) i-d,ii-a,iii-b,iv-c (B) i-a,ii-d,iii-b,iv-c
(C ) i-d,ii-d,iii-c,iv-b (D) i-d,ii-c,iii-b,iv-a
Ans:- A

31. In an absolute loading scheme which loader function is accomplished by assembler?
(A) re-allocation (B) allocation (C ) linking (D) loading
Ans:- A. Implementation of Absolute loader: The four loader functions are performed as following: 1.Allocation- By programmer 2.Linking- By programmer 3.Relocation- By assembler 4.Loading- By loader

32. Which of the following grammar is LR(1)?
(A) A->aAb, A->bAb,A->a,A->b
(B) A->aAa,A->aAb,A->c
(C ) A->A+A,A->a
(D)Both (A) and (B)

33. A shift-reduce parser carries out the actions specified within braces immediately after reducing with the corresponding rule of the grammar.
S->xxW[ print “1” ]
S->y [ print “2” ]
W->S2 [ print “3” }, what is the translation of “x x x x y z z”?
(A) 1 1 2 3 1 (B) 1 1 2 3 3 (C) 2 3 1 3 1 (D) 2 3 3 2 1
Ans:- C

34. Context-free Grammar(CFG) can be recognized by
(A) Finite state automata
(B) 2-way linear bounded automata
(C ) push down automata
(D ) Both (B) and (C)
Ans:- D

35. Synthesized attribute can be easily simulated by a
(A) LL grammar (B) Ambiguous grammar
(C ) LR grammar (D) None of the above
Ans:- C

36. In the process management Round-robin method is essentially the pre-emptive version of _______________.
(A) FILO (B) FIFO
(C ) SSF (D) Longest time first
Ans:- B

37. A page fault
(A) is an error specific page
(B) is an access to the page not currently in memory
(C ) occur when a page program occur in a page memory.
(D ) page used in the previous page reference.
Ans:- B

38. A semaphore count of negative n means (s=-n) that the queue contains ___n__________ waiting processes.
(A) n + 1 (B) n (C) n – 1 (D) 0
Ans:- B

39. A program is located in the smallest available hole in the memory is ______________
(A) best-fit (B) first-bit (C ) worst-fit (D ) buddy
Ans:- A

40. The unix command used to find out the number of characters in a file is
(A) nc (B) wc (C ) chcnt (D) lc
Ans:- B

41. Software Engineering is a discipline that integrates __________ for the development of computer software.
(A) Process (B) Methods (C ) Tools (D) All
Ans:- D

42. Any error whose cause cannot be identified anywhere within the software system is called _________________.
(A) Internal error (B) External error
(C ) Inherent error (D) Logic error
Ans:- B

43. Recorded software attributes can be used in the following endeavours:
(i) Cost and schedule estimates.
(ii) Software product reliability predictions
(iii )Managing development process
(iv). No where
Codes:
(A) (i) (ii) (iv)
(B) (ii) (iii) (iv)
(C) (i) (ii) (iii)
(D) (i) (ii) (iii) (iv)
Ans :- C

44. Black box testing is done
(A) To show that s/w is operational at its interfaces i.e. input and output.
(B) To examine internal details of code
(C) At client side
(D) None of the above
Ans:- A

45. The name of the transaction file shall be provided by the operator and the file that contains the edited transactions ready for execution shall be called
(A) Batch.exe (B) Trans.exe (C ) Opt.exe (D) Edit.exe
Ans:- C

46. The single stage network is also called
(A) One sided network (B) two sided network (C ) recirculating network
(E) pipeline network
Ans:- C. The single stage network is also called a recirculating network.

47. Analysis of large database to retrieve information is called
(A) OLTP (B) OLAP (C ) OLDP (D) OLPP
Ans:- B
48. Which technology is sometime referred to as wireless cable?
(A) MMDS (B) ATM (C ) LMDS (D) CDMA
Ans:- A. MMDS stands for multipoint multichannel distribution system. MMDS is a broadband wireless technology.

49. Another name of IEEE 802.11 a is ______________
(A) Wi-Max (B) Fast Ethernet (C) Wi-fi (D) 802.11 g
Ans:- C. IEEE 802.11 standards provide the basis for Wi-fi networks.

50. The unlicensed National Information Infrastructure band operates at the ____________frequency
(A) 2.4 GHz (B) 5 GHz (C ) 33 MHz (D) 5 MHz
Ans:- B

JAVA - BANGALORE UNIVERSITY

I am currently handling java programming for my BCA students. Apart from the classroom setting, i feel this is another forum for my students to interact with me and get their doubts clarified. Many students feel shy to ask questions in the classroom and keep quiet even if they do not understand a topic. So i am trying to write on certain specific topics which I am sure lot of students would still be having doubts. Please go through the topics, and if you want me to answer any particular doubts you have, feel free to post about them and i will explain it for you here. HAPPY LEARNING!!!!!!.

COMMAND LINE ARGUMENTS

ARRAYS IN JAVA





APPLET PROGRAMMING

JAVA QUESTION BANK



COMMAND LINE ARGUMENTS

Command line argument is a topic which we practically start our learning of java, but i am sure still there are students who are not clear about this. Here goes the explanation. Read it more than once if you are still not clear, you will get it.

Execution in a java program starts from the main method which we write in a class. When we write any method in java, you can pass parameters to it and the method can also return a value. Since "main" is also a method, parameters can also be passed to it but the only thing is that those parameters must be passed from the command line, when you invoke the java interpreter for executing the class file.

For example, if a class file called test is executed by the java interpreter, and command line arguments are passed to it, the invocation would like this ,

c:\>java test one two three

In the above example, three command line arguments are passed and they are the string one, two and three respectively. The complete program to handle these command line arguments would go like this,

class test
{
public static void main(String args[])
{
/* Arguments sent from the command line are stored in the args array.
Length of the args array would be equal to the no of arguments passed.
Following code simply prints the array elements */

for(int i=0;i<args.length;i++)
System.out.println(args[i]);
}
}


POINTS TO BE NOTED WHILE USING COMMAND LINE ARGUMENTS

1. Understand very clearly the data type of args. It is a array of strings. That is why it is declared as String args[]. args is just a variable name given to the array of strings which stores the command line arguments. It can be called anything, x,y or z.
2. Any data can be sent using command line arguments. But they are always copied into the string array only. So if any number is passed and should be treated like a number, we should convert it into a int data type using appropriate methods in java. (Like parseInt method called with the Integer class to convert the String into primitive int data type).
3. One of the useful applications of command line arguments would be to work with files, let us say. Suppose i am writing a class called copy which works like any other copy program. copy a source file to a destination file. The two file names can be given as command line arguments instead of accepting it from the user.

c:\>java copy file1 file2

Here file1 and file2 are command line arguments and there are statements in the copy class to copy file1 into file2.

APPLET PROGRAMMING



Applets are small java programs that are primarily used in internet computing. They are a piece of code which is downloaded by the browser and run at the client side. Applets can be used for doing any activity which we want to do. Say, for example, developing a user registration form, running a game program, a paint application, an EMI calculator etc.

Every applet that we write has to be extended from the built in class called Applet. This class is available in the applet package and so that should be imported. An example program for an applet would include an import statement for importing the applet package.

import java.applet.*;
import java.awt.*;

The awt package must be imported because it contains the Graphics class which is going to used in applet programming. Because of that reason, awt package also must be imported.

Let us say, we want to write a applet called testapp then the class definition for it should go like this,

public class testapp extends Applet
{
// Enclose the code for the applet
}

There are many methods executed in the life cycle of applet and they are

1. public void init()

2. public void start()

3. public void stop()

4. public void destroy()

init()

This method contains any initialisation code.

start()

This method is executed once init() finishes its execution. When a web page which contains the applet gets its focus, this method will be executed. So in the life cycle of an applet, this method could be executed more than once.

stop()

This is executed when a web page containing an applet loses its focus.

destroy()

This is the last method to be executed in the applet's life cycle and this will be executed only once.

Apart from all these methods, we should be familiar with one more method which would be frequently used in our learning of applet and it is the paint mehtod.

The signature for this method is ,
public void paint(Graphics g) { }
This method takes a Graphics object as its parameter. The Graphics class has lot of methods for drawing mamy different types of shapes, from simple to complex.
The following is a program for printing a "Hello world "

import java.applet.*;
import java.awt.*;
public class testapp extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hello world",100,100);
}
}

Parameter passing in applet

Just like how, values can be passed to the main method using command line arguments, we can also pass arguments to an applet. The arguments are passed using the PARAM tag using a name and value attribute. In the init method of the applet the parameter's values have to be captured and worked further upon. Let me first write the java program to capture the arguments. ;


import java.awt.*;
import java.applet.*
public class testparam
{
String str=" ";
public void init()
{
str=getParameter("name");
repaint();
}
public void paint(Graphics g)
{
g.drawString(str,200,200);
}
}

The second part is to write the html code which has the applet embedded and also the param tag for passing the parameters.

< html >
< body >
< applet code="testparam" width=400 height=400 >
< param name="name" value="JAVA" >
< body >
< html >

JAVA QUESTION BANK



The question bank comprises of PART A and PART B questions. PART A questions are 1 mark or 3 mark questions. PART B comprises of 7 mark questions.

PART A


PART B


PART A

1. Expand WWW,HTML,JDK,JVM,JRE,API and AWT.
2. Explain few methods available with the Math class.
3. What are the different types of comments available in java?
4. What are the rules for naming an identifier.
5. Why is java called platform independent?
6. What is a JVM?
7. How to create symbolic constant in java?
8. Write the syntax of switch statement in java.
9. What are labelled loops?
10. What are static members?
11. What is inheritance?
12. What are the different types of inheritance?
13. What are the consequences of making a class final?
14. What is the use of making a method final?
15. What are wrapper classes in java?
16. Name some inbuilt packages in java.
17. What are the different priorities that can be assigned to a thread?
18. Name some methods used for inter-thread communication.
19. How many catch blocks can be there for a single try block?
20. Name some differences between applets and applications.
21. Write a simple html file for embedding a applet.
22. Name some methods available in the Graphics class for drawing purpose.
23. What are the attributes available with applet tag?. Explain few of them.
24. What is the difference between byte stream and character stream classes?
25. What is the purpose of pushbackinput stream class?
26. What is the purpose of piped stream class?
27. Name some methods available with inputstream class?
28. Name some methods available with outputstream class?
29. What are the different modes of opening a file using Randomaccessfile class?
29. How to draw a polygon in java?
30. Name some important events available in java.

PART B

1. Explain the features of java.
2. How java differs from c and c++.
3. Explain the general structure of a java program.
4. Explain the different types of statements in java with example.
5. Explain command line arguments with an example.
6. Explain the data types in java with an example.
7. Eplain instance variables, class variables and local variables with an example.
8. What are constructors? Explain with an example.
9. What is method overloading? Explain with an example.
10. Illustrate method overriding with an example.
11. What are abstract methods?. Explain with an example.
12. Write the steps for creating an array in java with an example.
13. Explain atleast 10 string functions in java.
14. What are interfaces? Explain with an example.
15. What are packages? Write the steps for creating a package with an example.
16. What are threads?. What are the two different ways of creating a thread?
17. Explain the lifecycle of a thread with a neat diagram.
18. Explain the five keywords of exception handling.
19. Explain the life cycle of applet with a neat diagram.
20. How to pass parameters to applets?. Explaintream
with an example.
21. Explain the hierarchy of input stream classes with a digram.
22. Explain the hierarchy of output stream classes with a neat diagram.
23. Explain the hierarchy of input stream classes with a neat diagram.
24. Explain the random access file class in java with an example.
25. What is a File class?. Explain some important methods available with this class.


ARRAYS IN JAVA




Here i am assuming that the readers will know about how arrays are handled in c and c++. The main focus is on how java handles arrays and what are the unique features in its declaration.

In c or c++, whenever we declare an array we have to mention the size of the array(i am not talking about dynamic allocation of arrays using malloc or new operator). But in java when an array is declared you just mention that it is an array by writing empty square brackets next to the name of the array.
For example, if we want to declare an integer array which will be called as arr,
the declaration would go like this,
int arr[];

The size of the array would be mentioned when memory is allocated for it.
arr=new int[5];
Memory for the array arr is allocated and arr contains the reference to the set of five contiguous memory locations.

Points to be noted:

1. Individual elements of the array are accessed by using the arrayname[indexname]syntax.
2. If we overstep ar array in java, it generates an ArrayIndexOutOfBoundsException and comes out of the program. I just cannot overemphasize the importance of staying within the array bounds in java. If you overstep, java will not keep quiet and it will mouth exceptions like the one mentioned above. So, JUST BE PREPARED..
3. In java, if we are talking about two-dimensional arrays, all the rows need not have the same column. Each one of the rows can be having a different number of columns. Such arrays are called jagged arrays. A very interesting and a different way of working with arrays. I would explain it with an example.

class jaggedarr
{
public static void main(String ar[])
{
int twodim[][];
twodim=new int[3][];
int i,j;
for(i=0;i<twodim.length;i++)
{
twodim[i]=new int[i+1];
for(j=0;j<twodim[i].length;j++)
{
twodim[i][j]=1;
System.out.print(twodim[i][j]+" ");
}
System.out.println();
}
}
}
In the above example, the array twodim is declared as one having 3 rows, but the number of columns are given based on the value of i. So, the first row has one column, second row has two columns and third row has three columns.