hatidzhe / administration

0 stars 1 forks source link

Questions #13

Closed hatidzhe closed 9 years ago

hatidzhe commented 9 years ago
  1. What ist the meaning of the word "iterate" ?
  2. What is an operator in java?
  3. What is the role of the assign operator?
  4. What is the action of the compare operator?
  5. What are Arrays; how to iterate Arrays?
  6. What are Strings?
  7. What are characters? (Advice: A String is an Array with characters).
  8. How to iterate Strings?
  9. Which is the syntax of if/else-condition?
  10. How to construct a for-loop?
  11. What is the meaning of boolean logic?
  12. How many boolean operations does exist?
hatidzhe commented 9 years ago

Answers I:

  1. "iterate" = to say or perform again; repeat.
  2. Definition - What does Operator mean? An operator, in Java, is a special symbols performing specific operations on one, two or three operands and then returning a result. The operators are classified and listed according to precedence order. Java operators are generally used to manipulate primitive data types. The Java operators are classified into eight different categories: assignment, arithmetic, relational, logical, bitwise, compound assignment, conditional and type comparison operators.
  3. Assignment operators: Assign the value on its right to the operand on its left. It is denoted by the symbol “=”.
  4. Comparison operators: The instanceof operator compares an object to a specified type. This operator can be used to test if an object is an instance of a class, subclass or a particular interface.
hatidzhe commented 9 years ago

Answers II:

  1. Definition - What does Array mean? An array, in the context of Java, is a dynamically-created object that serves as a container to hold constant number of values of the same type. By declaring an array, memory space is allocated for values of a particular type. At the time of creation, the length of the array must be specified and remains constant. To access an array element, the numerical index (a non-negative value) corresponding to the location of that element must be used. The first index value in the array is zero, thus, the index with value four is used to access the fifth element in the array. An array element that is also an array is known as a subarray. Arrays could have one or two dimensions. Often, you will want to cycle through the elements in a collection. For example, you might want to display each element.

The easiest way to iterate is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface. Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.

Before you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an iterator( ) method that returns an iterator to the start of the collection. By using this iterator object, you can access each element in the collection, one element at a time.

In general, to use an iterator to cycle through the contents of a collection, follow these steps:

Obtain an iterator to the start of the collection by calling the collection's iterator( ) method.

Set up a loop that makes a call to hasNext( ). Have the loop iterate as long as hasNext( ) returns true.

Within the loop, obtain each element by calling next( ).

For collections that implement List, you can also obtain an iterator by calling ListIterator.

  1. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and manipulate strings. 7.Normally, when we work with characters, we use primitive data types char.
  2. Two options for(int i = 0, n = s.length() ; i < n ; i++) { char c = s.charAt(i); } or for(char c : s.toCharArray()) { // process c }
hatidzhe commented 9 years ago

Answers III:

  1. The Syntax of the if/else-condition: if (condition) { block of code to be executed if the condition is true } else { block of code to be executed if the condition is false }
  2. The for Loop: A for loop is a repetition control structure that allows you efficiently to write a loop that needs to execute a specific number of times. A for loop is useful when you know how many times a task is to be repeated. Syntax: for(initialization; Boolean_expression; update{ //Statements }
  3. Named after the nineteenth-century mathematician George Boole, Boolean logic is a form of algebra in which all values are reduced to either TRUE or FALSE. Boolean logic is especially important for computer science because it fits nicely with the binary numbering system, in which each bit has a value of either 1 or 0. Another way of looking at it is that each bit has a value of either TRUE or FALSE.
  4. The boolean operators: | the OR operator

& the AND operator

^ the XOR operator

! the NOT operator

|| the short-circuit OR operator

&& the short-circuit AND operator

== the EQUAL TO operator

!= the NOT EQUAL TO operator

?: the IF-THEN-ELSE operator