Question

In: Computer Science

1.) Many languages (e.g., C and Java) distinguish the character ’c’ from the string “c” with...

1.) Many languages (e.g., C and Java) distinguish the character ’c’ from the string “c” with separate sets of quotation marks. Others (e.g., Python) use “c” for both single characters and strings of length one. Provide (and justify) one advantage and one disadvantage of Python’s approach.

2.The designers of Java distinguish the primitive types (scalars) from the reference types (all other types of values) in the language. Discuss the costs and benefits to the programmer of this decision

3.In Ruby, the Hash class accepts the “each” method, allowing hashes to be interacted over, like a collection. In Java, however, the Map classes are not formally part of the JCF (Java Collections Framework). For both Ruby and Java, provide (and justify) an advantage of the language’s choice of location in the class hierarchy of its form of associative list

4.What are the basic differences, if any, in how Java and Ruby handle information hiding (a.k.a. encapsulation)?

5. Java and C++ support generic collections with type parameters, whereas Ruby does not. Does that fact place the Ruby programmer at a disadvantage? Why or why not?

Solutions

Expert Solution

Multiple questions posted, first two questions are answered below, please comment if any doubts:

1.

Advantage of using double quotes for character and single character string python:

  • The characters are basic units of strings so by using double quotes for both character and string will ease the programming practice.
    • Both the character and strings represented using the double quotes will reduce the complexity of the programming since the extraction of characters from the string and concatenating character with the strings will be more easy.

Disadvantage of using double quotes for character and single character string python:

  • In the programs that concentrated on the character based processing will take more memory and processing time compared to character based operation.
    • In python the characters are also stored as string, this makes higher use of memory, thus the character based larger programs will suffer the execution and memory usage abnormalities.

2.

By distinguishing primitive types from reference types the cost of the program can be reduced in terms of memory usage and execution time. The primitive types used very less memory compared to reference types. Thus this distinguish ion will make the use of low memory usage primitive scalars whenever it is required by replacing reference types for all the usages. Thus the programmer will get the enhanced depth in the usage of data types in the program. The complexity of the program can be reduced and also the object oriented approach can be improved.


Related Solutions

1.In C++, C#, Java. Discuss string operations functions, with examples. Then make Comparison of programming languages  ...
1.In C++, C#, Java. Discuss string operations functions, with examples. Then make Comparison of programming languages   2.String and StringBuffer (C#, Java) with examples.
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
(In JAVA)Write code to print the location of any alphabetic character in the 2-character string passCode.
Java Language Write code to print the location of any alphabetic character in the 2-character string passCode. Each alphabetic character detected should print a separate statement followed by a newline. Ex: If passCode is "9a", output is: Alphabetic at 1 import java.util.Scanner;   public class FindAlpha {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String passCode;              passCode = scnr.next();     ...
Design and construct a computer program in one of the approved languages (C, C++, C#, Java,...
Design and construct a computer program in one of the approved languages (C, C++, C#, Java, Pascal, Python, etc.) that will illustrate the use of a fourth-order explicit Runge-Kutta method of your own design. In other words, you will first have to solve the Runge-Kutta equations of condition for the coefficients of a fourth-order Runge-Kutta method. Then, you will use these coefficients in a computer program to solve the ordinary differential equation below. Be sure to follow the documentation and...
C++, Write a function, noPunct, that would take a string, go through the string character by...
C++, Write a function, noPunct, that would take a string, go through the string character by character, and push any character that is NOT a punctuation mark onto a stack but count the punctuation dropped. After going through the entire string, print the contents of the stack. Then print the number of punctuation dropped. Hint: use ispunct() library function (returns true if character is punctuation)
How To Print Nice Padding Character in a String in C++? 1. User input the width...
How To Print Nice Padding Character in a String in C++? 1. User input the width = 14 2. User input the padding character = + Example output: ++Hello World++ Thanks in advance.
(In java) Return a copy of the string with only its first character capitalized. You may...
(In java) Return a copy of the string with only its first character capitalized. You may find the Character.toUpperCase(char c) method helpful NOTE: Each beginning letter of each word should be capitalized. For example, if the user were to input: "United States of America " --> output should be "United States of America" NOT "United states of america" -------------------------------------- (This code is given) public class Class1 { public static String capitalize(String str) {     //add code here } }
Write a basic C++ program with function, whose input is a character and a string, and...
Write a basic C++ program with function, whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n...
Java, Python, and C++ are three of the most useful programming languages to learn. Compare the...
Java, Python, and C++ are three of the most useful programming languages to learn. Compare the functionalities of all three programming languages. Why would you choose one language over another? Provide code examples demonstrating their usefulness in a real-world scenario.
In objective-C Task: Write a program whose input is a character and a string, and whose...
In objective-C Task: Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1.You may assume that the string does not contain spaces and will always contain less than 50 characters. Ex: If the input is: n Monday the output is:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT