Friday, June 28, 2013

KBP - Chapter 16

Review Question

2. Two parts of a compound term are:  a functor, which is the function symbol that names the relation, and an ordered list of parameters, which together represent an element of the relation.

3. Propositions can be stated in two modes: one in which the proposition is defined to be true, and one in which the truth of the proposition is something that is to be determined. In other words, propositions can be stated to be facts or queries.

5. Antecedents are the right side of clausal form propositions, whereas Consequents are the left side of clausal form propositions, because it is the consequence of the truth of the antecedent.

8. The basic concept of this semantics is that there is a simple way to determine the meaning of each statement, and it does not depend on how the statement might be used to solve a problem.

10. Three forms of prolog term : 
  - Constant
  - Variable
  - Structure

13. Conjunctions : contain multiple terms that are separated by logical AND operations.

___________________________________________________

Problem Set

1.”All predicate calculus propositions can be algorithmically converted to clausal form”. Is this statement true or false?

This statement is true. Nilsson (1971) gives proof that this can be done, as well as a simple conversion algorithm for doing it.

2. Describe how a logic programming language is different from a general programming language.

Programming that uses a form of symbolic logic as a programming language, unlike other general programming language, is often called logic programming; languages based on symbolic logic are called logic programming languages, or declarative languages.

10.  Using the internet for reference, find some of the applications of expert systems.

 - Expert system in healthcare: The Electronic health record (EHR) is designed to replace the traditional medical and bring together a more versatile, expansive and robust expert system to provide greater quality care.

 - Expert systems in the financial field: Loan departments are interested in expert systems for morgages because of the growing cost of labour, which makes the handling and acceptance of relatively small loans less profitable.

 - A new application for expert systems is automated computer program generation. Funded by a US Air Force grant, an expert system-based application (hprcARCHITECT) that generates computer programs for mixed processor technology (FPGA/GPU/Multicore) systems without a need for technical specialists has recently been commercially introduced

KBP - Chapter 15

Review Question

3. Atoms and lists.

6. A list which membership of a given atom in a given list that does not include sublists.

7. REPL stand for read-evaluate-print loop.

8. Three parameters to IF are: a predicate expression, a then expression, and an else expression.

27. Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstr

29. Curried function let new functions can be constructed from them by partial evaluation.uction.

35. A language is nonstrict if it does not have the strict requirement.

___________________________________________________

Problem Set

2.  Give the general form of function declaration in ML.

Function declarations in ML appear in the general form
fun function_name( formal parameters ) = expression;

8. How is the functional operator pipeline ( |> ) used in F#?

The pipeline operator is a binary operator that sends the value of its left operand, which

is an expression, to the last parameter of the function call, which is the right operand. It is

used to chain together function calls while flowing the data being processed to each call.

9. What does the following Scheme function do?

(define (y s lis)

(cond

((null? lis) ‘() )

((equal? s (car lis)) lis)

(else (y s (cdr lis)))

))

y returns the given list with leading elements removed up to but not including the first

occurrence of the first given parameter.

KBP - Chapter 14

Review Question

2. An exception is raised when its associated event occurs.

3. Advantages to having exception handling built into a language :
Without exception handling, the code required to detect error conditions can considerably clutter a program, save development costs, program size, and program complexity
7. All of them are gathered together in an exception clause.

10. Four exceptions defined in the default package, Standard :
  - Constraint_Error
  - Program_Error
  - Storage_Error
  - Tasking_Error

12. Disabling run-time checks

15. Container classes.

18. After a handler has completed its execution, control flows to the first statement following the try construct

___________________________________________________
Problem Set

1. The early programming languages, when the error occurs, the error is transferred to the operating system. The typical OS reaction to a run-time error is to display a diagnostic message.
2. Java compilers usually generate code to check the correctness of every subscript expression. In C subscript ranges are not checked because the cost of such checking was not believed to be worth the benefit of detecting such errors
4.   What are the different approaches to handle checked exception in Java?

In Java there are basically two types of exceptions: Checked exceptions and unchecked exceptions.

Checked exceptions must be explicitly caught or propagated as described in Basic try-catch-finally Exception Handling. Unchecked exceptions do not have this requirement. They don’t have to be caught or declared thrown.
Checked exceptions in Java extend the java.lang.Exception class. Unchecked exceptions extend the java.lang.RuntimeException.

14.  Summarize the arguments in favor of the termination and resumption models of continuation.

The resumption model is useful when the exception is only an unusual condition, rather than an error. The termination model is useful when the exception is an error and it is highly unlikely that the error can be corrected so that execution could continue in some useful way.

KBP - Chapter 13

Review Question

1. Three possible levels of concurrency in programs:
 - instruction level (executing two or more machine instructions simultaneously),
 - statement level (executing two or more high-level language statements simultaneously)
 - unit level (executing two or more subprogram units simultaneously)

2. In an SIMD computer, each processor has its own local memory. One processor controls the operation of the other processors. Because all of the processors, except the controller, execute the same instruction at the same time, no synchronization is required in the software.

5. Unit-level concurrency is best supported by MIMD computers.

6. Vector processor have groups of registers that store the operands of a vector operation in which
the same instruction is executed on the whole group of operands simultaneously.

8. A scheduler manages the sharing of processors among the tasks. If there were never any interruptions and tasks all had the same priority, the scheduler could simply give each task a time slice, such as 0.1 second, and when a task’s turn came, the scheduler could let it execute on a processor for that amount of time.

12. What is a heavyweight task? What is a lightweight task?
Tasks fall into two general categories: heavyweight and lightweight. Simply stated, a heavyweight task executes in its own address space. Lightweight tasks all run in the same address space. It is easier to implement lightweight tasks than heavyweight tasks. Furthermore, lightweight tasks can be more efficient than heavyweight tasks, because less effort is required to manage their execution.

16. A task descriptor is a data structure that stores all of the relevant information about the execution state of a task.

18. The purpose of a task-ready queue is to be storage of tasks that are ready to run.

21. A binary semaphore is a semaphore that requires only a binary-valued counter.

A counting semaphore is a synchronization object that can have an arbitrarily large number of states.

30. Ada terminate clause, when selected, means that the task is finished with its job but is not yet terminated. Task termination is discussed later in this section.

34. Sleep method in Java blocks the the thread.

35. Yield method in Java surrenders the processor voluntarily as a request from the running thread.

36. The join method in Java is used to force a method to delay its execution until the run method of another thread has completed its execution.

55. Concurrent ML is an extension to ML that includes a fform of threads and a form of synchronous message passing to support concurrency.

56. The use of spawn primitive of CML is to take the function as its parameter and to create a thread.

63. The FORALL statement of High-Performance Fortran is to specifies a sequence of assignment statements that may be executed concurrently.

___________________________________________________
Problem Set

Review Question

1. Three possible levels of concurrency in programs:
• instruction level (executing two or more machine instructions simultaneously),
• statement level (executing two or more high-level language statements simultaneously)
• unit level (executing two or more subprogram units simultaneously)

2. In an SIMD computer, each processor has its own local memory. One processor controls the operation of the other processors. Because all of the processors, except the controller, execute the same instruction at the same time, no synchronization is required in the software.

5. Unit-level concurrency is best supported by MIMD computers.

6. Vector processor have groups of registers that store the operands of a vector operation in which
the same instruction is executed on the whole group of operands simultaneously.

7. Physical concurrency is several program units from the same program that literally execute simultaneously.

Logical concurrency is multiple processors providing actual concurrency, when in fact the actual execution of programs is taking place in interleaved fashion on a single processor.

8. A scheduler manages the sharing of processors among the tasks. If there were never any interruptions and tasks all had the same priority, the scheduler could simply give each task a time slice, such as 0.1 second, and when a task’s turn came, the scheduler could let it execute on a processor for that amount of time.

16. A task descriptor is a data structure that stores all of the relevant information about the execution state of a task.

18. The purpose of a task-ready queue is to be storage of tasks that are ready to run.

21. A binary semaphore is a semaphore that requires only a binary-valued counter.

A counting semaphore is a synchronization object that can have an arbitrarily large number of states.

30. Ada terminate clause, when selected, means that the task is finished with its job but is not yet terminated. Task termination is discussed later in this section.

34. Sleep method in Java blocks the the thread.

35. Yield method in Java surrenders the processor voluntarily as a request from the running thread.

36. The join method in Java is used to force a method to delay its execution until the run method of another thread has completed its execution.

55. Concurrent ML is an extension to ML that includes a fform of threads and a form of synchronous message passing to support concurrency.

___________________________________________________
Problem Set

1. Explain clearly why a race condition can create problems for a system.

Race condition can create problems for a system, because two or more tasks are racing to use the shared resource and the behavior of the program depends on which task arrives first (and wins the race).

2. The different ways to handle deadlock:
 - Ignoring deadlock
 - Detection
 - Prevention
 - Avoidance

3. Busy waiting is a method whereby a task waits for a given event by continuously checking for that event to occur. What is the main problem with this approach?

Busy-waiting or spinning is a technique in which a process repeatedly checks to see if a condition is true, such as whether keyboard input or a lock is available. Spinning can also be used to generate an arbitrary time delay, a technique that was necessary on systems that lacked a method of waiting a specific length of time. Processor speeds vary greatly from computer to computer, especially as some processors are designed to dynamically adjust speed based on external factors, such as the load on the operating system. Busy waiting may loop forever and it may cause a computer freezing.

KBP - Chapter 12

Review Question

2.   The problems associated with programming using abstract data types are:

• In nearly all cases, the features and capabilities of the existing type are not quite right for the new use.

• The type definitions are all independent and are at the same level.

3.   The advantage of inheritance is inheritance offers a solution to both the modification problem posed by abstract data type reuse and the program organization problem. If a new abstract data type can inherit the data and functionality of some existing type, and is also allowed to modify some of those entities and add new entities, reuse is greatly facilitated without requiring changes to the reused abstract data type.

4.   Message protocol is the entire collection of methods of an object.

6. Describe a situation where dynamic binding is a great advantage over its absence.
- There is a base class, A, that defines a method draw that draws some figure associated with the base class. A second class, B, is defined as a subclass of A. Objects of this new class also need a draw method that is like that provided by A but a bit different. With overriding, we can directly modify B’s draw function. But without it, we either make a specific function in A for B and inherit it.

7.   Dynamic dispatch is the third characteristic (after abstract data types and inheritance) of object-oriented programming language which is a kind of polymorhphism provided by the dynamic binding of messages to method definitions.

8.   An abstract method is an implemented method which all of descendant class should have and it is included in Building.

An abstract class is  a class that includes at least one abstract method.

10.  An inner class is  a nonstatic class that is nested directly in another class.

12.  All Smalltalk objects are allocated from the heap and are referenced through reference variables, which are implicitly dereferenced.

15.  Smalltalk supports single inheritance; it does not allow multiple inheritance.

19.  C++ heap-allocated objects are deallocated using destructor.

29.  No Objective-C doesn’t support it. Objective-C only supports single inheritance.

31.  The root class in Objective-C is called NSObject

38.  Boxing is primitive values in Java 5.0+ which is implicitly coerced when they are put in object context. This coercion converts the primitive value to an object of the wrapper class of the primitive value’s type.

49.  Access control in Ruby is different for data than it is for methods. All instance data has private access by default, and that cannot be changed. If external access to an instance variable is required, accessor methods must be defined.

___________________________________________________
Problem Set

2.    In what ways can “compatible “ be defined for the relationship between an overridden method and the overriding method?

Every overriding method must have the same number of parameters as the overridden method and the types of the parameters and the return type must be compatible with those of the parent class.

3.   Compare the inheritance of C++ and Java.

• In Java, all objects are Inherited, either directly or indirectly. While in C++ a class can be defined to stand on its own without an ancestor.

•  The meaning of protected member access specifier is somewhat different in Java. In Java, protected members of a class “A” are accessible in other class “B” of same package, even if B doesn’t inherit from A (they both have to be in the same package).

•  Java uses extends keyword for inheritence. Unlike C++, Java doesn’t provide an inheritance specifier like public, protected or private. Therefore, we cannot change the protection level of members of base class in Java, if some data member is public or protected in base class then it remains public or protected in derived class. Like C++, private members of base class are not accessible in derived class. Unlike C++, in Java, we don’t have to remember those rules of inheritance which are combination of base class access specifier and inheritance specifier.

5.    Compare abstract class and interface in Java.

• First and major difference between abstract class and interface is that, abstract class is a class while interface is a interface, means by extending abstract class you can not extend another class because Java does not support multiple inheritance but you can implement multiple inheritance in Java.
• Second difference between interface and abstract class in Java is that you can not create non abstract method in interface, every method in interface is by default abstract, but you can create non abstract method in abstract class. Even a class which doesn’t contain any abstract method can be abstract by using abstract keyword.
• Third difference between abstract class and interface in Java is that abstract class are slightly faster than interface because interface involves a search before calling any overridden method in Java. This is not a significant difference in most of cases but if you are writing a time critical application than you may not want to leave any stone unturned.
• Fourth difference between abstract class vs interface in Java is that, interface are better suited for Type declaration and abstract class is more suited for code reuse and evolution perspective.
• Another notable difference between interface and abstract class is that when you add a new method in existing interface it breaks all its implementation and you need to provide an implementation in all clients which is not good. By using abstract class you can provide default implementation in super class.

7.   What is one programming situation where multiple inheritance has a significant disadvantage over interfaces?

A situation when there are two classes derived from a common parent and those two derived class has one child.

9.   Give an example of inheritance in C++, where a subclass overrides the superclass methods.

class Enemy{

protected:

int Hp;

public:

void attack(){

cout<<”Enemy Attacks using GUN!!”<<endl;
}
};

class BossEnemy: public Enemy{

public:

void attack(){

cout<<”Boss Enemy attacks using MAGIC!!”<<endl;
}
};

10.  Explain one advantage of inheritance.

One of the key benefits of inheritance is to minimize the amount of duplicate code in an application by sharing common  code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be  refactored to move the common code up to a mutual superclass. This also tends to result in a better organization of  code and smaller, simpler compilation units.

17.  What are the different options for object destruction in Java?

There is no explicit deallocation operator. A finalize method is implicitly called when the garbage collector is about to reclaim the storage occupied by the object.

KBP - Chapter 11

Review Question

1. Two kinds of abstractions in programming languages are process abstraction and data abstraction.

2. Define abstract data type.
An abstract data type is a data structure, in the form of a record, but which includes subprograms that manipulate its data.
Syntactically, an abstract data type is an enclosure that includes only the data representation of one specific data type and the subprograms that provide the operations for that type.

5. The first design issue for abstract data types is the form of the container for the interface to the type. The second design issue is whether abstract data types can be parameterized. The third design issue is what access controls are provided and how such controls are specified.

6. Explain how information hiding is provided in an Ada package.
There are two approaches to hiding the representation from clients in the package specification. One is to include two sections in the package specification—one in which entities are visible to clients and one that hides its contents.

9. Package specification, is an Ada package which provides the interface of the encapsulation (and perhaps more).
Body package, is an Ada package which provides the implementation of most, if not all, of the entities named in the associated package specification.

10. The ‘with’ clause in Ada makes the names defined in external packages visible.

15. The purpose of a C++ destructor is to deallocate heap space (memory) that the object or class used.

16. A destructor has no return types.

20. Limited private types are useful when the usual predefined operations of assignment and comparison are not meaningful or useful.

21. Intializers in Objective-C are constructors.

26. The purpose of a Destructor is usually to clear off unused variables and clean up the memory. Java has in built memory handling mechanisms (Garbage collection) that clear off unused memory automatically. Hence there is no requirement for destructor methods. So that Java doesn’t need any destructor

27. Methods in Java must be defined completely in a class.

28. Java classes are allocated from the heap and accessed through reference variables.

___________________________________________________
Problem Set

2. Suppose someone designed a stack abstract data type in which the function top returned an access path (or pointer ) rather than returning a copy of the top element. This is not a true data abstraction. Why ? Give an example that illustrates the problem.

- The problem with this is that the user is given access to the stack through the returned value of the “top” function. For example, if p is a pointer to objects of the type stored in the stack, we could have:

p = top(stack1);

*p = 42;

These statements access the stack directly, which violates the principle of a data abstraction.

4. The advantages of the nonpointer concept in Java?

• There is no memory leak such as dangling pointers or unnamed variables.

KBP - Chapter 10

Review Question

1. By “simple” it means that subprograms cannot be nested and all local variables are static

2. Which of the caller of callee saves execution status information ?

-Either can save the execution status

3. Execution status information be stored for the linkage to a subprogram

4. What is the task of a linker?
Its first task is to find the files that contain the translated subprograms referenced in that program and load them into memory. Then, the linker must set the target addresses of all calls to those subprograms in the main program to the entry addresses of those subprograms.

6. What is the difference between an activation record and an activation record instance?
An activation record is the format, or layout, of the moncode part of a subprogram, whereas an activation record instance is a concrete example of an activation record, a collection of data in the form of an activation record.

8. What kind of machines often use registers to pass parameters?
RISC machines, parameters are passed in registers

11. What is an EP, and what is its purpose?
EP is a point or first address of the activation record instance of the main program. It is required to control the execution of a subprogram.

14. What are two potentialproblems with the static-chain method?
•  It is difficult for a programmer working on a time-critical program to estimate the costs of nonlocal references, because the cost of each reference depends on the depth of nesting between the reference and the scope of declaration.
•  Subsequent code modifications may change nesting depths, thereby changing the timing of some references, both in the changed code and possibly in code far from the changes.

___________________________________________________
Problem Set

6. Although local variables in Java methods are dynamically allocated at the beginning of each activation, under what circumstances could the value of a local variable in a particular activation retain the value of previous activation?
If the variable is declared as static. Static modifier is a modifier that makes a variable history – sensitive.

7. It is stated in this chapter that when nonlocal variables are accessed in a dynamic-scoped language using the dynamic chain, variable names must be stored in the activation records with the values. If this were actually done, every nonlocal access would require a sequence of costly string comparisons on names. Design an alternative to these string comparisons that would be faster.

Using approach that uses an auxiliary data structure called a display. Or, to write variable names as integers. These integers act like an array. So when the activation happens, the comparisons will be faster.

8.   Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Hint:Consider the way the correct activation record instance of the static parent of a newly enacted procedure is found(see Section 10.4.2).

Based on the hint statement, the target of every goto in a program could be represented as an address and a nesting_depth, where the nesting_depth is the difference between the nesting level of the procedure that contains the goto and that of the procedure containing the target. Then, when a goto is executed, the static chain is followed by the number of links indicated in the nesting_depth of the goto target. The stack top pointer is reset to the top of the activation record at the end of the chain.

9.   The static-chain method could be expanded slightly by using two static links in each activation  record instance where the  second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?

Including two static links would reduce the access time to nonlocals that are defined in scopes two steps away to be equal to that for nonlocals that are one step away. Overall, because most nonlocal references are relatively close, this could significantly increase the execution efficiency of many programs.

11.    If a compiler uses the static chain approach to implementing blocks, which of the entries in the activation records for subprograms are needed in the activation records for blocks?

There are two options for implementing blocks as parameterless subprograms: One way is to use the same activation record as a subprogram that has no parameters. This is the most simple way, because accesses to block variables will be exactly like accesses to local variables. Of course, the space for the static and dynamic links and the return address will be wasted. The alternative is to leave out the static and dynamic links and the return address, which saves space but makes accesses to block variables different from subprogram locals.

KBP - Chapter 9

Review Question

1.   What are the three general characteristics of subprograms?

• Each subprogram has a single entry point.
• The calling program unit is suspended during the execution of the called subprogram, which implies that there is only one subprogram in execution at any given time.
• Control always returns to the caller when the subprogram execution terminates.

2.   What does it mean for a subprogram to be active?

A subprogram is said to be active if, after having been called, it has begun execution but has not yet completed that execution.

7. What is a parameter profile? What is a subprogram protocol?

The parameter profile of a subprogram is the container of the number, order, and types of its formal parameters. While a subprogram protocol is subprogram’s parameter profile as well as its return type if it’s a function.

8.   What are formal parameters? What are actual parameters?

Formal parameters are The parameters in the subprogram header. They are sometimes thought of as dummy variables because they are not variables in the usual sense.
Actual parameters are a list of parameters to be bound to the formal parameters of the subprogram.

9.   What are the advantages and disadvantages of keyword parameters?

The advantage of keyword parameters is that they can appear in any order in the actual parameter list.
The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.

15. What are the three semantic models of parameter passing?

The three semantic models of parameter passing are:

In mode: formal parameters can receive data from te corresponding actual parameter
Out mode: formal parameters can transmit data to the actual parameter
Inout mode: do both of In mode and Out mode.
20. What is the parameter-passing method of Python and Ruby called?

The parameter-passing method of Python and Ruby is called passing-by-assignment. Because all data values are objects, every variable is a reference to an object. So, the actual parameter value is assigned to the formal parameter. Quite similar to pass-by reference.

23. What is automatic generalization?

Automatic generalization is the case in F# when for some functions F# infers a generic type for the parameters and the return value. This happens when the type inferencing system in F# cannot determine the type of parameters or the return tye of the function.

24. What is an overloaded subprogram?

An overloaded subprogram is a subprogram that has the same name as another subprogram in the same referencing environment.

34. What is a closure?

A closure is a subprogram and the referencing environment where it was defined.


___________________________________________________
Problem Set

3.   Argue in support of the templated functions of C++. How is it different from the templated functions of other languages?

It is different as C++ differentiates function based on overloading. It is not practical to make multiple function overloading in regard to writability and readability. Instead, creating a template allows a function to receive any datatype as long as the variation is based on the formal parameter definition.

7.   Consider the following program written in C syntax:
void fun(int first, int second){
first+=first;
second+=second;
}

void main(){
int list[2] = { 3 , 5 };
fun(list[0], list[1]);
}
 for each of the following parameter-passing methods, what are the values of the list array after execution?
a. Passed by value :  list[2] = {3,5}
b. Passed by reference : list[2] = {6,10}
c. Passed by value-result : list[2] = {6,10}

15. How is the problem of passing multidimensional arrays handled by Ada?

Ada compilers are able to determine the defined size of the dimension of all arrays that are used as parameters at the time of subprograms are compiled.

KBP - Chapter 8

Review Question

1. A control structure is a control statement and the collection of statements whose execution it controls.

2. They proved that all algorithms that can be expressed by flowcharts can be coded in a programming language with only two control statements: one for choosing between two control flow paths and one for logically-controlled iterations.

6. Python uses indentation to specify control statements and using a colon instead of then for a then clause.

12. It was based on multiple selection statement in ALGOL 68, which doesn’t have implicit branches from selectable segments.

19. In Python, range function does the most simple counting loops. The function takes 1, 2, or 3 variables. If range function has 1 variable (let’s say n), then it returns 0, 1, …, n. If range function has 2 variables (let’s say m and n), then it returns m, m+1, m+2, … , n-1. If range function has 3 variables, however (let’s say m,n,d) then it returns m, m+d, up before it goes to larger or equal to n.

25. What are the differences between the break statement of C++ and that of Java?


C++ has unconditional unlabeled exit with name break, while Java has unconditional labeled exit with the same name. C++ can only break the loop in which the break scope it was in, while Java can break straight to any targeted loop.

___________________________________________________
Problem Set

1. What design issues should be considered for two-way selection statements?

The design issues are:

What is the form and type of the expression that controls the selection?
How are then and else clauses specified?
How should the meaning of nested selectors be specified?
2. Python uses indentation to specify compound statements. Give an example in support of this statement.

Example:

if x>y:

x=y

print “case 1”

6. In C language, a control statement can be implemented using a nested if else, as well as by using a switch statement. Make a list of differences in the implementation of a nested if else and a switch statement. Also suggest under what circumstances the if else control structure is used and in which condition the switch case is used.

Switch

More compact than lots of nested if else, therefore it has more readability.
Not quite flexible, as in some languages it can only available to certain (even sometimes should be similar) data types.
If-else

Allows more complex expressions and various possible data types as conditions.
Quite hard to read when it’s too nested.
Switch statement is used to check mostly when a certain variable is equal to a certain value. Example, to check whether variable a is equal to 1, 2, 3, or 4. Other example may be to check whether the choice of variable x is equal to ‘y’ or ‘n’. Switch(x){ case ‘y’: statement1; case ‘n’: statement2}

If-else, on the other hand, can be more practical, especially if the programmer wants to check a certain condition is true while the program is running. Example, checking whether variable var is smaller than 10. If (var<10){statement1} else {statement2}.

 11. Explain the advantages and disadvantages of the Java switch statement, compared to C++’s switch statement.


Java’s variable in the argument of a switch statement can be of integeral type (byte, short, int, etc), char, and String (JDK 1.7 and newer versions), but C++ can only be int or char.