Skip to ContentGo to accessibility pageKeyboard shortcuts menu
OpenStax Logo

Practice Exercises

1 .
Research the data types of Java and C++. Write a summary outlining the differences and similarities between the two.
2 .
Explain the differences between pure compilation, pure interpretation, and hybrids of the two. Give the advantages and disadvantages of each methodology.
3 .
Programming for iPhone and programming for Android require different purpose-driven HLLs. List the HLLs used for each and summarize some of the differences between them.
4 .
What are some of the criteria for selecting among various HLLs? Describe these criteria.
5 .
Describe the purpose of an API and explain how the use of APIs can lead to faster development, increased readability, and less complexity.
6 .
The Python language controversially uses an indentation of a uniform number of spaces to construct code blocks in control statements and other structures. What are the arguments and pros and cons for using this technique instead of the usual curly braces? To illustrate your answer, please write a short program snippet that demonstrates the pros and cons of indentation (in Java) as compared to curly braces (in Python).
7 .
Write a conditional statement to determine if a variable is within a specific numerical boundary, and if so, multiply the number by 2, and if not, multiply the number by itself.
8 .
Research what Fibonacci numbers are. Write a recursive program that finds the Nth number of the Fibonacci sequence.
9 .
Interpret the following program snippet. What will the function return?
int main()
{
   int x = 1;
   int y = 7;

   if (x == 1 && y > 10)
   {
       return 0;
   }
   else if (x < 0 || y == x)
   {
       return 1;
   }
   else if (x != 0 && y == x)
   {
       return 2;
   }
   else if (x > 0 && (x != y || y > x))
   {
       return 3;
   }
   else
   {
       return 4;
   }
}
10 .
Write a do while loop that will execute five times.
11 .
Encapsulation is one of the three fundamental components of object-oriented programming. Write a summary which defines the term and explains the advantages of it. Please provide a code snippet that demonstrates poor usage of encapsulation and improve it to highlight the advantages of proper encapsulation.
12 .
Write a short program in JavaScript that asks the user to input the base and height of a triangle. Calculate the area of the triangle and print it back out.
13 .
One of the key features of OOP is inheritance. Research multiple inheritance and how Java and C++ differ when it comes to multiple inheritance. Why would restricting multiple inheritance be a good idea?
14 .
Research the synchronized keyword in Java. Implement a critical section of code in Java by using the synchronized keyword.
15 .
The back end of a conventional compiler differs from that of a JIT compiler. List the ways that they are different. Does their design add to their differences?
16 .
Implement a code block in C++ that is only “activated” when we are debugging the application using a preprocessor definition.
17 .
Run the program you wrote above in GDB. Explore setting breakpoints and setting watches on variables as they change. You can either download and install GDB on your computer or use the free online website that runs GDB for you.
Citation/Attribution

This book may not be used in the training of large language models or otherwise be ingested into large language models or generative AI offerings without OpenStax's permission.

Want to cite, share, or modify this book? This book uses the Creative Commons Attribution License and you must attribute OpenStax.

Attribution information
  • If you are redistributing all or part of this book in a print format, then you must include on every physical page the following attribution:
    Access for free at https://openstax.org/books/introduction-computer-science/pages/1-introduction
  • If you are redistributing all or part of this book in a digital format, then you must include on every digital page view the following attribution:
    Access for free at https://openstax.org/books/introduction-computer-science/pages/1-introduction
Citation information

© Oct 29, 2024 OpenStax. Textbook content produced by OpenStax is licensed under a Creative Commons Attribution License . The OpenStax name, OpenStax logo, OpenStax book covers, OpenStax CNX name, and OpenStax CNX logo are not subject to the Creative Commons license and may not be reproduced without the prior and express written consent of Rice University.