Skip to main content


Showing posts from April, 2017

Programming Language Concepts Questions/Answers Part 3

1. What is an associative array?
- An unordered collection of data elements that are indexed by keys.

2. Each element of an associative array is a pair consisting of a _______ and a _______.
- key and a value

3. True or False? Java supports associative arrays?
- True. As a matter of fact, Perl, Python, Ruby, C++, C# and F# do too.

4. What are associative arrays called in Perl?
- hashes

5. Why are associative arrays in Perl called hashes?
- Because their elements are stored and retrieved with a hash function

6. What character does a hash in Perl begin with?

7. In Perl, each key is a _____ and each value is a _______.
- string
- scalar

8. In Perl, subscripting is done using _______ and _______.
- braces and keys

9. In Perl, how are elements removed from hashes?
- using delete

10. In Perl, the ________ operator tests whether a particular value is a key in a hash.
- exists

11. What are associative arrays called in Python?
- dictionaries

12. What is a difference between Python’s dictiona…

When does Garbage Collection run in Java?

First, we cannot force garbage collection to run (System.gc()). Sometimes it will but it’s unpredictable.

What are the steps to Garbage Collection in Java?

Mark: GC walks through the object graph and marks the objects that are reachable as liveSweep: deletes unreachable objectsCompact: compacts the memory by moving around the objects
GC collectors are called generational collectors since the heap is divided into 2 spaces: Young and old generation spaces. Young generation is for new objects and is divided into Eden, “Survivor 0” and “Survivor 1” spaces.

Old generation holds objects that survive for a long time.

Minor garbage collection runs in the Young Generation space. Major garbage collection runs across the entire heap.

Steps to GC:

As your application runs, new objects get allocated to the Eden space.Some objects become unreachable.When the Eden space becomes full, and your application tries to create another object, and the JVM tries to allocate space on the Eden, the allocation fa…

C/C++ pointer vs C++ reference vs Java reference

To declare a pointer in C++, you would use an asterisk symbol next to your pointer name. To illustrate this, when declaring a regular int scalar variable, you might enter the following:

int a;

When declaring a pointer “b”, you’ll proceed by entering:

int* b;

As you can see, the pointer variable contains the asterisk symbol.

Let’s look at the memory to see what just happened. For the scalar variable int “a”, 4 bytes of memory were reserved. If you look at the representation below, you’ll see that int “a” was in fact assigned 4 bytes of memory and is located at memory address 0x34 (just a random memory address).

If we were to assign a value to the scalar variable “a”, the reserved space will be modified to include the value directly. This can be seen below:

int a = 5; // 5 in binary is 00000101

The rest of the bytes are padded with zeros. Why? Down the line you may want to modify the integer value. It has to make sure that it supports the predefined integer range, which happens to be -2,14…

Programming Language Concepts Questions/Answers Part 2

The following deals with questions/answers you may encounter when asked about:

Lexical and Syntax AnalysisNames, Bindings and ScopesData Types
1. What are the 3 approaches to implementing programming languages? - Compilation, Pure Interpretation and Hybrid Implementation
2. What is the job of the syntax analyzer? - Check the syntax of the program and create a parse tree.
3. What are the syntax analyzers based on? - Formal description of the syntax of programs, usually BNF.
4. What are some of the advantages of using BNF?
- Descriptions are clear and concise. - Syntax analyzers can be generated directly from BNF. - Implementations based on BNF are easy to maintain.
5. What are the 2 distinct parts of syntax analysis and what do they do? - Lexical analysis: deals with small-scale language constructs such as names - Syntax analyzer: deals with large-scale constructs such as expressions
6. What are the 3 reasons for why lexical analysis is separated from syntax analysis? - Simplicity, Effi…