Java Programming Chapters 1-3 Quiz
78 Questions
100 Views

Java Programming Chapters 1-3 Quiz

Created by
@EnthralledSaxhorn

Questions and Answers

Java source files end with the .class extension.

False

What type of memory is RAM?

A volatile type of memory, used only for temporary storage

What is the purpose of validating the results of the program?

Determine if the program solves the original problem

What do the methods that operate on the data allow?

<p>An object typically hides its data, but allows outside code to access</p> Signup and view all the answers

How many bits are in a byte?

<p>8</p> Signup and view all the answers

What does software refer to?

<p>Programs</p> Signup and view all the answers

What are symbolic names made by the programmer that represent locations in the computer's RAM?

<p>Variables</p> Signup and view all the answers

A(n) ____ is a software entity that contains data and procedures.

<p>Object</p> Signup and view all the answers

What was the original name for Java?

<p>Oak</p> Signup and view all the answers

What is a computer program?

<p>A set of instructions that enable the computer to solve a problem or perform a task</p> Signup and view all the answers

Encapsulation refers to the combining of data and code into a single object.

<p>True</p> Signup and view all the answers

What is a special language used to write computer programs?

<p>Programming language</p> Signup and view all the answers

What are byte code instructions?

<p>Read and interpreted by the JVM</p> Signup and view all the answers

What is the data contained in an object known as?

<p>Attributes</p> Signup and view all the answers

The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.

<p>True</p> Signup and view all the answers

What does application software refer to?

<p>The programs that make the computer useful to the user</p> Signup and view all the answers

What is a set of programming language statements that, together, perform a specific task?

<p>Procedure</p> Signup and view all the answers

Because Java byte code is the same on all computers, compiled Java programs are highly portable.

<p>True</p> Signup and view all the answers

Application software refers to programs that make the computer useful to the user.

<p>True</p> Signup and view all the answers

____ is a cross between human language and a programming language.

<p>Pseudocode</p> Signup and view all the answers

Whereas ____ is centered on creating procedures, ___ is centered on creating objects.

<p>Procedural programming = object-oriented programming</p> Signup and view all the answers

What is syntax?

<p>Rules that must be followed when writing a program</p> Signup and view all the answers

A characteristic of ___ is that only an object's methods are able to directly access and make the changes to the object's data.

<p>Data hiding</p> Signup and view all the answers

One of the design tools used by programmers when creating a model of the program is

<p>Pseudocode</p> Signup and view all the answers

A runtime error is usually the result of

<p>A logical error</p> Signup and view all the answers

What are variables of the boolean data type useful for?

<p>Evaluating conditions that are either true or false</p> Signup and view all the answers

Variables are classified according to their?

<p>Data type</p> Signup and view all the answers

Which of the following statements will correctly convert the data type if x is a float and y is a double?

<p>X=(float)y;</p> Signup and view all the answers

What is a named storage location in the computer's memory?

<p>Variable</p> Signup and view all the answers

If you wish to use the System.out.printf method to print a string argument, use the ___ format specifier.

<p>%s</p> Signup and view all the answers

When saving a Java source file, save it with an extension of

<p>.java</p> Signup and view all the answers

The System.out.printf method allows you to format output in a variety of ways.

<p>True</p> Signup and view all the answers

What will be displayed when the following code is executed? final int x = 22, y = 4; y += x; System.out.println("x = " + x + " y = " + y);

<p>Nothing. There is an error in the code</p> Signup and view all the answers

Character literals are enclosed in ___, and string literals are enclosed in ____.

<p>single quotes, double quotes</p> Signup and view all the answers

Which of the following is not a valid Java comment?

<p><em>/ Comment /</em></p> Signup and view all the answers

The simplest way you can use the System.out.printf method is

<p>With only a format string, and no additional arguments</p> Signup and view all the answers

Identifiers can contain spaces.

<p>False</p> Signup and view all the answers

What will be the value of z as a result of executing the following code? int x=5, y=28; float z; z=(float)(y/x);

<p>5.0</p> Signup and view all the answers

Which of the following statements is invalid?

<p>double r = 2.9X106;</p> Signup and view all the answers

Named constants are initialized with a value and that value cannot change during the execution of the program.

<p>True</p> Signup and view all the answers

The primitive data types only allow a(n) ___ to hold a single value.

<p>Variable</p> Signup and view all the answers

What output will be displayed as a result of executing the following code? int x = 5, y = 20; x+= 32; y/= 4; System.out.println("x=" + x + ", y=" + y);

<p>x=37, y=5</p> Signup and view all the answers

What would be displayed as a result of the following code? int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house.");

<p>There are 5785 hens in the hen house.</p> Signup and view all the answers

What will be the value of z after the following statements have been executed? int x=4, y=33; double z; z=(double)(y/x);

<p>8.25</p> Signup and view all the answers

What is the result of the following expression?

<p>7</p> Signup and view all the answers

When you call one of the Scanner class's methods to read a primitive value, an annoying and hard-to-find problem can occur.

<p>True</p> Signup and view all the answers

In the following Java statement what value is stored in the variable name? String name="John Doe";

<p>The memory address where 'John Doe' is located</p> Signup and view all the answers

A Java program must have at least one

<p>Class definition</p> Signup and view all the answers

Both character literals and string literals can be assigned to a char variable.

<p>False</p> Signup and view all the answers

This is a value that is written into the code of a program.

<p>Literal</p> Signup and view all the answers

What is the following statement an example of? import java.util.Scanner;

<p>An explicit import statement</p> Signup and view all the answers

Both the things a class is responsible for knowing and the things a class is responsible for doing?

<p>A class's responsibilities include</p> Signup and view all the answers

When an object is created, the attributes associated with the object are called?

<p>Instance fields</p> Signup and view all the answers

To indicate the data type of a variable in a UML diagram, you specify?

<p>The variable name followed by a colon and the data type.</p> Signup and view all the answers

Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by?

<p>Using the private access specifier on the class fields.</p> Signup and view all the answers

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.

<p>Methods</p> Signup and view all the answers

The scope of a local variable is?

<p>The method in which they are defined.</p> Signup and view all the answers

What is the following statement an example of? import java.util.*;

<p>A wildcard import statement</p> Signup and view all the answers

When an argument is passed by value,?

<p>The parameter variable holds a copy of the value passed to it.</p> Signup and view all the answers

UML diagrams do not contain object names.

<p>True</p> Signup and view all the answers

A method may have zero or more parameter variables.

<p>True</p> Signup and view all the answers

In UML diagrams, what symbol indicates that a member is public?

<ul> <li></li> </ul> Signup and view all the answers

Another term for an object of a class is a(n)?

<p>Instance</p> Signup and view all the answers

What does the keyword new do?

<p>Creates an object in memory.</p> Signup and view all the answers

One or more objects may be created from a(n)?

<p>Class</p> Signup and view all the answers

In the blueprint/house analogy, think of a class as a blueprint that describes a house and ________ as instances of the house built from the blueprint.

<p>Objects</p> Signup and view all the answers

What is a group of related classes called?

<p>Package</p> Signup and view all the answers

Which of the following is not involved in finding the classes when developing an object-oriented application?

<p>False</p> Signup and view all the answers

You should not define a class field that is dependent upon the values of other class fields in order to?

<p>Avoid having stale data.</p> Signup and view all the answers

If you do not provide initialization values for a class's numeric fields, they will be automatically initialized with 0.

<p>True</p> Signup and view all the answers

It is common practice in object-oriented programming to make all of a class's?

<p>Fields private</p> Signup and view all the answers

After the header, the body of the method appears inside a set of?

<p>Braces, {}</p> Signup and view all the answers

A UML diagram uses the ________ symbol to indicate that a member is private.

<ul> <li></li> </ul> Signup and view all the answers

Methods that operate on an object's fields are called?

<p>Instance methods</p> Signup and view all the answers

For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; }

<p>False</p> Signup and view all the answers

What is import scanner?

<p>import java.util.Scanner;</p> Signup and view all the answers

What is the declaration for scanner?

<p>Scanner anyName = new Scanner(System.in);</p> Signup and view all the answers

How do you close the scanner?

<p>anyName.close();</p> Signup and view all the answers

Study Notes

Java Basics

  • Java source files utilize the .java extension; .class is for bytecode.
  • RAM (Random Access Memory) is a volatile memory used for temporary data storage.
  • Validating program results ensures that it effectively solves the intended problem.

Object-Oriented Programming

  • Objects encapsulate data and methods, hiding internal data while providing access through defined procedures.
  • Variables serve as symbolic names representing locations in a computer's memory.
  • Encapsulation combines data and functionality within a single unit, ensuring data security.

Programming Fundamentals

  • A computer program is a structured set of instructions that solve problems or perform tasks.
  • Software is a term used to describe programs executed by a computer.
  • Java bytecode is platform-independent, leading to high portability across different systems.

Data Types and Variables

  • Variables can hold data classified by their data types, including primitive data types that store single values.
  • Boolean variables evaluate conditions as true or false, essential for control flow in programming.

Java Syntax and Identifiers

  • Syntax comprises specific rules programming code must adhere to; identifiers cannot contain spaces.
  • Named constants in Java are immutable once initialized, providing stability in code.

Exception Handling

  • A runtime error often results from logical errors in code execution.
  • Understanding how errors manifest helps in debugging Java applications effectively.

Program Structures

  • The UML (Unified Modeling Language) diagram indicates relationships between classes, identifying attributes and methods.
  • A class definition is fundamental for creating objects, establishing a blueprint for data structure and functionality.

Input and Output Management

  • The System.out.printf method formats output, and the simplest usage requires only a format string.
  • User input handling often involves the Scanner class, a common approach for reading data in Java applications.

Scoping and Accessibility

  • Local variables' scope is restricted to the method in which they are defined.
  • Data hiding ensures object fields are protected from outside interference, promoting encapsulation principles.

Class Relationships

  • A class may produce multiple object instances, referred to as instances.
  • Packages group related classes, enhancing organization within the programming structure.

Best Practices in Programming

  • Following conventions, such as keeping fields private, enhances data security.
  • Avoid defining class fields based on others to maintain clean, understandable code.

Fundamental Operations

  • An implicit conversion of data types can be performed while assigning values.
  • The keyword new is crucial for object instantiation in memory.

Summary of Common Features

  • Comments serve as documentation within code but cannot be enclosed improperly.
  • Understanding the context of variable manipulations is essential for predictable program behavior.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Test your knowledge with this quiz covering Chapters 1-3 of Java programming. The questions focus on basic concepts such as file extensions, memory types, and program validation. Perfect for beginners looking to strengthen their understanding of Java fundamentals.

More Quizzes Like This

Use Quizgecko on...
Browser
Browser