Chp 2 Flashcards

1
Q

A JAVA APPLICATION

A

Executes when you use teh java command to launch JVM

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

A COMMENT LINE BEGINS WITH…

A

//

Which is an end-of-line comment

*It terminates at the end of the line on which it appears

** JAVA WILL NOT READ THESE COMMENTS

Example:

// empty statement

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

TRADITIONAL COMMENTS

PG. 39

A

CAN SPREAD OVER SEVERAL LINES AND ARE DELIMITED BY /* AND */

THESE COMMENTS ARE NOT READ BY JAVA EITHER

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

JAVADOC

COMMENTS

PG. 39

A

DELIMITED BY /** AND */

ENABLE YOU TO EMBED PROGRAM DOCUMENTATION IN YOUR CODE.

GENTERATES HTML PAGES BASED ON THESE COMMENTS

COMPILER INGNORES ALL TEXT BETWEEN DELIMITERS

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

SYNTAX ERROR

PG. 39

A

AKA COMPILER ERROR, COMPILE TIME ERROR, COMPILATION ERROR

OCCURS WHEN THE COMPILER ENCOUNTERS CODE THAT VIOLATES JAVA’S LANGUAGE RULES

SIMILAR TO A GRAMMER ERROR IN NATURAL LANGUAGE

THE COMPILER RESPONDS BY ISSUING AN ERROR AND PREVENTING YOUR PROGRAM FROM COMPILING

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

BLANK LINES

SPACE CHARACTERS

TAB CHARACTERS

PG. 39

A

KNOWN AS WHITE SPACE

WHITE SPACE MAKES PROGRAMS EAISER TO READ AND IS IGNORED BY THE COMPILER

** IN A PROGRAM IT WOULD JUST BE A SKIPPED LINE

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

KEYWORDS

PG. 40

A

RESERVED FOR USE BY JAVA AND ARE ALWAYS SPELLED WITH ALL LOWERCASE LETTERS

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

KEYWORD CLASS

PG 40

A

INTRODUCES A CLASS DECLARATION

EX:

public class Welcome1

  • public class being the keyword class*
  • Welcome1 being the class name*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

CLASS NAMES

A

BY CONVENTION ALL CLASS NAMES IN JAVA BEGIN WITH A CAPITAL LETTER AND CAPITALIZE THE FIRST LETTER OF EACH WORD THEY INCLUDE

E.G.

SampleClassName

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

JAVA CLASS NAME

A
  • SERIES OF CHARACTERS CONSISTING OF LETTERS, DIGITS, UNDERSCORES (_) AND DOLLAR SIGNS ($)
  • DOES NOT BEGIN WITH A DIGIT AND DOES NOT CONTAIN SPACES
  • JavaClassNameSample
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

IS JAVA CASE SENSITIVE?

A
  • YES
  • UPPER AND LOWERCASE LETTERS ARE DISTINCT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

THE BODY OF EVERY CLASS DECLARATION

PG. 40

A
  • IS DELIMITED BY BRACES
  • { AND }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A PUBLIC CLASS DECLARATION MUST BE SAVED IN….

A
  • A FILE WITH THE SAME NAME AS THE CLASS FOLLOWED BY THE “.java” FILE NAME EXTENSION
  • E.G public class Welcome1, would be saved as Welcome1.java
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

METHOD MAIN

PG.41

A
  • STARTING POINT OF EVERY JAVA APPLICATION
  • MUST BEGIN WITH public static void main( String [] args)
  • otherwise the JVM will not execute

Ex:

{

// main method begins execution of java application

public static main void main ( String [] args )

}

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

METHODS

PG.41

A
  • PERFORM TASKS AND RETURN INFO WHEN THEY COMPLETE THEM
  • KEYWORD void, INDICATES THAT A METHOD WILL PERFORM A TASK BUT RETURN NO INFORMATION

public static void main ( String [] args )

*The parentheses after the identtifirer main indicate that its’s a program building block called method.

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

STATEMENTS

A
  • INSTRUCT THE COMPUTER TO PERFORM ACTIONS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

A STRING

PG.41

A
  • IN DOUBLE QUOTES
  • CALLED A CHARACTER STRING OR STRING LITERAL
  • CAN NOT SPAN MULTIPLE LINES OF CODE

EX:

System.out.println( ” Welcome to Java Programming!” )

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

STANDARD OUTPUT OBJECT

PG.41

A
  • DISPLAYS CHARACTERS IN THE COMMAND WINDOW
  • System.out
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Method

System.out.println

A
  • DISPLAYS THE ARGUMENT IN THE COMMAND WINDOW FOLLOWED BY A NEW LINE CHARACTER TO POSITION THE OUTPUT CURSOR TO THE BEGINING OF THE NEXT LINE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

TO COMPILE A PROGRAM

A
  • YOU COMPILE A PROGRAM WITH THE COMMAND javac.
  • IF THE PROGRAM CONTAINS NO SYTAX ERRORS, A CLASS FILE CONTAINING JAVA BYTECODES THAT REPRESENT THE APPLICATION CREATED.
  • THE BYTECODES ARE INTERPRETED BY THE JVM WHEN YOU EXECUTE THE PROGRAM
  1. Open Command Window
  2. Change directory where program is stored using command cd to change directory
  3. once directory is found type javac ClasName.java
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

TO RUN AN APPLICATION

A
  • TYPE JAVAc
  • FOLLOWED BY THE NAME OF THE CLASS THAT CONTAINS MAIN
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

System.out.print

not

System.out.println

pg.44

A
  • DISPLAYS ITS ARGUMENT AND POSITIONS THE OUTPUT CURSOR IMMEDIATELY AFTER THE LAST CHARACTER DISPLAYED
  • println vs print (println positions at the next line)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

BACKLASH

( \ )

PG.45

A
  • A BACKLASH IN A STRING IS AN ESCAPE CHARACTER
  • JAVA COMBINES IT WITH THE NEXT CHARACTER TO FORM AN ESCAPE SEQUENCE
  • THE ESCAPE SEQUENCE \n represents the newline character

Ex:

{

public static void main ( String [] args)

{

    System.out.println ( "Welcome **\n** to **\n** Java **\n**      Programing!" );

 }

}

Will Display on seperate lines

Welcome to java progaming!

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

System.out.printf

Method

pg.46

A
  • Syestem.out.printf
  • MEANS “FORMATTED”
  • DISPLAYS FORMATTED DATA
  • FIRST ARGUMENT IS A FORMAT STRING CONTAINING FIXED TEXT AND / OR FORMAT SPECIFIERS
  • EACH FORMAT SPECIFIER INDICATES THE TYPE OF DATA TO OUTPUT AND IS PLACE HOLDERFOR A CORRESPONDING ARGUMENT THAT APPEARS AFTER THE FORMAT STRING
25
Q

FORMAT SPECIFIERS

A
  • BEGIN WITH % ADN FOLLOWED BY A CHARACTER THAT REPRESENTS THE DATY TYPE
  • THE FORMAT SPECIFER % IS A PLACE HOLDER FOR A STRING
26
Q

DISPLAYING MULTIPLE LINES WITH

System.out.printf

A

{

System.out.printf( “%s \ n%s \ n”,

       "Welcome to", "Java Programing!" );

}

* Will Display

Welcome to Java Programing!

27
Q

PACKAGES

PG.48

A
  • NAMED GROUPS OF RELATED CLASSES
  • COLLECTIVELY REFFERED TO AS THE JAVA CLASS LIBRARY OR JAVA APPLICATION PROGRAMING INTERFACE
  • PREDEFINED CLASSES THAT YOU CAN REUSE
28
Q

IMPORT DECLARATION

PG 48

A
  • HELPS THE COMPILER LOCATE CLASS THAT’S USED IN A PROGRAM

USUALLY AT BEGINGING AFTER TITLE

import java.util.Scanner; // program uses Class Scanner

29
Q

VARIABLE

A
  • IS A LOCATION IN THE COMPUTERS MEMORY WHERE A VALUE CAN BE STORED FOR USE LATER IN A PROGRAM. ALL VARIABLES MUST BE DECLARED WITH A NAME AND TYPE BEFORE THEY CAN BE USED

**VARIABLE DECLARATION STATEMENT: ** Scanner input = new Scanner ( System.in );

  • The = indicates that the Scanner variable input should be inititalized
  • Variables should be initialized to prepare for use
30
Q

VARIABLE NAMES

PG. 52

A

CORRESPOND TO LOCATIONS IN THE COMPUTERS MEMORY. EVERY VARIABLE HAS THE NAME, A TYPE, A SIZE, AND A VALUE.

A VALUE THAT’S PLACED IN A MEMORY LOCATION REPLACES THE LOCATIONS PERVIOUS VALUE, WHICH IS LOST.

31
Q

ARITHMETIC OPERATORS

PG. 53

A
  • + FOR ADDITION
  • ** -** FOR SUBTRACTION
  • * FOR MULTIPLICATION
  • / FOR DIVISION
  • % FOR REMAINDER
32
Q

INTEGER DIVISION

PG 53

A
  • YIELDS AN INTERGER QUOTIENT
  • 7 / 4 evaluates to 1
  • 17 / 5 evaluates to 3
  • no rounding occurs

% yeilds the remainder

7 % 4 yields 3

17 % 5 yields 2

33
Q

ARITHMETIC EXPRESSIONS

A
  • MUST BE WRITTEN IN STRAIGHT LINE FORM
  • EX: A OVER B must be written a / b
34
Q

IF AN EXPRESSION CONTAINS NESTED PARENTHESES (A + B) * 2

A
  • THE INTERMOST SET IS EVALUATED FIRST
35
Q

RULES OF OPERATOR PRECEDENCE

A
  1. MULTIPLICATION, DIVISION, AND REMAINDER OPERATIONS ARE APPLIED FIRST
  2. ADDITION AND SUBTRACTION OPERATORS APPLIED NEXT

WHEN WE SAY THE OPERATORS ARE APPLIED FROM LEFT TO RIGHT, WE’RE REFFERING TO THEIR ASSOCIATIVITY.

SOME OPERATORS ASSOCIATE FROM RIGHT TO LEFT

36
Q

REDUNDANT PARENTHESES

A

CAN MAKE AN EXPRESSION CLEARER

37
Q

THE “IF” STATEMENT

PG.56

A
  • MAKES A DECISION BASED ON A CONDITIONS VALUE ( TRUE OR FALSE)
38
Q

EQUALITY OPERATORS

A
  • ** (X == Y)** x is equal to y
  • ( x != y ) x is not equal to y
39
Q

RELATIONAL OPERATORS

A
  • ( X > Y ) x is greater than y
  • ( x < y ) x is less than y
  • ( x >= y ) x is greater than or equal to y
  • ( x <= y ) x is less or equal to y
40
Q

EMPTY STATEMENT

A

IS A STATEMENT THAT DOES NOT PERFORM A TASK

41
Q

A ______ BEGINS THE BODY OF EVERY METHOD, AND A _______ ENDS THE BODY OF EVERY METHOD

A

LEFT BRACE {

&

RIGHT BRACE }

42
Q

THE ________ STATEMENT IS USED TO MAKE DECISIONS

A

IF STATEMENT

43
Q

_______ BEGINS AN END-OF-LINE COMMENT

A

//

44
Q

______, _____, AND ______ ARE CALLED WHITE SPACE

A

SPACE CHARACTERS

NEW LINES

TABS

45
Q

______ ARE RESERVED FOR JAVA USE

A

KEY WORDS

46
Q

JAVA APPLICATIONS BEGIN EXECUTION AT METHOD ________

A

METHOD MAIN

47
Q

METHODS _____, ______, ______, DISPLAY INFO IN A COMMAND WINDOW

A

System.out.print

System.out.println

System.out.printf

48
Q

COMMENTS CAUSE THE COMPUTER TO PRINT THE TEXT AFTER THE // ON THE SCREEN WHEN THE PROGRAM EXECUTES

TRUE OR FALSE

A

FALSE

COMMENTS DO NOT CAUSE ANY ACTION TO BE PERFORMED WHEN THE PROGRAM EXECUTES.

THEY ARE USED TO DOCUMENT PROGRAMS AND IMPROVE THE READIBILITY

49
Q

ALL VARIABLES MUST BE GIVEN A TYPE WHEN THEY ARE DECLARED….

TRUE OR FALSE

A

TRUE

50
Q

JAVA CONSIDERS THE VARIABLES NUMBER AND NuMber TO BE IDENTICAL

TRUE OR FALSE

A

FALSE

JAVA IS CASE SENSITIVE

SO THESE VAIRABLES ARE DISTINCT

51
Q

THE REMAINDER OPERATOR ( % ) CAN BE USED ONLY WITH INTERGER OPERANDS

A

FALSE

THE REMAINDER OPERATOR CAN ALSO BE USED WITH NONINTERGER OPERANDS IN JAVA

52
Q

THE ARITHMETIC OPERATORS * / % + AND - ALL HAVE THE SAME LEVEL OF PRECEDENCE

A

FALSE

THE OPERATORS * AND / AND % ARE HIGHER THAN OPERATORS + AND -

53
Q

DECLARE VARIABLES

C, thisIsAVariable, q76354 and number

TO BE OF TYPE INT.

A

int c, thisIsAVariable, q76356, number;

54
Q

PROMPT

THE USER TO ENTER AN INTEGER

A

System.out.print ( “Enter an integer” ) ;

55
Q

INPUT AN INTEGER AND ASSIGN THE RESULTS TO INT VARIABLE VALUE.

ASSUME SCANNER VARIABLE INPUT CAN BE USED TO READ A VALUE FROM THE KEYBOARD

A

value = input.nextInt();

56
Q

PRINT “THIS IS A JAVA PROGRAM”

ON ONE LINE IN THE COMMAND WINDOW.

USE METHOD System.out.println

A

System.out.println ( “This is a Java Program!” ) ;

57
Q

PRINT

“THIS IS A JAVA PROGRAM”

ON 2 LINES IN COMMAND WINDOW

FISRT LINE SHOULD END WITH JAVA

USE METHOD System.out.println

A

System.out.println ( “This is a Java \n Program” ) ;

58
Q

PRINT

“THIS A JAVA PROGRAM”

ON TWO LINES FIRST LINE ENDING WITH JAVA

USE METHOD System.out.printf & two %s format specifiers

A

System.out.printf ( “%s \ n%s \ n”, “this is a java”, “program” ) ;

59
Q

IF THE VARIABLE NUMBER IS NOT EQUAL TO 7, DISPLAY “THE VARIABLE NUMBER IS NOT EQUAL TO 7”

A