1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
Easy Learn Java: Programming Articles, Examples and Tips - Page 315
1060 Stories (530 Pages, 2 Per Page)
Java: String Overview
Strings are sequences of Unicode characters. In many programming languages strings are
are stored in arrays of characters (eg C, C++, Pascal, ...).
However, in Java strings are a separate object type, called String.
There is a String class and methods for working with String objects.
The "+" operator is used for concatenation, but all other operations
on strings are done with methods in the String class.
See the Summary - Strings
for an overview of the methods in String and related classes.
Related types and classes
|The basic class for strings. String objects can NOT be changed.|
|Primitive type for 16-bit Unicode characters.|
|Primarily useful for its utility functions for working with characters.|
|StringBuffers are used to build or change strings. Conversion between
String and StringBuffer is easy.|
|Used to break a String into tokens (words).|
|Useful for reading and writing text files.|
|JDK 1.4 added java.util.Pattern and Matcher to do regular expression
To write a constant string, put the characters between double quotes,
If the string contains double quotes, put a
backslash ('') in front of each double quote, eg "abc"def"ghi".
The String equivalent of 0, is the string with no characters, "".
Putting two strings together to make a third string is called
concatenation. In Java the concatenation operator
is '+', the same operator as for adding numbers. If either operand
is a String, Java will convert the other operand to a String
(if possible) and concatenate the two.
|1 + 2 ||3|
|"1" + 2 ||"12"|
|1 + "2" ||"12"|
|"1" + 2 + 3||"123"|
|1 + 2 + "3"||"33"|
8 comments | | Score: 4
Posted by jalex on Sunday, March 06, 2005 (00:00:00) (4045 reads)
Java: GUI Structural Patterns
Structuring the program - Separating the Model
In all ways of structuring a GUI program, there is one vitally important issue --
separating the code which is the essence of the problem from the
user interface. This logical part is variously referred to as the
model, business logic, abstraction, or document.
This code must not refer to the user interface directly -- it will interact
with the user interface code by returning values or invoking listeners.
Motivation. There are two compelling reasons for this separation.
- Lower complexity -- Programs end up being less complex and therefore easier (cheaper) to modify.
For the smallest programs this may not be obvious, but
the benefits show up very quickly as a program grows.
This is not an advantage only in large programs.
- Interface Flexibility -- This allows changes to the user interface, eg,
moving from Swing to SWT, or to a web interface.
You should be able to use your basic logic code (if applicable) with the following interfaces.
- GUI interface. And it should be easy to change between Swing, SWT, XML based GUI, etc.
- Command line interface - yes, some Unix sysadmins might want to run it that way.
- Web based interface.
- MVC - Model-View-Controller Pattern
- This classic pattern is widely used, altho the Presentation-Document pattern
below is a more common (because it's simpler) choice for small programs.
- The View component presents the output and may interact with the Model to do so.
- The Controller component accepts user input. It typically interacts with both the View and Model.
- The Model implements the logic, and knows nothing about the interface.
- Presentation-Document Pattern
- This pattern is perhaps the best choice for small GUI applications.
- The Presentation contains all user interface code (the View and Controller).
- The Document is the logic, model, etc.
- PAC - Presentation-Abstraction-Control Pattern
- This is the application of stepwise refinement to GUIs. Parts of the
GUI are each implemented as in MVC, and these parts are put together
using MVC. This is basically a recursively applied MVC model.
It would only be used for complicated GUIs.
- The Abstraction corresponds to the Model in MVC.
- The PAC pattern has a hierarchy of agents, each structured in the PAC model.
2 comments | | Score: 0
Posted by jalex on Saturday, March 05, 2005 (00:00:00) (3187 reads)