Intro To Programming UNIT 1 Flashcards

1
Q

What should be the first line in a program without import statements and comments

A

public class FileName {

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you format the main method declaration

A

public static void main(String[]args) {

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What statement should you use to print to the console without a new line

A

System.out.print(“Text to be displayed on the console”);

Take note of the capitalization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you output a text as a new line in the console

A

System.out.println(“Text to be displayed”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you print a new line / How do you print a TAB

A

/n … /t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When a user types on the keyboard where are those characters stored before being interpreted by the program

A

In the keyboard buffer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a low level function to read from the keyboard buffer? What is it’s disadvantages?

A

Using the System.in method. It’s not powerful because it can only return one character at a time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the Java API?

A

It’s a collection of thousands of useful classes that are stored in sever hundred “packages” or class libraries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When importing as such:

import java.util.Scanner;

What is the package name of Scanner?
What is the fully qualified name?

A

The package name of scanner is java.util

The fully qualified name is java.util.Scanner

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is accomplished by using an import statement such as:

import java.util.Scanner;

A

It tells the compiler where to go in the library to find the code it needs to run the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How would you create a new Scanner object?

include import statements

A

include java.util.Scanner;

Scanner obj_name = new Scanner(System.in)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are methods

A

It’s a function or a block of code that is run when called upon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What methods does a Scanner object have to read from the Keyboard Buffer

A

nextInt() -> Reads an int

nextDouble() -> Reads a double

nextLine() -> Reads a line of text till the eol

next() -> Reads from the buffer until it hits a space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between Scanner.next() and Scanner.nextLine()

A

nextLine() will read and RETURN ever character that is typed into the keyboard buffer including spaces and EOL characters therefore it empties the keyboard buffer

next() will read characters from the buffer until it hits a space or a EOL. it does not flush the buffer clean and leaves the EOL character behind this applies to nextInt() and nextDouble()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the problem of using nextLine() after a next() and what is the solution to the problem?

A

When it’s called it will immediately look at the keyboard buffer before looking for user input. If a eol character is in the buffer it will stop reading and return.

The solution if you use a next() call before using a nextLine(). You must complete a buffer flush by calling nextLine() after using a next() call. This will empty all EOL characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a paradigm

A

A way of doing things

17
Q

What are the two main paradigms in programming

A

Object Oriented Programming / Procedural Programming

18
Q

What is procedural programming

A

Task analysis or task decomposition. Looking at the overall process and breaking it down into smaller atomic tasks.

19
Q

What does Procedural Programming lead to?

A

An algorithm

20
Q

What is an algorithm?

A

It’s a procedure or series of steps for solving a problem

21
Q

What are the three control structures of any program

A

Sequence - executing the code in order
Selection - conditional if else
Repetition - loops

22
Q

What is an object

A

It’s some computer code that models or represents some self-container entity

23
Q

What do objects hold

A

Some functions - Methods
Data - Properties

24
Q

What language is Java base on

A

C++

25
Q

What compiles the source code into java byte code

A

The java compiler (javac.exe)

26
Q

What turns the java byte code into machine specific code.

A

The JVM or JRE. This is the java.exe program

27
Q

Is java an interpreter language or compiled

A

It’s both

28
Q

In what charset is Java represented

A

UNICODE