In Chapter 6, the Java API is introduced. the Java API is a library of already written code for generic tasks. I had to pull the ArrayList class from the Java API. The ArrayList is an object that one can use methods on, which cannot be done with regular arrays. In fact, ArrayList objects are more powerful and flexible than regular arrays. the only case where a regular Array might be more useful is in a list of primitive values. Since ArrayLists are objects, the use regular Java language, unlike regular arrays that have specialized components. There is also a way to restrict the type of things that are allowed into the ArrayList. ArrayLists do not need an assigned size, things can be added to them and removed and the size will grown or shrink whenever needed. Regular Arrays do not do that. if one exceeds the size of the array, a runtime error pops up.
Within boolean expressions, I leanred new concpets that can be applied, like the 'and' and 'or' operators. within a boolean expression next to an if statement, while loop, etc. && can be used inbetween two statements to say "Hey if both of these are true, do this" or "while bnoth of these are true, do this". || works similarly, except EITHER statement can be true for the whole expression to be considered true. Also, x != 1 means x does not equal 1, and that little thing can be put wherever an expression needs to be true when something does not equal something else. But what about if the code requires the .equals() operator rather than an =? well then a ! gets plopped in front of the entire thing and it means not equal.
In order to use any class from the Java API, one can just use it as if it were their own class he or she made and compiled. The only exception is the FULL package must be imported to the package bein written. For example, to use an ArrayList, one can type "import Java.util.*". "import" is the import function, "Java" is the language, "util" is the package, and "*" is where the class goes, however using the * imports all classes within the package. any code that is imported that begins with "Javax" rather than "Java" originally began as an extension, but then began to be included in the Java API. other than that, there is no difference.
No comments:
Post a Comment