Thursday, September 18, 2008

Core Java Interview Questions

Core Java Interview Questions Part-1

Core Java Interview Questions Part-2

Core Java Interview Questions Part-3

Core Java Interview Questions Part-4

Core Java Interview Questions Part-5

Core Java Interview Questions Part-6

Core Java Interview Questions Part-7

Core Java Interview Questions Part-8

Core Java Interview Questions Part-9

Core Java Interview Questions Part-9

132 Q What is volatile variable?

A volatile variable is not allowed to have a local copy of a variable that is different from the value currently held in "main" memory. Volatile modifier requests the JVM to always access the shared copy of the variable so the its most current value is always read.

133 Q Why java does not support multiple inheritance?

Because the multiple inheritance causes the redundancy. Also we cannot solve diamond problem.

134 Q What is diamond problem?

The diamond problem is an ambiguity that can occur when a class multiply inherits from two classes that both descend from a common super class

135 Q How many JVM's we can run in a system?

Any number of JVMs can run in a system. Whenever we issue the command 'java' a new JVM will start.

136 Q Why Java is not 100% pure object oriented language?

Because java uses primitives.

137 Q Why ArrayList is faster than Vector?

Because Vector is synchronized. Synchronization reduces the performance.

138 Q What is the security mechnaism used in java?

Java uses sand box security model.

139 Q What is sandbox?

A sandbox is a security mechanism for safely running programs. The sandbox typically provides a tightly-controlled set of resources for guest programs to run in, such as scratch space on disk and memory.

140 Q What is phantom memory?

Phantom memory is the memory that does not exist in reality.

141 Q What is reflection?

Reflection is the process of finding out the different features of a class dynamically.

142 Q What are the differences between JIT and HotSpot?

The Hotspot VM is a collection of techniques, the most important of which is called adaptive optimization. The original JVMs interpreted byte codes one at a time. Second-generation JVMs added a JIT compiler, which compiles each method to native code upon first execution, then executes the native code. Thereafter, whenever the method is called, the native code is executed. The adaptive optimization technique used by Hotspot is a hybrid approach, one that combines byte code interpretation and run-time compilation to native code. Hotspot, unlike a regular JIT compiling VM, doesn't do "premature optimization"

143 Q What are the advantages and disadvantages of reference counting in garbage collection?

An advantage of this scheme is that it can run in small chunks of time closely linked with the execution of the program. These characteristic makes it particularly suitable for real-time environments where the program can't be interrupted for very long time. A disadvantage of reference counting is that it does not detect cycles. A cycle is two or more objects that refer to one another. Another disadvantage is the overhead of incrementing and decrementing the reference count each time. Because of these disadvantages, reference counting currently is out of favor.

144 Q How would you implement a thread pool?

The ThreadPool class is a generic implementation of a thread pool, which takes the following input Size of the pool to be constructed and name of the class which implements Runnable (which has a visible default constructor) and constructs a thread pool with active threads that are waiting for activation. once the threads have finished processing they come back and wait once again in the pool.

145 Q What is the difference between throw and throws clause?

throw is used to throw an exception manually, where as throws is used in the case of checked exceptions, to tell the compiler that we haven't handled the exception, so that the exception will be handled by the calling function.

146 Q What is JAR file?

A JAR file (short for Java Archive) is a ZIP file used to distribute a set of Java classes. It is used to store compiled Java classes and associated metadata that can constitute a program

147 Q What is a classloader?

A class loader is an object that is responsible for loading classes.

148 Q What is the difference between Comparable and Comparator ?

The Comparable is for natural ordering and Comparator is for custom ordering. But we can override the compareTo method of comparable interface to give a custom ordering.

149 Q What is the difference between List, Set and Map?

A Set is a collection that has no duplicate elements. A List is a collection that has an order associated with its elements. A map is a way of storing key/value pairs. The way of storing a Map is similar to two-column table.

150 Q What is the difference between Exception and Error ?

Error is unrecoverable.

Core Java Interview Questions Part-8

111 Q How does a try statement determine which catch clause should be used to handle an exception?

When an exception is thrown , the catch block of the try statement are examined in the order in which they appear. The first catch block that is capable of handling the exception is executed. The remaining catch blocks are ignored

112 Q How parameters are passed to methods in java program ?

All java method parameters in java are passed by value only. Obviously primitives are passed by value. In case of objects a copy of the reference is passed and so all the changes made in the method will persist.

113 Q If a class doesn't have any constructors, what will happen?

If a class doesn't have a constructor, the JVM will provide a default constructor for the class.

114 Q What will happen if a thread cannot acquire a lock on an object?

It enters to the waiting state until lock becomes available.

115 Q How does multithreading occurring on a computer with a single CPU?

The task scheduler of OS allocates an execution time for multiple tasks. By switching between different executing tasks, it creates the impression that tasks execute sequentially. But actually there is only one task is executed at a time.

116 Q What will happen if you are invoking a thread's interrupt method while the thread is waiting or sleeping?

When the task enters to the running state, it will throw an InterruptedException.

117 Q What are the different ways in which a thread can enter into waiting state?

There are three ways for a thread to enter into waiting state. By invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method.

118 Q What are the the different ways for creating a thread?

A thread can be created by subclassing Thread, or by implementing the Runnable interface.

119 Q What is the difference between creating a thread by extending Thread class and by implementing Runnable interface? Which one should prefer?

When creating a thread by extending the Thread class, it is not mandatory to override the run method (If we are not overriding the run method , it is useless), because Thread class have already given a default implementation for run method. But if we are implementing Runnable , it is mandatory to override the run method. The preferred way to create a thread is by implementing Runnable interface, because it give loose coupling.

120 Q What is coupling?

Coupling is the dependency between different components of a system

121 Q How is an interface?

An interface is a collection of method declarations and constants. In java interfaces are used to achieve multiple inheritance. It sets a behavioral protocol to all implementing classes.

122 Q What is an abstract class?

An abstract class is an incomplete class. An abstract class is defined with the keyword abstract . We cannot create an object of the abstract class because it is not complete. It sets a behavioral protocol for all its child classes.

123 Q How will you define an interface?

An interface is defined with the keyword interface. Eg:
public interface MyInterface { }

124 Q How will you define an abstract class?

An abstract class is defined with the keyword abstract Eg:
public abstract class MyClass { }

125 Q What is any an anonymous class?

A An anonymous class is a local class with no name.

126 Q What is a JVM heap?

The heap is the runtime data area from which memory for all class instances and arrays is allocated. The heap may be of a fixed size or may be expanded. The heap is created on virtual machine start-up.

127 Q What is difference between string and StringTokenizer?

StringTokenizer as its name suggests tokenizes a String supplied to it as an argument to its constructor and the character based on which tokens of that string are to be made. The default tokenizing character is space " ".

128 Q What is the difference between array and ArrayList ?

Array is collection of same data type. Array size is fixed, It cannot be expanded. But ArrayList is a growable collection of objects. ArrayList is a part of Collections Framework and can work with only objects.

129 Q What is difference between java.lang .Class and java.lang.ClassLoader? What is the hierarchy of ClassLoader ?

Class 'java.lang.Class' represent classes and interfaces in a running Java application. JVM construct 'Class' object when class in loaded. Where as a ClassLoader is also a class which loads the class files into memory in order for the Java programs to execute properly. The hierarchy of ClassLoaders is:

Bootstrap ClassLoaders
Extensive ClassLoaders
System Classpath ClassLoaders
Application ClassLoaders

130 Q What is daemon thread?

Theards which are running on the background are called deamon threads. daemon thread is a thread which doesn't give any chance to run other threads once it enters into the run state it doesn't give any chance to run other threads. Normally it will run forever, but when all other non-daemon threads are dead, daemon thread will be killed by JVM

131 Q What is a green thread?

Native threads can switch between threads preemptively. Green threads switch only when control is explicitly given up by a thread ( Thread.yield(), Object.wait(), etc.) or a thread performs a blocking operation (read(), etc.). On multi-CPU machines, native threads can run more than one thread simultaneously by assigning different threads to different CPUs. Green threads run on only one CPU. Native threads create the appearance that many Java processes are running: each thread takes up its own entry in the process table. One clue that these are all threads of the same process is that the memory size is identical for all the threads - they are all using the same memory. The process table is not infinitely large, and processes can only create a limited number of threads before running out of system resources or hitting configured limits.

Core Java Interview Questions Part-7

91 Q What is java byte code?

Byte code is an sort of intermediate code. The byte code is processed by virtual machine.

92 Q What is method overloading?

Method overloading is the process of creating a new method with the same name and different signature.

93 Q What is method overriding?

Method overriding is the process of giving a new definition for an existing method in its child class.

94 Q What is finalize() ?

Finalize is a protected method in java. When the garbage collector is executes , it will first call finalize( ), and on the next garbage-collection it reclaim the objects memory. So finalize( ), gives you the chance to perform some cleanup operation at the time of garbage collection.

95 Q What is multi-threading?

Multi-threading is the scenario where more than one threads are running.

96 Q What is deadlock?

Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread.

97 Q What is the difference between Iterator and Enumeration?

Iterator differ from enumeration in two ways Iterator allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. And , method names have been improved.

98 Q What is the Locale class?

A Locale object represents a specific geographical, political, or cultural region

99 Q What is internationalization?

Internationalization is the process of designing an application so that it can be adapted to various languages and regions without changes.

100 Q What is anonymous class ?

A An anonymous class is a type of inner class that don't have any name.

101 Q What is the difference between URL and URLConnection?

A URL represents the location of a resource, and a URLConnection represents a link for accessing or communicating with the resource at the location.

102 Q What are the two important TCP Socket classes?

ServerSocket and Socket. ServerSocket is useful for two-way socket communication. Socket class help us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.

103 Q Strings are immutable. But String s="Hello"; String s1=s+"World" returns HelloWorld how ?

Here actually a new object is created with the value of HelloWorld

104 Q What is classpath?

Classpath is the path where Java looks for loading class at run time and compile time.

105 Q What is path?

It is an the location where the OS will look for finding out the executable files and commands.

106 Q What is java collections?

Java collections is a set of classes, that allows operations on a collection of classes.

107 Q Can we compile a java program without main?

Yes, we can. In order to compile a java program, we don't require any main method. But to execute a java program we must have a main in it (unless it is an applet or servlet). Because main is the starting point of a java program.

108 Q What is a java compilation unit.

A compilation unit is a java source file.

109 What are the restrictions when overriding a method ?

Overridden methods must have the same name, argument list, and return type (i.e., they must have the exact signature of the method we are going to override, including return type.) The overriding method cannot be less visible than the method it overrides( i.e., a public method cannot be override to private). The overriding method may not throw any exceptions that may not be thrown by the overridden method

110 Q What is static initializer block? What is its use?

A static initializer block is a block of code that declares with the static keyword. It normally contains the block of code that must execute at the time of class loading. The static initializer block will execute only once at the time of loading the class only.

Wednesday, September 17, 2008

Cobol Interview Questions Part-11

178. Define the structure of a COBOL subroutine.

Ans: The PROCEDURE DIVISION header must have a using a phrase, if the data needs to be passed to the program. The operands of the USING phrase must be defined in the LINKAGE SECTION as 01-level or 77-level entries. No VALUE clause is allowed unless the data defined is a condition name.

If the program needs to be returned to the CALLER, use EXIT PROGRAM statement at the end of the program. GOBACK is an alternative, but is nonstandard.

179. What is difference between next sentence and continue

Ans: NEXT SENTENCE gives control to the verb following the next period. CONTINUE gives control to the next verb after the explicit scope terminator. (This is not one of COBOL II's finer implementations). It's safest to use CONTINUE rather than NEXT SENTENCE in COBOL II. CONTINUE is like a null statement (do nothing) , while NEXT SENTENCE transfers control to the next sentence (!!) (A sentence is terminated by a period). Check out by writing the following code example, one if sentence followed by 3 display statements: If 1 > 0 then next sentence end if display 'line 1' display 'line 2'. display 'line 3'. *** Note- there is a dot (.) only at the end of the last 2 statements, see the effect by replacing Next Sentence with Continue ***

180. What is the difference between Structured Cobol Programming and Object Oriented COBOL programming?

Ans: Structured programming is a Logical way of programming using which you divide the functionality's into modules and code logically. OOP is a Natural way of programming in which you identify the objects, first then write functions and procedures around the objects. Sorry, this may not be an adequate answer, but they are two different programming paradigms, which is difficult to put in a sentence or two.

181. PIC S9(4)COMP is used in spite of COMP-3 which occupies less space why?

Ans:S9(4) COMP uses only 2 bytes. 9(4) COMP-3 uses 3 bytes. 3 bytes are more than 2 bytes. Hence COMP is preferred over COMP-3 in this case.

182. How many number of bytes and digits are involved in S9(10) COMP?

Ans: 8 bytes (double word) and 10 digits. Up to 9(9) comp use full word, up to 9(18) comp needs double word.

183. How many numbers of decimal digits are possible, when the amount of storage allocated for a USAGE COMP item is a) half word b) full word c) double word?

Ans: 2 bytes (halfword) for 1-4 Digits 4 bytes (fullword) for 5-9

8 bytes (doubleword) for 10-18

184. What is a scope terminator? Give examples.

Ans: Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE , IF, END-IF.

185. How many dimensions are allowed for a table?

Ans: 7

186. How many subscripts or indexes are allowed for an OCCURS clause?

Ans: 7

187. Why cannot Occurs be used in 01 level?

Ans: Because, Occurs clause is there to repeat fields with the same format, but not the records.

188. Can a REDEFINES clause be used along with an OCCURS clause?

Ans: Yes, if the REDEFINES clause is subordinate to OCCURS clause.

189. Can you specify PIC clause and a VALUE with an OCCURS clause? Will the following code compile without errors?

01 WS-TABLE.

03 WS-TABLE-EL OCCURS 5 TIMES PIC X(1) VALUE SPACES.

Ans: Yes, the code will compile without any errors.

190. What would be the output, when the following code is executed?

01 WS-TABLE.

03 WS-TABLE-EL OCCURS 5 TIMES PIC X(1) VALUE 'AAAAA'.

Ans:It cannot be executed because the code will compile with error ' "VALUE" literal "'AAAA'" exceeded the length specified in the "PICTURE" definition'.

191. 01 WS-TABLE.

03 WS-TABLE-EL OCCURS 5 TIMES PIC X(1) VALUE 'A'.

03 WS-EX REDEFINES WS-TABLE-EL PIC X(5). What can you expect?

Ans: Compile error. Direct Redefinition of OCCURS clause is not allowed.

192. 01 WS-TABLE.

03 WS-TABLE-EL OCCURS 5 TIMES.

04 FILLER-X PIC X(1) VALUE 'A'.

04 WS-EX REDEFINES FILLER-X PIC X(1).

What would be the output of DISPLAY WS-TABLE?

Ans: 'AAAAA'. The code will compile and execute as Redefinition of an item subordinate to OCCURS clause.

193. Can a SEARCH be applied to a table which does not have an INDEX defined?

Ans: No, the table must be indexed.

194. What is the difference between SEARCH and SEARCH ALL?

Ans: SEARCH - is a serial search.

SEARCH ALL - is a binary search & the table must be sorted ( ASCENDING/DESCENDING KEY clause to be used & data loaded in this order) before using SEARCH ALL.

195. What should be the sorting order for SEARCH ALL?

Ans:It can be either ASCENDING or DESCENDING. ASCENDING is default. If you want the search to be done on an array sorted in descending order, then while defining the array, you should give DESCENDING KEY clause. (You must load the table in the specified order).

196. What is binary search?

Ans:Search on a sorted array. Compare the item to be searched with the item at the center. If it matches, fine else repeat the process with the left half or the right half depending on where the item lies.

197. Can a SEARCH be applied to a table which does not have an INDEX defined?

Ans: No, the table must be indexed.

198. A table has two indexes defined. Which one will be used by the SEARCH verb?

Ans: The index named first will be used, by Search.

199. What are the different rules applicable to perform a binary SEARCH?

Ans: The table must be sorted in ascending or descending order before the beginning of the SEARCH. Use OCCURS clause with ASC/DESC KEY IS dataname1 option

The table must be indexed. There is no need to set the index value. Use SEARCH ALL verb

200. How does the binary search work?

Ans: First the table is split into two halves and in which half, the item need to be searched is determined. The half to which the desired item may belong is again divided into two halves and the previous procedure is followed. This continues until the item is found. SEARCH ALL is efficient for tables larger than 70 items.

Cobol Interview Questions Part-10

151. What are the few advantages of VS COBOL II over OS/VS COBOL?

Ans: The working storage and linkage section limit has been increased. They are 128 megabytes as supposed to 1 megabytes in OS/VS COBOL.

Introduction of ADDRESS special register.

31-bit addressing. In using COBOL on PC we have only flat files and the programs can access only limited storage, whereas in VS COBOL II on M/F the programs can access up to 16MB or 2GB depending on the addressing and can use VSAM files to make I/O operations faster

152. What are the steps you go through while creating a COBOL program executable?

Ans: DB2 pre-compiler (if embedded SQL is used), CICS translator (if CICS program), Cobol compiler, Link editor. If DB2 program, create plan by binding the DBRMs.

153. Name the divisions in a COBOL Program

Ans: Identification / Environment/ Data/ Procedure Divisions

154. What are the different data types available in COBOL?

Ans: Alpha-numeric (X) , Alphabetic (A) and numeric (9).

155. What does the INITIALIZE verb do?

Ans: Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES. Numeric, Numeric edited items set to ZERO. FILLER , OCCURS DEPENDING ON items left untouched

156. What is the difference between a 01 level and 77 levels?

Ans: 01 level can have sublevels from 02 to 49. 77 cannot have sublevel.

157. What are 77 levels used for?

Ans: Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.

158. What is 88 level used for?

Ans: For condition names.

159. What is level 66 used for?

Ans: For RENAMES clause.

160. What does the IS NUMERIC clause establish?

Ans: IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal items and unsigned numeric & packed decimal items. IS NUMERIC returns TRUE if the item only consists of 0-9. However, if the item being tested is a signed item, then it may contain 0-9, + and - .

161. Is compute w=u a valid statement?

Ans: Yes, it is. It is equivalent to move u to w.

162. In the above example, when will you prefer compute statement over the move statement?

Ans: When significant left-order digits would be lost in execution, the COMPUTE statement can detect the condition and allow you to handle it. The MOVE statement carries out the assignment with destructive truncation. Therefore, if the size error is needs to be detected, COMPUTE will be preferred over MOVE. The ON SIZE ERROR phrase of COMPUTE statement, compiler generates code to detect size-overflow.

163. What happens when the ON SIZE ERROR phrase is specified on a COMPUTE statement?

Ans: If the condition occurs, the code in the ON SIZE ERROR phrase is performed, and the content of the destination field remains unchanged. If the ON SIZE ERROR phrase is not specified, the assignment is carried out with truncation. There is no ON SIZE ERROR support for the MOVE statement.

164. How will you associate your files with external data sets where they physically reside?

Ans: Using SELECT clause, the files can be associated with external data sets. The SELECT clause is defined in the FILE-CONTROL paragraph of Input-Output Section that is coded Environment Division. The File structure is defined by FD entry under File-Section of Data Division for the OS.

165. How will you define your file to the operating system?

Ans: Associate the file with the external data set using SELECT clause of INPUT-OUTPUT SECTION. INPUT-OUTPUT SECTION appears inside the ENVIRONMENT DIVISION.

166. Explain the use of Declaratives in COBOL?

Ans: Declaratives provide special section that are executed when an exceptional condition occurs. They must be grouped together and coded at the beginning of procedure division and the entire procedure division must be divided into sections. The Declaratives start with a USE statement. The entire group of declaratives is preceded by DECLARIVES and followed by END DECLARITIVES in area A. The three types of declaratives are Exception (when error occurs during file handling), Debugging (to debug lines with 'D' coded in w-s section) and Label (for EOF or beginning...) declaratives.

167. How do you define a table/array in COBOL?

Ans:

01 ARRAYS.

05 ARRAY1 PIC X(9) OCCURS 10 TIMES.

05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.

168. Can the OCCURS clause be at the 01 level?

Ans: No

169. A statically bound subprogram is called twice. What happens to working-storage variables?

Ans:The working-storage section is allocated at the start of the run-unit and any data items with VALUE clauses are initialized to the appropriate value at the time. When the subprogram is called the second time, a working-storage items persist in their last used state. However, if the program is specified with INITIAL on the PROGRAM-ID, working-storage section is reinitialized each time the program is entered.

170. Significance of the COMMON Attribute ?

Ans:COMMON attribute is used with nested COBOL programs. If it is not specified, other nested programs will not be able to access the program. PROGRAM-ID. Pgmname is COMMON PROGRAM.

171. In which division and section, the Special-names paragraph appears?

Ans: Environment division and Configuration Section.

172. What is the LOCAL-STORAGE SECTION?

Ans:Local-Storage is allocated each time the program is called and is de-allocated when the program returns via an EXIT PROGRAM, GOBACK, or STOP RUN. Any data items with a VALUE clauses are initialized to the appropriate value each time the program is called. The value in the data items is lost when the program returns. It is defined in the DATA DIVISION after WORKING-STORAGE SECTION

173. What does passing BY REFERENCE mean?

Ans:When the data is passed between programs, the subprogram refers to and processes the data items in the calling program's storage, rather than working on a copy of the data. When

CALL . . . BY REFERENCE identifier. In this case, the caller and the called share the same memory.

174. What does passing BY CONTENT mean?

Ans:The calling program passes only the contents of the literal, or identifier. With a CALL . . . BY CONTENT, the called program cannot change the value of the literal or identifier in the calling program, even if it modifies the variable in which it received the literal or identifier.

175. What does passing BY VALUE mean?

Ans:The calling program or method is passing the value of the literal, or identifier, not a reference to the sending data item. The called program or invoked method can change the parameter in the called program or invoked method. However, because the subprogram or method has access only to a temporary copy of the sending data item, those changes do not affect the argument in the calling program. Use By value, If you want to pass data to C program. Parameters must be of certain data type.

176. What is the default, passing BY REFERENCE or passing BY CONTENT or passing BY VALUE?

Ans: Passing by reference (the caller and the called share the same memory).

177. Where do you define your data in a program if the data is passed to the program from a Caller program?

Ans: Linkage Section 

Cobol Interview Questions Part-9

140. Can you REWRITE a record in an ESDS file? Can you DELETE a record from it?

Ans: Can rewrite(record length must be same), but not delete.

141.What is file status 92?

Ans: Logic error. e.g., a file is opened for input and an attempt is made to write to it.

142.What is file status 39?

Ans: Mismatch in LRECL or BLOCKSIZE or RECFM between your COBOL pgm & the JCL (or the dataset label). You will get file status 39 on an OPEN.

143.What is Static, Dynamic linking ?

Ans: In static linking, the called subroutine is link-edited into the calling program , while in dynamic linking, the subroutine & the main program will exist as separate load modules. You choose static/dynamic linking by choosing either the DYNAM or NODYNAM link edit option. (Even if you choose NODYNAM, a CALL identifier (as opposed to a CALL literal), will translate to a DYNAMIC call).

A statically called subroutine will not be in its initial state the next time it is called unless you explicitly use INITIAL or you do a CANCEL. A dynamically called routine will always be in its initial state.

144.Explain NEXT and CONTINUE verbs for file handling.

Ans: A The Continue verb is used for a situation where there in no EOF condition. i.e. The records are to be accessed again and again in a file. Whereas in the next verb the indexed file is accessed sequentially, whence when index clause is accessed sequentially read next record command is used.

145. What is AMODE(24), AMODE(31), RMODE(24) and RMODE(ANY)? (applicable to only MVS/ESA).

Ans: These are compile/link edit options. AMODE - Addressing mode. RMODE - Residency mode.

AMODE(24) - 24 bit addressing. AMODE(31) - 31 bit addressing. AMODE(ANY) - Either 24 bit or 31 bit addressing depending on RMODE. RMODE(24) - Resides in virtual storage below 16 Meg line. Use this for 31 bit programs that call 24 bit programs. (OS/VS Cobol pgms use 24 bit addresses only). RMODE(ANY) - Can reside above or below 16 Meg line.

146. What compiler option would you use for dynamic linking?

DYNAM.

147. What is SSRANGE, NOSSRANGE ?

Ans: These are compiler options w.r.t subscript out of range checking. NOSSRANGE is the default and if chosen, no run time error will be flagged if your index or subscript goes out of the permissible range.

148. How do you set a return code to the JCL from a COBOL program?

Ans: Move a value to RETURN-CODE register. RETURN-CODE should not be declared in your program.

149. How can you submit a job from COBOL programs?

Ans: Write JCL cards to a dataset with

//xxxxxxx SYSOUT=(A,INTRDR) where 'A' is output class, and dataset should be opened for output in the program. Define a 80 byte record layout for the file.

150. What are the differences between OS VS COBOL and VS COBOL II?

Ans:

  1. OS/VS Cobol pgms can only run in 24 bit addressing mode, VS Cobol II pgms can run either in 24 bit or 31 bit addressing modes allowing program to address above 16 Meg main storage line.
  2. Report writer is supported only in OS/VS Cobol.
  3. USAGE IS POINTER is supported only in VS COBOL II.
  4. Reference modification eg: WS-VAR(1:2) is supported only in VS COBOL II.
  5. COBOL II introduces new features (EVALUATE, SET ... TO TRUE, CALL ... BY CONTEXT, etc)
  6. Scope terminators are supported in COBOL II.
  7. OS/VS Cobol follows ANSI 74 stds while VS COBOL II follows ANSI 85 stds.
  8. Under CICS Calls between VS COBOL II programs are supported.
  9. COBOL II supports structured programming by using in-line PERFORM 's.
  10. COBOL II does not support old features (READY TRACE, REPORT-WRITER, ISAM, etc.).
  11. In non-CICS environment, it is possible. In CICS, this is not possible. 

Cobol Interview Questions Part-8

121. What is the difference between performing a SECTION and a PARAGRAPH?

Ans: Performing a SECTION will cause all the paragraphs that are part of the section, to be performed.

Performing a PARAGRAPH will cause only that paragraph to be performed.

122.Can I redefine an X(200) field with a field of X(100) ?

Ans: Yes.

123.What does EXIT do?

Ans: Does nothing ! If used, must be the only sentence within a paragraph.

124.Can I redefine an X(100) field with a field of X(200)?

Ans: Yes. Redefines just causes both fields to start at the same location. For example:

01 WS-TOP PIC X(1)

01 WS-TOP-RED REDEFINES WS-TOP PIC X(2).

If you MOVE '12' to WS-TOP-RED,

DISPLAY WS-TOP will show 1 while

DISPLAY WS-TOP-RED will show 12.

125.Can I redefine an X(200) field with a field of X(100) ?

Ans: Yes.

126. What do you do to resolve SOC-7 error?

Ans:Basically you need to correcting the offending data. Many times the reason for SOC7 is an un-initialized numeric item. Examine that possibility first. Many installations provide you a dump for run time abends ( it can be generated also by calling some subroutines or OS services thru assembly language). These dumps provide the offset of the last instruction at which the abend occurred. Examine the compilation output XREF listing to get the verb and the line number of the source code at this offset. Then you can look at the source code to find the bug. To get capture the runtime dumps, you will have to define some datasets (SYSABOUT etc ) in the JCL. If none of these are helpful, use judgement and DISPLAY to localize the source of error. You may even use batch program debugging tools.

127.How is sign stored in Packed Decimal fields and Zoned Decimal fields?

Ans:Packed Decimal fields: Sign is stored as a hex value in the last nibble (4 bits ) of the storage. Zoned Decimal fields: As a default, sign is over punched with the numeric value stored in the last bite.

128. How is sign stored in a comp-3 field?

Ans:It is stored in the last nibble. For example if your number is +100, it stores hex 0C in the last byte, hex 1C if your number is 101, hex 1D if the number is -101, hex 2D if the number is -102 etc...

129.How is sign stored in a COMP field ?

Ans: In the most significant bit. Bit is on if -ve, off if +ve.

130. What is the difference between COMP & COMP-3 ?

Ans: COMP is a binary storage format while COMP-3 is packed decimal format.

131. What is COMP-1? COMP-2?

COMP-1 - Single precision floating point. Uses 4 bytes. COMP-2 - Double precision floating point. Uses 8 bytes.

132. How do you define a variable of COMP-1? COMP-2?

Ans: No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.

133. How many bytes does a S9(7) COMP-3 field occupy ?

Ans: Will take 4 bytes. Sign is stored as hex value in the last nibble.

General formula is INT((n/2) + 1)), where n=7 in this example.

134. How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?

Ans: Will occupy 8 bytes (one extra byte for sign).

135. What is the maximum size of a 01 level item in COBOL I? in COBOL II?

In COBOL II: 16777215

136. What is COMP SYNC?

Ans: Causes the item to be aligned on natural boundaries. Can be SYNCHRONIZED LEFT or RIGHT.

For binary data items, the address resolution is faster if they are located at word boundaries in the memory. For example, on main frame the memory word size is 4 bytes. This means that each word will start from an address divisible by 4. If my first variable is x(3) and next one is s9(4) comp, then if you do not specify the SYNC clause, S9(4) COMP will start from byte 3 ( assuming that it starts from 0 ). If you specify SYNC, then the binary data item will start from address 4. You might see some wastage of memory, but the access to this comp field is faster.

137. How do you reference the following file formats from COBOL programs?

Ans:Fixed Block File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F, BLOCK CONTAINS 0. Fixed Unblocked - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F, do not use BLOCK CONTAINS. Variable Block File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS V, BLOCK CONTAINS 0. Do not code the 4 bytes for record length in FD. i.e. JCL record length will be max record length in program + 4 Variable Unblocked - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS V, do not use BLOCK CONTAINS. Do not code 4 bytes for record length in FD ie JCL rec length will be max rec length in pgm + 4. ESDS VSAM file - Use ORGANISATION IS SEQUENTIAL. KSDS VSAM file - Use ORGANISATION IS INDEXED, RECORD KEY IS, Alternate Record Key Is RRDS File - Use ORGANISATION IS RELATIVE, RELATIVE KEY IS Printer File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F, BLOCK CONTAINS 0. (Use RECFM=FBA in JCL DCB).

138. What are different file OPEN modes available in COBOL? In which modes are the files Opened to write.

Ans:Different Open modes for files are INPUT, OUTPUT, I-O and EXTEND. Of which Output and Extend modes are used to write new records into a file.

139. In the JCL, how do you define the files referred to in a subroutine?

Ans: Supply the DD cards just as you would for files referred to in the main program. 

Cobol Interview Questions Part-7

101.How many Sections are there in Data Division?.

Ans: SIX SECTIONS 1.'FILE SECTION' 2.'WORKING-STORAGE SECTION' 3.'LOCAL-STORAGE SECTION' 4.'SCREEN SECTION' 5.'REPORT SECTION' 6.'LINKAGE SECTION'

In COBOL II, there are only 4 sections. 1.'FILE SECTION' 2.'WORKING-STORAGE SECTION' 3.'LOCAL-STORAGE SECTION' 4.'LINKAGE SECTION'.

102. How can I tell if a module is being called DYNAMICALLY or STATICALLY?

Ans:The ONLY way is to look at the output of the linkage editor (IEWL)or the load module itself. If the module is being called DYNAMICALLY then it will not exist in the main module, if it is being called STATICALLY then it will be seen in the load module. Calling a working storage variable, containing a program name, does not make a DYNAMIC call. This type of calling is known as IMPLICITE calling as the name of the module is implied by the contents of the working storage variable. Calling a program name literal (CALL).

103. What is the difference between a DYNAMIC and STATIC call in COBOL.

Ans:To correct an earlier answer:All called modules cannot run standalone if they require program variables passed to them via the LINKAGE section. DYNAMICally called modules are those that are not bound with the calling program at link edit time (IEWL for IBM) and so are loaded from the program library (joblib or steplib) associated with the job. For DYNAMIC calling of a module the DYNAM compiler option must be chosen, else the linkage editor will not generate an executable as it will expect null address resolution of all called modules. A STATICally called module is one that is bound with the calling module at link edit, and therefore becomes part of the executable load module.

104. What is the difference between PIC 9.99 and 9v99?

Ans:PIC 9.99 is a FOUR-POSITION field that actually contains a decimal point where as PIC 9v99 is THREE-POSITION numeric field with implied or assumed decimal position.

105. How is PIC 9.99 is different from PIC 9v99?

Ans:PIC 9.99 is a four position field that actually contains a decimal point where as 9v99 is a three position numeric field with an implied or assumed decimal point.

106. what is Pic 9v99 Indicates?

Ans:PICTURE 9v99 is a three position Numeric field with an implied or assumed decimal point after the first position; the v means an implied decimal point.

107. what guidelines should be followed to write a structured COBOL program?

Ans:1) Use 'EVALUATE' stmt for constructing cases. 2) Use scope terminators for nesting. 3)Use in-line Perform stmt for writing 'do ' constructions. 4) Use Test Before and test after in the Perform stmt for writing Do-While constructions.

108. Read the following code.

01 ws-n PIC 9(2) value zero.

a-para.

move 5 to ws-n.

perform b-para ws-n times.

b-para.

move 10 to ws-n.

How many times will b-para be executed ?

Ans: 5 Times only. it will not take the value 10 that is initialized in the loop.

109. What are some examples of command terminators?

Ans: END-IF, END-EVALUATE

110.What care has to be taken to force program to execute above 16 Meg line?

Ans: Make sure that link option is AMODE=31 and RMODE=ANY. Compile option should never have SIZE(MAX).BUFSIZE can be 2K, efficient enough.

111.Give some advantages of REDEFINES clause.

Ans: You can REDEFINE a Variable from one PICTURE class to another PICTURE class by using the same memory location. By REDEFINES we can INITIALISE the variable in WORKING-STORAGE Section itself.3. We can REDEFINE a Single Variable into so many sub-variables.(This facility is very useful in solving Y2000 Problem.)

112.Why do we code s9(4)comp. Inspite of knowing comp-3 will occupy less space.

Ans: Here s9(4)comp is small integer ,so two words equal to 8 bytes. Totally it will occupy 2 bytes(4 words).here in s9(4) comp-3 as one word is equal to 1/2 byte.4 words equal to 2 bytes and sign will occupy 1/2 bytes totally it will occupy 3 bytes.

113. The maximum number of dimensions that an array can have in COBOL-85 is ________.

Ans: SEVEN in COBOL - 85 and THREE in COBOL - 84

114. Name the divisions in a COBOL program.

Ans: IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, PROCEDURE DIVISION.

115. What are the different data types available in COBOL?

Ans: Alpha-numeric (X), alphabetic (A) and numeric (9).

116. What is 77 level used for ?

Ans: Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.

117. What is 88 level used for ?

Ans: For defining condition names.

118. What is level 66 used for ?

Ans: For RENAMES clause.

119. What does the IS NUMERIC clause establish?

Ans:IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal items and unsigned numeric & packed decimal items. IS NUMERIC returns TRUE if the item only consists of 0-9. However, if the item being tested is a signed item, then it may contain 0-9, + and - .

120. My program has an array defined to have 10 items. Due to a bug, I find that even if the program access the 11th item in this array, the program does not abend. What is wrong with it?

Ans: Must use compiler option SSRANGE if you want array bounds checking. Default is NOSSRANGE. 

My Ad

.