AZK BG Java

Home > Preview

The flashcards below were created by user flashsmilenet on FreezingBlue Flashcards.


  1. byte
    how long? range?
    • integer
    • 8     -128 to 127
  2. short
    how long?
    • integer
    • 16
  3. int
    how long?
    • integer
    • 32
  4. long
    how long?
    • integer
    • 64
  5. integers
    list? how long?
    • - byte          8     -128 to 127          
    • - short        16          
    • - int           32          
    • - long        64
  6. float
    how long?
    32
  7. double
    how long?
    64 - most commonly used
  8. char
    how long?
    16
  9. most commonly used floating-point
    double    64
  10. floating-point
    list?
    • - float        32            
    • - double    64 - most commonly used
  11. primitive variable types
    • - integers       
    •    - byte         8     -128 to 127       
    •    - short        16        
    •    - int        32        
    •    - long        64    
    • - floating-point          
    •    - float        32         
    •    - double    64 - most commonly used     
    • - char         16        
    •    - ch = 'X'        
    •    - ch = ++ = Y - can be incremented        
    •    - ch = 90 = Z    
    • - boolean         - true / false
  12. access modifier
    • - public
    • - private
    • - is a keyword to determie how other parts of the program can access the member of the class
  13. public
    • - access modifier    
    • - member can be accessed by code outside the class in which it is declared
  14. private
    • - access modifier    
    • - prevents a member from being used by code defined outside of its class
  15. main method
    • main (String args[ ])
    • - declares a parameter named args which is an array object of type String    
    • - args receives any command-line arguments present when program is executed
  16. System.
    - predifined class that provides access to the system
  17. .out.
    - output stream that connected to the console
  18. System.out
    - an object that encapsulates console output
  19. println
    - method that build in the System.out package
  20. refer to fixed value that are presented in their human-readable form
    literals
  21. can be assigned to a variable of type "char" "byte" or "short"  as long as the value being assigned can be represented by the target type
    literals
  22. literals
       - definition
       - can be what type...?
       - char - ?
       - int - ?
       - 100 by default ?
       - long - ?
       - float - ?
       - char, byte, short ???
       - 11.2 by default ?
    • - constant - refer to fixed value that are presented in their human-readable form
    • - can be any of primitive types        
    • - char - 'a', '%'        
    • - int - 100, 10            
    • - 100 by default type "int"      
    • - long - 12l or 12L        
    • - float - 11.123f or 11.123F            
    • - 11.12 by default type "double"        
    • - can be assigned to a variable of type "char" "byte" or "short"  as long as the value being assigned can be represented by the target type        
    • - int can always be assigned to a "long" variable        
    • - underscore can be imbeded into an integer (compiler will ignore it)           
    •      - 123_45_1234 = 123,451,234
    •      - useful for SSN, ID...
  23. - constant: refer to fixed value that are presented in their human-readable form
  24. literals
  25. number system based on 8 and uses the digitals 0-7 (10 = 8)
    octal literals
  26. octal literals
    • - number system based on 8 and uses the digitals 0-7 (10 = 8)    
    • - oct = 011 = 9 in dec
  27. number system based on 16 and uses the digitals 0-9 plus letters A-F for numbers 10-15
    hexsadecimal literals
  28. hexsadecimal literals
    • - number system based on 16 and uses the digitals 0-9 plus letters A-F for numbers 10-15    
    • - hex = 0xFF = 255 in dec
  29. scope of variables (same name declaration?)

    int count;    
    for(count = 0; cont < 10; count++){    
        System.out.println(count);           
        int count;        
    }
    same name declaration legal for C, C#, but ilegal for Java
  30. automatic type conversion will take place if:
    • - two types are compatible    
    • - destination type is larger than the source type
    •    int to float, but not float to int
  31. double to int
    • casting incompatible types
    • i = (int) (x / y);      i is int, x and y are double
  32. byte to char
    • casting incompatible types
    • ch = (char) n;        n = 88; ch = X
  33. int to double
    • casting incompatible types
    • db = (double) int;    cast needed
  34. all "char", "byte" and "short" are promoted to
    int
  35. if one operand is long, float or double, the whole  expression promoted to ...
    long, float or double
  36. value of a "byte" promoted to "int" inside the expression, outside it is
    still a "byte"
  37. when operation involves 2 "byte" values:
    stapes?
    • 1) "byte" operands promoted to "int"
    • 2) operation takes place, yielding an "int" result
    • 3) outcome of an operation involving 2 "byte" values will be an "int"
    •     i = b * b;        // no cast needed (result elevated to "int")
    •     b = (byte) (b * b);    // cast needed to assign "int" back to "byte"
  38. System.in.read( )
    input object attached to the keyboard
  39. read( )
    • - method of "System.in" package  will wait until the user press the key in the console    
    • - character is returned as an integer and must be cust into a "char" or assign to "char" variable
  40. in order to use "System.in.read( )" the program must specify this clause within main method
    public static void main(String[ ] args) throws java.io.IOException {
  41. throws java.io.IOException
    • - in order to use "System.in.read( )" the program must specify this clause within main method    
    • - to handle input error
    •     public static void main(String[ ] args) throws java.io.IOException {
  42. for loop used to ?
    perform known number of iteration
  43. Multiple loop control variables (example)
    for(i = 0, j = 10;   i < j;    i++, j--)
  44. Loop until an "S" typed by user (example)
    for(s = 0; (char) System.in.read() != 'S'; s++)
  45. Increment inside of the body of the loop (example)
    • for(m = 0; m < 4; ){            
    •     System.out.println("Pass #" + m);            
    •     m++;        
    • }
  46. Increment inside of the body of the loop and Initialization outside of the loop (example)
    • m = 0;        
    • for(; m < 4; ){
    •     System.out.println("Pass #" + m);           
    •     m++;        
    •     }
  47. Loop with "NO BODY"
    • for(n = 0; n <= 5; sum += n++);        // loop with no Body                
    • System.out.println("Sum of 5 numbers is: " + sum);
  48. while
    • to repeat unknown number of times
    • condition is tested on the top of the loop (could be never executed)

    •     char ch = 97;             // 97 = 'a'
    •     while(ch <= 100){         // 100 = 'd'
    •         System.out.println(ch);
    •     ch++;    }
  49. do-while
    to perform at least once

    • do{            
    •     System.out.println(ch);    // always execute at least once             
    •     ch++;        
    • } while(ch != 'e');    // check condition at the bottom
  50. break
    • - to go to the next statement outside the loop  
    • - in the nested loop will break out of only innermost loop
  51. break go-to
    • to exit from a deeply nested set of loop
    • go to the next statement after the loop or block marked w the tag:

    • end:            
    •     for(ii = 1; ii < 4; ii++){                
    •         if(ii == 2) break end;             
    •     }
    •     System.out.println("next statement");

    go to next statement w/o performing next iterations of the loop:

    •     for(ii = 1; ii < 4; ii++) end: {
    •         if(ii == 2) break end;
    •         System.out.println("ii = " + ii);
    •     }
    • "ii = 2" is not going to be printed

    you cannot break to any label that is not defined for an enclosing block
  52. continue
    forces the next iteration of the loop which is labeled
  53. class
    - is a template that defines the form of an object
  54. class specification
    - used by Java to construct an object
  55. class members
    methods and variables that constitute a class
  56. instance variables
    - the data members of the class
  57. Object creation (example)
    Vehicle minivan = new Vehicle(empty or arg-list);
  58. Object 'creation
    Vehicle minivan = new Vehicle(empty or arg-list);
    2 functions?
    • Function 1: declaration of a variable "minivan" of the class type "Vehicle"
    • Function 2: creation of a physical copy of the object and assign to "minivan" a reference of that object using operator "new"
  59. Vehicle minivan = new Vehicle(empty or arg-list);
    Vehicle?
    Vehicle is a name of the class that is being instantiated
  60. Vehicle minivan = new Vehicle(empty or arg-list);
    Vehicle(empty or arg-list)?
    Vehicle specifies the constructor of the class
  61. Vehicle minivan = new Vehicle();
    if constructor is not defined?
    "new" will use the default constructor supplied by Java
  62. Vehicle minivan = new Vehicle(empty or arg-list);
    sins memory is finite?
    "new" can be not able to allocate memory for the object - run-time exception will occur.
  63. Methods
    • subroutines that manipulate the data defined by the class
    • void range( ){            
    •     System.out.println("Range is " + fuelcap * mpg);        
    • }
  64. returning from method:
    • method's closing curly brace is encountered
    • when "return" statement is executed
  65. What is it?
    int range( ){            
        return fuelcap * mpg;        
    }
    ???
    method "range" with returning value type "int"
  66. What is it?
    double fuelneeded(int miles){            
        return miles / mpg;        
    }
    ???
    method "fuelneeded" with returning value type "double" and received parm "int miles"
  67. return
    • statement to return value from the method w specified type of returning
    • if "void" - to return to the point from where "void" method was called
  68. Constructor
    • - inirializes an object when it is created    
    • - has same name as it's class    
    • - have no explicit return type    
    • - used to give initial values to the instance variables defined by the class
  69. Garbage Collector
    • - for recovery of free memory from unused objects, making that memory available for subsequent relocation    
    • - reclaims object automatically, behind the scenes 
    • - occurs only sporadically during the execution of the program    
    • - runs when 2 conditions are met:        
    •     1) there are objects to recycle        
    •     2) there is a need to recycle them
  70. finalize()
    • -  method that will be called just before an object's final destruction by the garbage collector    
    • - used to ensure that an object terminates cleanly (that opened file owned by that object is closed)    
    • - called just before garbage collector (we do not know when it is executed)  
    • - if program ends before garbage collector occurs, finalize( ) will not execute   
    • - should be used as a backup procedure

    • protected void finalize( ){            
    •     finalization code here        
    • }
  71. this
    keyword that is reference to the invoking object

    • double get_pwr( ){            
    •     return this.val;                
    • }        
    • System.out.println(x.get_pwr( ))

    • - "this.val" refers to the object on which "get_pwr( )" was called
    • - if "get_pwr( )" had been invoked on "x.get_pwr( )", than "this" referring to "x" object
  72. Arrays
    simplest data structure, which is a linear list that supports random access to its lelements
  73. Array declaration during creation of the object:
    int ar1[ ] = new int[10];
  74. Alternative array declaration
    int[ ] ar1 = new int[10];
  75. Array declaration during initialization
    int ar1[ ] = {0,1,2,3,4,5,6,7,8,9};
  76. Arrays declaration
    • during creation of the object:
    •    int ar1[ ] = new int[10];
    • alternative declaration
    •    int[ ] ar1 = new int[10];
    • during initialization      
    •    int ar1[ ] = {0,1,2,3,4,5,6,7,8,9};
  77. Arrays alternative declaration
    int[ ] ar1 = new int[10]
  78. Declaring several array at the same time
    • int[ ] nums1, nums2, nums3;
    • int nums1[ ], nums2[ ], nums3[ ];
  79. array as a return type for a method
    int[ ] someMeth(    ) {...
  80. loading array "ar1" with index numbers
    for(i=0; i<10; i++) ar1[ i ] = i;
  81. reading array "ar1"
    • for(i=0; i<10; i++)
    •     System.out.println("ar1[" + i + "] = " + ar1[i]);
  82. Multidimensional Array
    list of one-dimensional arrays
  83. Multidimensional Array declaration
    int table[ ][ ] = new int[3][4]
  84. Multidimensional Array alternative declaration
    int[ ] table = new int[3][4]
  85. Multidimensional Array initialization
    • int multidim[ ][ ] = {            
    •     {1, 1},            
    •     {3, 1},            
    •     {5, 25},            
    •     {6, 36}        
    • };
  86. Irregular Array
    • 1) specifying only the memory for the 1-st dimension            
    • 2) specifying the memory for the 2-nd dimension separately
    • 3) # of elements in 2-nd dimension is different

    • int table[ ][ ] = new int [3][ ];            
    • table[0] = new int[4];            
    • table[1] = new int[2];            
    • table[2] = new int[2];
  87. Three Dimensions Array (or more)
    int multidim[ ][ ][ ] = new int[4][10][3];
  88. Assigning Array References
    • - assigning one array reference variable to another
    • - simply changing what object that variable refers to

    • nums2 = nums1;      // now "nums2" refers to "nums1"
    • nums2[3] = 99;        // means nums1[3] = 99
  89. length of array
    int size = nums.length;
  90. data engine
    storage and retrieval are provided by the data structure itself, not by program
  91. stack
    • - data engine    
    • - list in which elements can be accessed in "first-in, last-out" (FILO) orders only    
    • - like stack of plates on the table - the first down, the last to be used
  92. queue
    • - data engine    
    • - list in which elements can be accessed in "first-in, first-out" (FIFO) orders only   
    •  - like line at a bank - the first in line, is the first served    
    • - supports 2 basic operations: "put" and "get"
    •     1) put            
    • - places a new element on the end of the queue 
    •     2) get            
    • - retrieves the next element from the front of the queue            
    • - consumptive - element can be retrieved only once
  93. 2 basic types of queue:
    • 1) circular            
    •     - reuses location when element is removed        
    • 2) non-circular           
    •     - DOES NOT reuse location when element is removed and can be exhausted
  94. FILO
    "first-in, last-out" - stack
  95. FIFO
    "first-in, first-out" - queue
  96. for-each
    another name?
    Enhanced "for"
  97. for-each
    cycles through collection of objects (arrays) in strictly sequential fashion from start to finish

    • int nums[ ] = {1, 2, 3, 4, 5, 6};        
    • for(int x : nums){   // "x" is a value of an array element
    •     System.out.println("Value is: " + x);        
    • }
  98. for-each
    over multidimensional array?
    • nt nums[ ][ ] = new int[3][5];        
    • for(int x[ ] : nums){       // "x[ ]" is an array of the multidimensional array  
    •     for(int y : x){   // "y" is a value of a multidimensional array element                
    •         System.out.println("Value is: " + y); 
    •            
    • }
  99. for-each
    used for?
    • - searching unsorted array        
    • - computing an average        
    • - finding min or max        
    • - looking for duplicates.
  100. Contents of a String object is Immutable?
    the character sequence cannot be altered
  101. Creating construct a String?
    • String str1 = new String("Hello");            
    • String str2 = new String(str1);
  102. Create a String?
    Srting str = "Java strings are powerful";
  103. str1.equals(str2)
    true if invoking string contains the same character sequence as str
  104. true if invoking string contains the same character sequence as str
    • operating String using method
    • str1.equals(str2)
  105. operating String using methods
    Boolean equals(str)?
    • true if invoking string contains the same character sequence as str
    • str1.equals(str2)
  106. obtains length of the string
    • operating String using method
    • str1.length( )
  107. str1.length( )
    obtains length of the string
  108. operating String using methods
    int length()
    • obtains length of the string
    • str1.length( )
  109. obtains the character at the index
    • operating String using method
    • char charAt(index)
  110. str1.charAt(30)
    obtains the character at the index
  111. operating String using methods
    char 'charAt(index)
    • obtains the character at the index
    • str1.charAt(30)
  112. str1.compareTo(str3)
    • - invoking string is < str    (<0)            
    • - invoking string is = str    (=0)          
    • - invoking string is > str    (>0)
  113. - invoking string is < str    (<0)            
    - invoking string is = str    (=0)          
    - invoking string is > str    (>0)
    str1.compareTo(str3)
  114. operating String using methods
    int 'compareTo(str)
    • - invoking string is < str    (<0)            
    • - invoking string is = str    (=0)          
    • - invoking string is > str    (>0)
    • str1.compareTo(str3)
  115. str3.indexOf("Java")
    • - searches the invoking string for the substring in "str"            
    • - returns the index of the first match            
    • - on failure = "-1"
  116. - searches the invoking string for the substring in "str"  
    - returns the index of the first match
    • - str3.indexOf("Java")
    • - returns the index of the first match            
    • - on failure = "-1"
  117. operating String using methods
    int 'indexOf(str)
    • - searches the invoking string for the substring in "str"            
    • - returns the index of the first match            
    • - on failure = "-1"                
    • str3.indexOf("Java")
  118. str3.lastIndexOf("Java")
    • - searches the invoking string for the substring in "str"            
    • - returns the index of the last match            
    • - on failure = "-1"
  119. - searches the invoking string for the substring in "str"            
    - returns the index of the last match
    str3.lastIndexOf("Java")
  120. operating String using methods
    int lastIndexOf(str)
    • - searches the invoking string for the substring in "str"            
    • - returns the index of the last match            
    • - on failure = "-1"                
    • str3.lastIndexOf("Java")
  121. str3.substring(5, 10)
    returns substring of the string starting w "startIndex" and ending w "endIndex"
  122. returns substring of the string starting w "startIndex" and ending w "endIndex"
    str3.substring(5, 10)
  123. operating String using methods
    String substring(startIndex, endIndex)
    - returns substring of the string starting w "startIndex" and ending w "endIndex"
  124. String can control "switch" statement
    prior to JDK7, switch has to be controlled by an integer only

    • String command = "cancel";                        
    • switch(command){                    
    •     case "connect":                        
    •         System.out.println("Connect");
    •          break;   
    •     case "cancel"                        
    •         System.out.println("Cancel");    
    •        break;                          
    • }

Card Set Information

Author:
flashsmilenet
ID:
323811
Filename:
AZK BG Java
Updated:
2016-10-14 17:18:14
Tags:
AZK BG Java
Folders:
AZK BG Java
Description:
AZK BG Java
Show Answers:

Home > Flashcards > Print Preview