CS1302 Exam 1:

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which of the command-line options were used to produce the following output for ls? Select all that apply. Not sure? Try it on Odin! total 16 drwxr-xr-x 2 mec grad 4096 Jan 8 14:56 . drwxr-xr-x 3 mec grad 4096 Jan 8 14:56 .. -rw-r--r-- 1 mec grad 11 Jan 8 14:56 README.txt -rw-r--r-- 1 mec grad 0 Jan 8 14:56 RickRoll.mp3 -rw-r--r-- 1 mec grad 16 Jan 8 14:56 TODO.txt -l -m -a -h

-l and -a We need -a because there are some hidden files included in the output.

Assume we have two disparate classes, Turtle and Hare, which implement Movable but are otherwise unrelated. Which of the following are valid? Select all that apply. Movable t = new Turtle(); Turtle t = new Movable(); Hare h = new Turtle(); Movable h = new Hare();

1, 2, 4

Which of the following can be used to open file1.txt and file2.txt in the Emacs text editor at the same time? Select all that apply. 1) Type the following command: $ emacs file1.txt file2.txt 2) Type the following command: $ EMACS file2.txt file1.txt 3) Launch Emacs, then type the following set of commands: C-x C-f file1.txt C-x 2 C-x o C-x C-f file2.txt 4) Launch Emacs, then type the following set of commands: C-x C-f file1.txt C-x 3 C-x o C-x C-f file2.txt

1, 3, and 4

Standard Input Redirection

< symbol directs input into a specified command, file, or directory Ex: sort < file This feeds the input of a specified source into the command source which will sort the contents by alphabetical order

Standard Output Redirection (truncate)

> symbol directs output into a specified file or directory using it with "cat" allows user to type input into a new file truncate functionality essentially OVERWRITES the original file's contents

Standard Output Redirection (append)

>> symbol directs output into a specified file or directory unlike >, or truncating, the user's input will ADD ON to the original file's contents

What is check1302?

A command that is used to check if a user's source code aligns with the CS1302 Code Style Guide.

The last two lines of an error output are BEST known as: a. call stack b. random output c. (call) stack trace d. lines we ignore when debugging

A is an ok answer, but C is the best answer. This is because a "trace" of memory is produced from the computer's memory.

Where is the exception first thrown in a stack trace?

A stack trace goes from the bottom to the top. The top of the stack trace shows where the exception was thrown. Look for the keyword "throwFor"

What is the command to see processes and what does it mean/do?

"ps" is used to see processes/jobs and their status. They can either be in the foreground, background, or be suspended.

What command is used to add a new file to the repository to save changes?

$ git add path/to/File.java

What command is used to commit the changes you made to your local copy of the repository?

$ git commit -m "Add comment here to summarize changes to code."

What is the command to check the status of your local copy of the repository?

$ git status

Consider the class edu.uga.cs.Fun and the following directory structure: project ├── dist │ └── bin │ └── edu │ └── uga │ └── cs │ └── Fun.class └── src └── edu └── uga └── cs └── Fun.java What is the compilation command used to reproduce the directory structure under dist if typed from inside the project directory? You may assume that the dist directory itself already exists and contains bin. $ javac Fun.java $ javac -cp dist/bin src/edu/uga/cs/Fun.java $ javac -d dist/bin src/edu/uga/cs/Fun.java $ java -d bin src/edu/uga/cs/Fun.java

$ javac -d dist/bin src/edu/uga/cs/Fun.java

What is the command to generate the API documentation website?

$ javadoc -d doc -sourcepath src -subpackages cs1302 -d -- specifies the destination directory where Javadoc saves the generated HTML files; -sourcepath -- specifies the search paths for finding source files (.java); and -subpackages -- specifies the packages for which documentation should be generated.

What is the command to create a symbolic link of your API website?

$ ln -s $(pwd)/doc ~/public_html/cs1302-javadoc-doc The website can be seen in the following URL: https://webwork.cs.uga.edu/~user/cs1302-javadoc-doc/

What is "version control"

A system that records changes to a file or set of files over time so that you can recall specific versions later.

What is inheritance?

A way to create a new class based on an existing class without needing to copy and paste code. A child class will inherit everything (except private variables) from its parent class. A subclass/child class cannot directly access the private members of its parent class.

Why does some Java code throw exceptions? a. control flow b. communication c. force a crash d. scare users

A, B When you encounter an exception, you change the control flow. Exceptions always provide info (in a stack) related to where the error lies, and why the exception was thrown. C isn't right because a try-catch will prevent this from occurring. Said in lecture this was not the best answer.

An unchecked exception: a. a run time error b. is an object of a class of or under Runtime Exception c. must be caught or declared to be thrown d. may prevent compilation e. automatically propagates through the call stack

A, B, E C - You can do this, but it won't do anything because of automatic propagation. D - Only types/classpath issues may cause this, but we ignore it in this question.

What is an exception? a. run-time error b. compile-time error c. object d. program-crash

A, C B - exceptions aren't thrown during compilation. Exceptions may occur due to syntax/spelling errors so this is not an actual exception for this question. D - a crash can occur BECAUSE of an exception, but the exception itself is just JVM's way of showing an error.

A checked exception is: a. a run-time error b. an object of a class under Runtime Exception c. must be caught or declared to be thrown d. may prevent compilation e. automatically propagates through the call stack

A, C B isn't right because the class Runtime Exceptions and its subclasses are UNCHECKED exceptions. D MAY occur because if they aren't caught/declared to be thrown, then they can indirectly prevent compilation. E isn't right because checked exceptions need to be explicitly propagated through call stacks and declared to be thrown.

Which of the following are true about interfaces in Java? a. Interfaces serve as a contract for the classes that implement the interface. b. Interfaces are functionally equivalent to classes. c. If no visibility modifier is explicitly given, an abstract method in an interface defaults to private visibility. d. Interfaces specify what a type can do.

A, D B isn't right because they are NOT functionally equivalent. You can make an object of a class that implements an interface, but you CANNOT make an object out of an interface. C isn't right because the default visibility is not private.

There is a Jumpable interface that is implemented in two different classes, Batman and Kangaroo. Both have default (zero parameter) constructors. Which of the following are valid assignment statements? a. Batmobile b = new Jumpable(); b. Jumpable j = new Batmobile(); c. Kangaroo k = new Batmobile(); d. Jumpable j2 = new Kangaroo(); e. Batmobile b2 = new Batmobile(); f. Batmobile b3 = new Kangaroo();

B, D, and E a - can't make a jumpable object. You can't make an object out of an interface. b - batmobile is compatible with jumpable c and f - you can't take Kangaroo and assign it to Batmobile (or the other way around)

You have a class with a FQN of java.util.Scanner and access to Scanner.java. What's the package statement in that file? a. package; b. package java.util.Scanner; c. package java.util; d. package java/util;

C A isn't right because there is no package name. B isn't right because this is the FQN. Scanner.java is the simple name containing the Scanner class. D isn't right because you can't have any slashes.

When looking at the inside of a .java file you see "package edu.uga.cs;" at the top and "public class Student" a few lines later. What's the Student class' FQN? a. edu/uga/cs/Student b. Student c. edu.uga.cs.Student d. edu/uga/cs.Student e. edu.uga.cs.Student.class

C FQNs CANNOT have slashes. Only dots. B isn't right because that is the simple name. C is correct because the format of an FQN is "packagename.simplename." E is incorrect because ".class" is not part of a simple name.

You successfully execute: javac -d path/to/bin src/uga.Driver.java and you have a class called Driver.java that contains the main method. What command can you use to run that program from where you are? a. java -cp bin Driver b. java -cp path/to/bin Driver c. java -cp path/to/bin uga.Driver d. java -cp /absolute/path/to/bin uga.Driver e. java -cp path/to/bin uga.Driver.class

C and D A is incorrect because it assumes bin is in pwd, when it is NOT. It is further down. B is incorrect because it uses the simple name. C is the best answer, and D is ok because it goes to the right place but assumes where bin is. E is incorrect because you do not use ".class".

Move to start of the line

C-a

Move backward by char

C-b

Move to end of line

C-e

Move forward by character

C-f

Kill/cut a line

C-k

Yank/paste a killed line

C-y

What is the FQN of the exception object's class? a. ArrayIndexOutOfBoundsException b. java.lang c. ArrayIndexOutOfBoundsException.class d. java.lang.ArrayIndexOutOfBoundsException e. java/lang/ArrayIndexOutOfBoundsException.class f. java/lang/ArrayIndexOutOfBoundsException

D The error tells you the FQN of the class after "Exception in thread main." C and E are more like relative paths of the exception. F is incorrect because FQNs don't use slashes.

What does changing "String[] args" to "String... args" do?

String[] args takes an array argument in while "String... args" takes an arbitrary number of strings as its argument and creates an array out of them. Using "String... args" allows you to run the program without passing any String paramters. Note: A method may only contain a single varargs declaration and it must be at the end.

What are unchecked exceptions?

They are exceptions caught during runtime. They may or may not be handled by the programmer. The program will compile, but cannot run. Try-catch blocks do not need to be used because the compiler doesn't force you to catch the exception.

What is the difference between "throw", "throws", and @throws?

Throw is used in code to explicitly throw an exception. This is used when you want your method to throw an exception under some predefined conditions. If the exception object being thrown using throw is a checked exception, then you might also need to include throws in the method signature. The throws keyword is used in a method or constructor signature to list the checked exceptions that the method is allowed to propagate. The @throws tag is a Javadoc tag that is used in the Javadoc comment associated with a method (or constructor) to document that it can throw an exception under certain circumstances. The rule of thumb is this: if your method throws an exception (checked or unchecked) that a user of your method should handle, then you should document that exception using @throws in the associated Javadoc comment.

Checked vs unchecked exceptions (relating to propagation)

Unchecked exceptions automatically propagate and checked exceptions must be explicitly propagated

How can a child constructor inherit the code from a parent constructor?

Use the "super()" keyword. This needs to be done on the FIRST line of the constructor. This calls the parent constructor and Java executes the code from that constructor when called.

If a file has an octal mode of 645, what is it's permissions?

User: Octal = 6 Binary = 110 Symbolic = rw- Group Octal = 4 Binary = 100 Symbolic = r-- Other Octal = 5 Binary = 101 Symbolic = r-x

Why use $(pwd) when creating a symbolic link?

When using the ln command, we need the absolute path to get to our path (in this case, doc). Using $(pwd) is a shortcut that is used to fill the paths to the working directory. This makes the process less tedious and less error-prone.

When looking in a stack trace, how do we find where the exception was thrown in our code?

Wherever the exception is encountered in OUR .java file. Exceptions occur much earlier (for example, in the Scanner class), but is propagated to our code.

What is an exception?

an OBJECT that communicates error conditions that an application might want to deal with - each exception corresponds with a class

Two ways to deal with exceptions:

avoid them by understanding the conditions in why they are thrown handle them through "try-catch" statements

Example of top-level declarations

classes or interfaces

Example of member-level declarations

constructors, class variables, methods, constants

What keyword is used in a class signature to show it inherits code from another class?

extends

Which of the following are true about Git? Select all that apply. 1) Git is a Centralized Version Control System (CVCS) 2) When you commit, Git takes files that are currently in the staging area and stores them in a new snapshot. 3) After a file is saved, it is automatically added to the staging area to be included in the next commit. 4) When you clone a Git repository, you create a copy of the entire history of the repository on your local machine.

2, 4

What is an interface?

An interface is a reference type that only includes method signatures and constants. The methods are not implemented in the interface. Another class must be created to supply the implementation.

Which of the following can be contained in an interface? a. instance methods b. constants c. static methods d. instance variables e. abstract methods

B, C, E a - this may work, only if its an abstract method

What are checked exceptions?

Exceptions that must be explicitly caught or propagated. They are caught when code is compiled. and cannot be run. A try-catch block is required since the compiler forces you to provide a way of propagation.

What does the chmod command do?

In Unix operating systems, chmod is the command that can change the access permissions to files and directories. The syntax is: chmod (owner) + or - (permissions) (filename). The permissions list includes permissions for user, group, and other. You can use rwx (read, write, execute) notation or 0-7 digits to represent the permissions Example: "chmod go-rwx file" will remove read, write, and execute permissions on the file for the group and others. "chmod a+rw bigList" will add read and write permissions on the "bigList" file for everyone.

What does varargs do?

It allows us to write methods that accept a variable of arguments of the same type.

What does "args" in the main method do?

It holds command-line arguments (from the terminal) as an array of String objects.

Move backward by word

M-b

Move forward by word

M-f

Overriding

Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes. When a method in a subclass has the same name, same parameters or signature, and same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class. If an object of a parent class is used to invoke the method, then the version in the parent class will be executed, but if an object of the subclass is used to invoke the method, then the version in the child class will be executed. In other words, it is the type of the object being referred to (not the type of the reference variable) that determines which version of an overridden method will be executed.

Pipes

Redirects input of a process to a destination (denoted by "|" character). Example: who | sort Who command lists users who are online, and the sort command sorts data alphabetically. Piping them (above) takes the output of who and puts it into the input of sort. Advantages: This takes less steps than using the other forms of standard output/input redirection and you won't need to create intermediate files.

Interfaces in Java can contain which of the following? Static methods constants abstract methods instance variables

Static methods constants abstract methods

How do try-catch blocks work

The code that can throw an exception is placed in a try block. The catch block is used to deal with the exception. Each line of code in the try block is executed until the exception is thrown. When thrown, the control flow moves to the catch block. Once the catch block is executed, the control flow is directed to the code after the whole block.

Why is handling exceptions better than avoiding them?

The program doesn't crash and you can customize how you want to deal with a possible error.

How should a method signature look if it is being implemented from an interface?

The signature should be the exact same with the same parameters. There should also be a visibility modifier.

What keyword should be used if you want to use an interface in a class?

implements

What is the keyword for declaring an interface?

interface

Which of the following could be used to gain further insight into a command or command options that you are unfamiliar with? Select all that apply. rel cd man --help

man and --help

What type of declarations can be protected?

only member-level

What type of declarations can be private?

only member-level declarations

What type of declarations can be package private?

only top-level and member-level

What type of declarations can be public?

only top-level and member-level

Where is the "private" modifier visible from? What is its symbol in UML diagrams? What is its keyword in Java?

same class denoted by - "private"

Where is the "package-private" modifier visible from? What is its symbol in UML diagrams? What is its keyword in Java?

same class, same package denoted by ~ no keyword - omission of a visibility modifier will cause compiler to treat things as package private

Where is the "protected" modifier visible from? What is its symbol in UML diagrams? What is its keyword in Java?

same class, same package, and child-class denoted by # "protected"

Where is the "public" modifier visible from? What is its symbol in UML diagrams? What is its keyword in Java?

same class, same package, child-class, and elsewhere denoted by + "public"

Consider the class edu.uga.cs.Math and the following directory structure: project └── src └── edu └── uga └── cs └── Math.java What is the relative path of the default package for source code from inside the project directory? src src/uga/cs project/src ..

src

Example of local-level declarations

variables within a method's parameter and any variable declared within the body of the method


संबंधित स्टडी सेट्स

spanish 10: estar conjugation and feelings

View Set

Chapter 17: Endocrine System (A&P II)

View Set

Lesson 31: The t-test for the Population Mean (sigma unknown)

View Set

ZOO 3731 Human Anatomy Final Quizlet

View Set