Computer Knowledge

Programming Languages and Compilers

2,284 Questions

Programming languages and compilers involve the rules, syntax, and semantics used to write and execute software programs. Key areas include scripting languages, object oriented concepts, and parsing algorithms like top down parsers. Practice these computer science questions to build proficiency for technical and computer knowledge exams.

Object oriented languagesScripting languagesCompilers and parsersProgramming syntax

Programming Languages and Compilers Questions

Multiple choice technology programming languages
  1. Case 1

  2. Case 2

  3. Case 3

  4. Default

  5. Compiler Error

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

In Java, the switch expression must evaluate to a compatible type (such as int, char, String, or enum). Using a long variable (i) in a switch statement is illegal and causes a compiler error.

Multiple choice technology programming languages
  1. This won't print

  2. This prints

  3. There's a runtime exception

  4. scenario is not legal

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In Java, an if statement condition must evaluate to a boolean value. Passing an integer variable i directly into the condition is illegal and causes a compilation error.

Multiple choice technology
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is the standard classic for loop syntax in Java: for(initialization; condition; iteration) statement. The initialization executes once, the condition is checked before each iteration, and the iteration executes after each loop cycle. Java also supports enhanced for-each loops, but this is the fundamental traditional form.

Multiple choice technology packaged enterprise solutions
  1. lazy=false;

  2. lazy=true;

  3. lazy=yes;

  4. lazy=no;

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The default value of lazy loading in Hibernate is 'true'. This means associations are loaded on-demand when first accessed, not eagerly when the parent object is loaded. This lazy loading improves performance by avoiding unnecessary database queries for data that might never be used.

Multiple choice technology packaged enterprise solutions
  1. Query.list()

  2. Query.iterate()

  3. Both are same

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

When instances are not cached, Query.iterate() can cause the N+1 select problem - it issues one query for the initial list and then additional queries for each uninitialized object proxy. Query.list() loads all data in a single query, making it more efficient for uncached data.

Multiple choice technology programming languages
  1. a) session.contains() method to determine if an instance belongs to the session cache.

  2. b) session.contains() method to determine if an instance belongs to the data base .

  3. c) Both are correct

  4. d) none of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

session.contains() checks if an instance exists in the session cache (first-level cache), not whether it's in the database. An entity can be in session cache without being persisted, or exist in database without being in cache.

Multiple choice technology programming languages
  1. a) By mapping the property with access="onlyfield" in Hibernate metadata

  2. b) By mapping the property with access="variable" in Hibernate metadata

  3. c) By mapping the property with access="field" in Hibernate metadata

  4. d) none of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In Hibernate, mapping a property with access="field" tells Hibernate to bypass the setter method and access the instance variable directly using reflection. This is useful when you have non-trivial setter logic that shouldn't execute during object loading. The 'variable' and 'onlyfield' values are not valid access strategies.

Multiple choice technology programming languages
  1. a) On session close session.load() Emp Object unavailable to access

  2. b) On session close session.createCriteria() Emp unavailable to access

  3. c) None

  4. Both a & b

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To understand the difference between session.load(Emp.class) and session.createCriteria(Emp.class), the user needs to know about Hibernate, an ORM (Object-Relational Mapping) framework that provides a way to map Java objects to database tables.

session.load(Emp.class) and session.createCriteria(Emp.class) are two different ways to retrieve data from the database using Hibernate.

session.load(Emp.class) is used to load an object from the database using its identifier. It returns a proxy object of the requested entity and the actual database query is executed only when the proxy object is accessed for the first time. If the identifier is not found in the database, then it throws the ObjectNotFoundException exception.

On the other hand, session.createCriteria(Emp.class) is used to create a Criteria object that can be used to retrieve data from the database. It provides a way to construct a query using a set of criteria such as restrictions, projections, and ordering. It returns a list of objects that match the criteria specified in the query.

Now let's go through each option and explain why it is right or wrong:

A. a) On session close session.load() Emp Object unavailable to access: This option is partially correct. When the session is closed before accessing the Emp object loaded using session.load(), then the ObjectNotFoundException exception is thrown. However, the Emp object is still available to access until the session is closed.

B. b) On session close session.createCriteria() Emp unavailable to access: This option is incorrect. When the session is closed before accessing the Emp object retrieved using session.createCriteria(), then the LazyInitializationException exception is thrown. However, the Emp object is still available to access until the session is closed.

C. c) None: This option is incorrect. There is a difference between session.load() and session.createCriteria() as explained above.

D. Both a & b: This option is incorrect. Option A is partially correct and option B is incorrect.

Therefore, the correct answer is:

The Answer is: A

Multiple choice technology programming languages
  1. a) remove the object and its collections from the first level cache

  2. b) remove the object and its collections from the second level cache

  3. c) remove the object and its collections from the data base

  4. d) None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Hibernate, evict() removes an object and its associated collections from the first-level cache (session cache). This detaches the object from the session, making changes no longer tracked. It does NOT affect second-level cache or the database.

Multiple choice technology mainframe
  1. SUBSET FROM(IN1) TO(OUT1) INPUT REMOVE LAST = 1

  2. SUBSET FROM(IN1) TO(OUT1) INPUT REMOVE LAST(1)

  3. SUBSET FROM(IN1) TO(OUT1) INPUT REMOVE TRAILER

  4. All of the above

Reveal answer Fill a bubble to check yourself
B,C Correct answer
Explanation

Both B and C are correct methods to remove the last record from an input file. Option B uses REMOVE LAST(1) which explicitly removes the last 1 record. Option C uses REMOVE TRAILER which removes trailer records - if the last record is a trailer, this achieves the same result. Both syntaxes are valid in mainframe sort utilities like Easytrieve. Option A is incorrect because REMOVE LAST = 1 has incorrect syntax (should use parentheses, not equals).

Multiple choice technology databases
  1. a) Only local or packaged sub programs can be overloaded.

  2. b) Overloading allows different functions with the same name that differ only in their return types.

  3. c) Overloading allows different subprograms with the same number, type and order of the parameter.

  4. d) Overloading allows different subprograms with the same name and same number or type of the parameters.

  5. e) Overloading allows different subprograms with the same name but different in either number or type or order of parameter.

Reveal answer Fill a bubble to check yourself
A,E Correct answer
Explanation

Package overloading allows multiple subprograms with the same name if they differ in the number, type, or order of parameters (option E). Only local (private) subprograms within the package body or packaged subprograms in the specification can be overloaded (option A). Option B is false because subprograms cannot differ only in return type - the parameter signature must be different. Option C is false because identical parameters would create a duplicate, not an overload. Option D is false because the parameters must differ in some way.

Multiple choice technology mainframe
  1. OUTREC

  2. INREC

  3. OUTFIL

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

OUTFIL is the JCL statement used to create multiple output files from a single input file based on different conditions. It allows you to specify different INCLUDE/OMIT criteria and formatting for each output dataset. OUTREC and INREC are used for record formatting but not for creating multiple output files. OUTFIL can split data into different files using various selection criteria.