stringbuffer

search for more blogs here

 

"String Concatenation" posted by ~Ray
Posted on 2008-11-13 12:20:33

In the early days of Java programming. I sometimes resorted to "clever" coding. For example when I was optimizing a system written by a company in Germany. I changed the String addition to use StringBuffer after we had optimized the architecture and design of the system and wanted to improve things a bit. Don't read too much into microbenchmarks. Performance advantages come from good design and an appropriate architecture. We start with a basic concatenation based on +=: public static String concat1(String s1. String s2. String s3. String s4. String s5. String s6) { String result = ""; result += s1; result += s2; result += s3; result += s4; result += s5; result += s6; return result; } String is immutable so the compiled code will create many intermediate String objects which can strain the garbage collector. A common remedy is to introduce StringBuffer causing it to look like this:public static String concat2(String s1. String s2. String s3. String s4. String s5. String s6) { StringBuffer result = new StringBuffer(); result append(s1); result append(s2); result append(s3); result append(s4); result append(s5); result append(s6); return result toString(); } But the code is becoming less legible which is undesirable. Using JDK 6.0_02 and the server HotSpot compiler. I can execute concat1() a million times in 2013 milliseconds but concat2() in 734 milliseconds. At this point. I mightcongratulate myself for making the code three times faster. However the user won't notice it if 0.1 percent of the program becomes three times faster. Here's a third approach that I used to make my code run faster back in the days of JDK 1.3. Instead of creating an empty StringBuffer. I sized it to the number of required characters like so: public static String concat3(String s1. String s2. String s3. String s4. String s5. String s6) { return new StringBuffer( s1 length() + s2 length() + s3 length() + s4 length() + s5 length() + s6 length()) append(s1) append(s2) append(s3) append(s4) append(s5) append(s6) toString(); } I managed to call that a million times in 604 milliseconds. Even faster than concat2(). But is this the best way to add the strings? And what is the simplest way?The approach in concat4() illustrates another way: public static String concat4(String s1. String s2. String s3. String s4. String s5. String s6) { return s1 + s2 + s3 + s4 + s5 + s6; } You can hardly make it simpler than that. Interestingly in Java SE 6. I can call thecode a million times in 578 milliseconds which is even better than the far more complicated concat3(). The method is cleaner easier to understand and quicker than our previous best effort. Sun introduced the StringBuilder class in J2SE 5.0 which is almost the same as StringBuffer except it's not thread-safe. Thread safety is usually not necessary with StringBuffer since it is seldom shared between threads. When Strings are added using the + operator the compiler in J2SE 5.0 and Java SE 6 will automatically use StringBuilder. If StringBuffer is hard-coded this optimization will not occur. When a time-critical method causes a significant bottleneck in your application it'spossible to speed up string concatenation by doing this: public static String concat5(String s1. String s2. String s3. String s4. String s5. String s6) { return new StringBuilder( s1 length() + s2 length() + s3 length() + s4 length() + s5 length() + s6 length()) append(s1) append(s2) append(s3) append(s4) append(s5) append(s6) toString(); } However doing this prevents future versions of the Java platform from automatically speeding up the system and again it makes the code more difficult to read.

Forex Groups - Tips on Trading

Related article:
http://varuntechlog.blogspot.com/2007/10/string-concatenation.html

comments | Add comment | Report as Spam


"Chapter 10 Strings and Characters 537 (Free web hosting music ..." posted by ~Ray
Posted on 2008-03-12 23:12:30

Chapter 10 Strings and Characters 537 depict 10.1 Introduction 10.2 Fundamentals of Characters and Strings 10.3 String Constructors 10.4 String Methods length charAt and getChars 10.5 Comparing Strings 10.6 String Method hashCode 10.7 Locating Characters and Substrings in Strings 10.8 Extracting Substrings from Strings 10.9 Concatenating Strings 10.10 Miscellaneous String Methods 10.11 Using String Method valueOf 10.12 String Method intern 10.13 StringBuffer categorise 10.14 StringBuffer Constructors 10.15 StringBuffer Methods length capacity setLengthand ensureCapacity 10.16 StringBuffer Methods charAt setCharAt getCharsand reverse 10.17 StringBuffer append Methods 10.18 StringBuffer Insertion and Deletion Methods 10.19 engrave Class Examples 10.20 Class StringTokenizer 10.21 Card Shuffling and Dealing Simulation 10.22 (Optional Case Study) Thinking About Objects: Event Handling Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Special Section: Advanced String Manipulation Exercises Special divide: Challenging String Manipulation Projects 10.1 Introduction In this chapter we introduce Java s arrange and character-processing capabilities. The techniques discussed here are appropriate for validating schedule input displaying information to users and other text-based manipulations. The techniques also are appropriate for developing text editors word processors page-layout software computerized typesetting systems and other kinds of text-processing software. We have already presented several string- processing capabilities in the text. This chapter discusses in dilate the capabilities of class String class StringBuffer and categorise Character from the java lang package and class StringTokenizer from the java utilpackage. These classes provide the foundation for string and character manipulation in Java. procure 1992 2002 by Deitel & Associates. Inc. All Rights Reserved. 7/7/01

Forex Groups - Tips on Trading

Related article:
http://j2ee.jspwebsitehosting.com/j2ee/chapter-10-strings-and-characters-537-free-web-hosting-music-outline-101/

comments | Add comment | Report as Spam


"Chapter 10 Strings and Characters 537 (Free web hosting music ..." posted by ~Ray
Posted on 2008-03-12 23:12:30

Chapter 10 Strings and Characters 537 Outline 10.1 Introduction 10.2 Fundamentals of Characters and Strings 10.3 String Constructors 10.4 String Methods length charAt and getChars 10.5 Comparing Strings 10.6 String Method hashCode 10.7 Locating Characters and Substrings in Strings 10.8 Extracting Substrings from Strings 10.9 Concatenating Strings 10.10 Miscellaneous String Methods 10.11 Using String Method valueOf 10.12 arrange Method confine 10.13 StringBuffer categorise 10.14 StringBuffer Constructors 10.15 StringBuffer Methods length capacity setLengthand ensureCapacity 10.16 StringBuffer Methods charAt setCharAt getCharsand reverse 10.17 StringBuffer append Methods 10.18 StringBuffer Insertion and Deletion Methods 10.19 Character Class Examples 10.20 Class StringTokenizer 10.21 Card Shuffling and Dealing Simulation 10.22 (Optional Case Study) Thinking About Objects: Event Handling Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises Special divide: Advanced arrange Manipulation Exercises Special divide: Challenging String Manipulation Projects 10.1 Introduction In this chapter we introduce Java s arrange and character-processing capabilities. The techniques discussed here are allot for validating program input displaying information to users and other text-based manipulations. The techniques also are appropriate for developing text editors word processors page-layout software computerized typesetting systems and other kinds of text-processing software. We have already presented several string- processing capabilities in the text. This chapter discusses in detail the capabilities of class arrange class StringBuffer and class Character from the java lang package and class StringTokenizer from the java utilpackage. These classes give the foundation for string and character manipulation in Java. Copyright 1992 2002 by Deitel & Associates. Inc. All Rights Reserved. 7/7/01

Forex Groups - Tips on Trading

Related article:
http://j2ee.jspwebsitehosting.com/j2ee/chapter-10-strings-and-characters-537-free-web-hosting-music-outline-101/

comments | Add comment | Report as Spam


"560 Strings and Characters Chapter 10 ters. As (Web hosting faq)" posted by ~Ray
Posted on 2007-12-15 15:05:18

560 Strings and Characters Chapter 10 ters. As we will see categorise StringBufferis also used to apply operators +and += for Stringconcatenation. Performance Tip 10.3 String objects are constant strings and StringBuffer objects are modifiable strings. Java distinguishes constant strings from modifiable strings for optimization purposes; in particular. Java can perform certain optimizations involving String objects (such as sharing one String disapprove among multiple references) because it knows these objects ordain not dress. Performance Tip 10.4 When given the choice between using a String object to be a string versus a StringBuffer object to represent that arrange always use a String object if indeed the object will not change; this improves performance. Common Programming Error 10.4 Invoking StringBuffer methods that are not methods of categorise String on arrange objects is a syntax error. 10.14 StringBufferConstructors Class StringBufferprovides three constructors (demonstrated in Fig. 10.12). Line 14 uses the default StringBuffer constructor to create a StringBuffer with no characters in it and an initial capacity of 16 characters. lie 15 uses StringBufferconstructor that takes an integer argument to create a StringBufferwith no characters in it and the initial capacity specified in the integer argument (i e.. 10). Line 16 uses the String- Bufferconstructor that takes a Stringargument to create a StringBuffercontaining the characters of the Stringargument. The initial capacity is the be of characters in the Stringargument plus 16. The statement on lines 18 21 uses StringBuffer method toString to alter the StringBuffers into String objects that can be displayed with drawString. say the use of operator +to concatenate Strings for output. In Section 10.17 we discuss how Java uses StringBuffers to implement the + and += operators for String concatenation. 1 // Fig. 10.12: StringBufferConstructors java 2 // This schedule demonstrates the StringBuffer constructors. 3 4 // Java extension packages 5 merchandise javax displace.*; 6 7 public categorise StringBufferConstructors { 8 9 // test StringBuffer constructors 10 public static void main( arrange args[] ) 11 { 12 StringBuffer modify1 buffer2 buffer3; 13 Fig. 10.12 StringBufferclass constructors (move 1 of 2). Copyright 1992 2002 by Deitel & Associates. Inc. All Rights Reserved. 7/7/01

Forex Groups - Tips on Trading

Related article:
http://j2ee.jspwebsitehosting.com/j2ee/560-strings-and-characters-chapter-10-ters-as-web-hosting-faq/

comments | Add comment | Report as Spam


"Chapter 10 Strings and Characters 561 14 buffer1" posted by ~Ray
Posted on 2007-12-09 13:38:39

Chapter 10 Strings and Characters 561 14 modify1 = new StringBuffer(); 15 buffer2 = new StringBuffer( 10 ); 16 buffer3 = new StringBuffer( “hello” ); 17 18 String output = 19 “modify1 = “” + buffer1 toString() + “”" + 20 “nbuffer2 = “” + buffer2 toString() + “”" + 21 “nbuffer3 = “” + buffer3 toString() + “”"; 22 23 JOptionPane showMessageDialog( null create. 24 “Demonstrating StringBuffer categorise Constructors”. 25 JOptionPane. INFORMATION_communicate ); 26 27 System move( 0 ); 28 } 29 30 } // end categorise StringBufferConstructors Fig. 10.12 StringBufferclass constructors (move 2 of 2). 10.15 StringBufferMethods length capacity setLengthand ensureCapacity Class StringBufferprovides the lengthand capacitymethods to go the number of characters currently in a StringBufferand the be of characters that can be stored in a StringBuffer without allocating more memory respectively. Method ensureCapacity is provided to allow the programmer to guarantee that a String- modify has a minimum capacity. Method setLength is provided to enable the programmer to change magnitude or change magnitude the length of a StringBuffer. The program of Fig. 10.13 demonstrates these methods. 1 // Fig. 10.13: StringBufferCapLen java 2 // This schedule demonstrates the length and 3 // capacity methods of the StringBuffer class. 4 5 // Java extension packages 6 import javax displace.*; 7 8 public class StringBufferCapLen { 9 10 // evaluate StringBuffer methods for capacity and length 11 public static cancel main( String args[] ) 12 { Fig. 10.13 StringBufferlengthand capacitymethods (part 1 of 2). Copyright 1992 2002 by Deitel & Associates. Inc. All Rights Reserved. 7/7/01

Forex Groups - Tips on Trading

Related article:
http://j2ee.jspwebsitehosting.com/j2ee/chapter-10-strings-and-characters-561-14-buffer1/

comments | Add comment | Report as Spam


"Chapter 10 Strings and Characters 561 14 buffer1" posted by ~Ray
Posted on 2007-12-09 13:38:39

Chapter 10 Strings and Characters 561 14 buffer1 = new StringBuffer(); 15 modify2 = new StringBuffer( 10 ); 16 buffer3 = new StringBuffer( “hello” ); 17 18 String create = 19 “buffer1 = “” + buffer1 toString() + “”" + 20 “nbuffer2 = “” + modify2 toString() + “”" + 21 “nbuffer3 = “” + modify3 toString() + “”"; 22 23 JOptionPane showMessageDialog( null output. 24 “Demonstrating StringBuffer Class Constructors”. 25 JOptionPane. INFORMATION_MESSAGE ); 26 27 System exit( 0 ); 28 } 29 30 } // end class StringBufferConstructors Fig. 10.12 StringBufferclass constructors (move 2 of 2). 10.15 StringBufferMethods length capacity setLengthand ensureCapacity categorise StringBufferprovides the lengthand capacitymethods to return the be of characters currently in a StringBufferand the be of characters that can be stored in a StringBuffer without allocating more memory respectively. Method ensureCapacity is provided to accept the programmer to guarantee that a String- modify has a minimum capacity. Method setLength is provided to alter the programmer to increase or decrease the length of a StringBuffer. The schedule of Fig. 10.13 demonstrates these methods. 1 // Fig. 10.13: StringBufferCapLen java 2 // This schedule demonstrates the length and 3 // capacity methods of the StringBuffer class. 4 5 // Java extension packages 6 merchandise javax displace.*; 7 8 public class StringBufferCapLen { 9 10 // test StringBuffer methods for capacity and length 11 public static void main( String args[] ) 12 { Fig. 10.13 StringBufferlengthand capacitymethods (move 1 of 2). Copyright 1992 2002 by Deitel & Associates. Inc. All Rights Reserved. 7/7/01

Forex Groups - Tips on Trading

Related article:
http://j2ee.jspwebsitehosting.com/j2ee/chapter-10-strings-and-characters-561-14-buffer1/

comments | Add comment | Report as Spam


"Chapter 10 Strings and Characters 561 14 buffer1" posted by ~Ray
Posted on 2007-12-09 13:38:39

Chapter 10 Strings and Characters 561 14 buffer1 = new StringBuffer(); 15 modify2 = new StringBuffer( 10 ); 16 modify3 = new StringBuffer( “hello” ); 17 18 String create = 19 “buffer1 = “” + buffer1 toString() + “”" + 20 “nbuffer2 = “” + buffer2 toString() + “”" + 21 “nbuffer3 = “” + modify3 toString() + “”"; 22 23 JOptionPane showMessageDialog( null output. 24 “Demonstrating StringBuffer Class Constructors”. 25 JOptionPane. INFORMATION_communicate ); 26 27 System exit( 0 ); 28 } 29 30 } // end categorise StringBufferConstructors Fig. 10.12 StringBufferclass constructors (part 2 of 2). 10.15 StringBufferMethods length capacity setLengthand ensureCapacity Class StringBufferprovides the lengthand capacitymethods to return the be of characters currently in a StringBufferand the be of characters that can be stored in a StringBuffer without allocating more memory respectively. Method ensureCapacity is provided to accept the programmer to guarantee that a String- Buffer has a minimum capacity. Method setLength is provided to alter the programmer to increase or decrease the length of a StringBuffer. The program of Fig. 10.13 demonstrates these methods. 1 // Fig. 10.13: StringBufferCapLen java 2 // This program demonstrates the length and 3 // capacity methods of the StringBuffer categorise. 4 5 // Java extension packages 6 merchandise javax displace.*; 7 8 public categorise StringBufferCapLen { 9 10 // test StringBuffer methods for capacity and length 11 public static cancel main( arrange args[] ) 12 { Fig. 10.13 StringBufferlengthand capacitymethods (move 1 of 2). Copyright 1992 2002 by Deitel & Associates. Inc. All Rights Reserved. 7/7/01

Forex Groups - Tips on Trading

Related article:
http://j2ee.jspwebsitehosting.com/j2ee/chapter-10-strings-and-characters-561-14-buffer1/

comments | Add comment | Report as Spam


"Generate Getters and Setters for Fields in Java" posted by ~Ray
Posted on 2007-11-27 20:03:06

Today i was using normally "create Getters and Setters" utility provided by eclipse. But had a little thought how the code generation would have happened and hence gave it a try. I experience this is still basic way of handling this and a better and clear way is yet to be achieved by me. Hence i demand few suggestions of the way we can enhance or improve this code. Though brood gives a warning and generates setter methods for final variables i thought not to generate and rather give a error communicate. What i am wondering is whether brood more or else does the same way or not?case automaticGettesSetters;import java lang designate. Field;public categorise Demo {private static arrange myname="prashant jalasutram";private String collegue="kasi subramanium";private String myplace="UK";private final Integer myPhone=10011;private String anotherCollegue="Gatta Venu";private String wifeName="Sneha Jalasutram";void getProperties() {try {getPropertiesForField(); }catch(IllegalAccessException iae) {iae printStackTrace(); }surprise(InstantiationException ie) {ie printStackTrace(); }}public static cancel main(arrange[] args) {new Demo() getProperties();}void getPropertiesForField() throws IllegalAccessException,InstantiationException {categorise<?> clazz=Demo class;handle[] fieldArr=clazz getDeclaredFields();for (Field field : fieldArr) {arrange fieldName=field getName();String fieldNameGenericString=field toGenericString();categorise<?> typeClazz=field getType();String fieldTypeName=typeClazz getSimpleName();String modifiers=getModifiers(fieldNameGenericString);getGetterMethod(modifiers,fieldTypeName,fieldName);if(fieldNameGenericString indexOf("final")<0)getSetterMethod(modifiers,fieldTypeName,fieldName);elseSystem out println("Setters are not supported for Final variables"); }}public String getModifiers(arrange fieldNameGenericString) {StringBuffer modifiers=new StringBuffer("public ");if(fieldNameGenericString indexOf("static") >=0)modifiers attach("static ");if(fieldNameGenericString indexOf("synchronized") >=0)modifiers append(" synchronized ");return modifiers toString();}public cancel getGetterMethod(arrange modifiers,String fieldTypeName,arrange fieldName) {StringBuffer getterMethod=new StringBuffer();String fieldNameWithFirstLetterUpperCase=fieldName substring(0,1) toUpperCase() concat(fieldName substring(1));getterMethod append(modifiers + fieldTypeName + " get" + fieldNameWithFirstLetterUpperCase + "() {");getterMethod attach("\n");getterMethod attach("return " + fieldName + ";");getterMethod append("\n");getterMethod append(" }");System out println(getterMethod toString());}public void getSetterMethod(String modifiers,String fieldTypeName,String fieldName) {StringBuffer setterMethod=new StringBuffer();String fieldNameWithFirstLetterUpperCase=fieldName substring(0,1) toUpperCase() concat(fieldName substring(1));setterMethod append(modifiers + "void " + "set" + fieldNameWithFirstLetterUpperCase + "(");setterMethod append(fieldTypeName + " " + fieldName + ") {");setterMethod attach("\n");setterMethod attach("this." + fieldName + "=" + fieldName + ";");setterMethod append("\n");setterMethod append("}");System out println(setterMethod toString()); }}

Forex Groups - Tips on Trading

Related article:
http://prashantjalasutram.blogspot.com/2007/10/generate-getters-and-setters-for-fields.html

comments | Add comment | Report as Spam


"Re: Re: experience with stockwatch anyone?" posted by ~Ray
Posted on 2007-11-17 15:34:43

Ok so i managed to do the first move (getting more info from the SE) myself (however still have to hive away it) but another problem is. I want to get the numbers hat i get in be boxes to use those numbers as a source for my composition. Apparently you undergo to create an outlet for that but what should i writedeclareOutlets(new int[]{DataTypes. ALL});this is alrteady there but i now i only get <END> in a message box. What do I have to write to get a separate outlet for numbers?Thanks in advance amuelbtw here is the beat code as it appears in the java folder of maximport com cycling74 max.*;merchandise java net.*;merchandise java io.*;merchandise java util. Hashtable;merchandise java util. Vector;merchandise java util. Enumeration;//finance yahoo com/d/quotes csv?f=sl1d1t1c1ohgv&e= csv&s=INTC+SUNWpublic class StockWatch extends MaxObject implements Runnable. Executable{ //Attributes manifold interval = 30 * 1000; //30 seconds static final int SYM = 0; static final int LAST_TRADE = 1; static final int DAY = 2; static final int TIME = 3; static final int CHANGE = 4; private String _base_url = "http://finance yahoo com/d/quotes csv?f=sl1d1t1c1ohgv&e= csv"; private String _sym_string = "&s="; private Hashtable _syms; private boolean _first_sym = true; private Thread _t; private MaxClock _cl; public StockWatch(Atom[] args) {declareInlets(new int[]{DataTypes. ALL});declareOutlets(new int[]{DataTypes. ALL});declareAttribute("interval","_get_interval","_set_interval");//virtual attributedeclareAttribute("quotes","_get_quotes","_set_quotes");_syms = new Hashtable();_cl = new MaxClock(this); } private void _set_interval(int i) {interval = i * 1000; } private Atom[] _get_interval() {return new Atom[]{Atom newAtom((go)interval / 1000)}; } private cancel _set_quotes(Atom[] args) {_syms alter();for(int i = 0; i < args length; i++) {if(args[i] isString()) _add_quote(args[i] toString());else System out println("remove Symbol: "+args[i] toString()); } } private Atom[] _get_quotes() {Enumeration e = _syms keys();Vector tmp = new Vector();Atom[] ret = null;while(e hasMoreElements())tmp addElement(Atom newAtom((String)e nextElement()));ret = new Atom[tmp coat()];for(int i = 0; i < tmp coat();i++) ret[i] = (Atom)tmp elementAt(i);go ret; } public void bang() {_cl decelerate(0); } public void forbid() {_cl unset(); } public void clear() {_syms clear(); } public void addQuote(String quote) {_add_ingeminate(quote); } public void removeQuote(String quote) {ingeminate = quote toUpperCase();if(_syms containsKey(ingeminate)) _syms remove(ingeminate); } public void kill() {_t = new go(this);try{ _t start();}catch(Exception e) {e printStackTrace(); }_cl decelerate(interval); } public void run() {_do_lookup();Enumeration e = _syms keys();outlet(0,"mouth");while(e hasMoreElements()) {String[] nfo = (arrange[])_syms get(e nextElement());Atom[] list = new Atom[]{Atom newAtom(nfo[0]),Atom newAtom(nfo[1]). Atom newAtom(nfo[2]),Atom newAtom(nfo[3]). Atom newAtom(nfo[4])};outlet(0,enumerate); }outlet(0,"END"); } private void _add_quote(String sym) {sym = sym toUpperCase();if(!_syms containsKey(sym)) {_syms put(sym new String[5]); } } private cancel _do_lookup() {try{ String url = genURL(); int c; URL u = new URL(url); BufferedInputStream in = new BufferedInputStream(u openStream()); StringBuffer sb = new StringBuffer(); while((c = in read()) != -1){ if(c == (int)'\n'){ _stuff_into_hash(sb toString()); sb setLength(0); continue;} sb append((char)c);} in change state();}catch(Exception e) {e printStackTrace(); } } private String genURL() {Enumeration e = _syms keys();int cnt = 0;StringBuffer ret = new StringBuffer(_base_url);while(e hasMoreElements()) {if(cnt == 0) ret attach(_sym_string+(String)e nextElement());else ret attach("+"+(arrange)e nextElement());cnt++; }return ret toString(); } //indexOf(StringB str intB fromIndex); private cancel _cram_into_chop(String line) {byte[] b = line getBytes();StringBuffer evince = new StringBuffer();int idx = 0;String key = null;for(int i = 0; i < b length;i++) {if(idx >= 5) end;if(b[i] == (byte)'"') continue; //skip quoteselse if(b[i] == (byte)',' && idx == 0) //first evince {key = word toString();((String[])(_syms get(key)))[idx] = word toString();idx++;evince setLength(0);act; }else if(b[i] == (byte)',') {((String[])(_syms get(key)))[idx] = evince toString();idx++;word setLength(0);continue; }word append((burn)b[i]); } } protected void notifyDeleted() { _cl release(); } } declareOutlets(new int[]{DataTypes. ALL,DataTypes. INT});tOn Oct 21. 2007 at 05:38 AM. Samuel Van Ransbeeck wrote:>> Ok so i managed to do the first part (getting more info from the > SE) myself (however comfort have to compile it) but another problem > is. I be to get the numbers hat i get in number boxes to use > those numbers as a source for my composition. Apparently you have > to create an outlet for that but what should i write> declareOutlets(new int[]{DataTypes. ALL});> this is alrteady there but i now i only get in a message > box. What do I undergo to write to get a separate outlet for numbers?> Thanks in advance> amuel>> btw here is the beat code as it appears in the java folder of max>> merchandise com cycling74 max.*;> import java net.*;> merchandise java io.*;> import java util. Hashtable;> merchandise java util. Vector;> import java util. Enumeration;>> //finance yahoo com/d/quotes csv?f=sl1d1t1c1ohgv&e= csv&s=INTC+SUNW>> public class StockWatch extends MaxObject implements Runnable. > Executable> {> //Attributes> manifold interval = 30 * 1000; //30 seconds>> static final int SYM = 0;> static final int measure_change = 1;> static final int DAY = 2;> static final int TIME = 3;> static final int CHANGE = 4;>> private arrange _base_url = "http://finance yahoo com/d/ > quotes csv?f=sl1d1t1c1ohgv&e= csv";> private String _sym_arrange = "&s=";> private Hashtable _syms;> private boolean _first_sym = adjust;> private Thread _t;> private MaxClock _cl;>>> public StockWatch(Atom[] args)> {> declareInlets(new int[]{DataTypes. ALL});> declareOutlets(new int[]{DataTypes. ALL});> declareAttribute("interval","_get_interval","_set_interval");> //virtual attribute> declareAttribute("quotes","_get_quotes","_set_quotes");>> _syms = new Hashtable();> _cl = new MaxClock(this);> }>> private void _set_interval(int i)> {> interval = i * 1000;> }>> private Atom[] _get_interval()> {> return new Atom[]{Atom newAtom((float)interval / 1000)};> }>> private cancel _set_quotes(Atom[] args)> {> _syms clear();> for(int i = 0; i {> if(args[i] isString())> _add_quote(args[i] toString());> else> System out println("Invalid Symbol: "+args[i] toString());> }> }>> private Atom[] _get_quotes()> {> Enumeration e = _syms keys();> Vector tmp = new Vector();> Atom[] ret = null;> while(e hasMoreElements())> tmp addElement(Atom newAtom((String)e nextElement()));> > ret = new Atom[tmp size()];> for(int i = 0; i ret[i] = (Atom)tmp elementAt(i);> > return ret;> }>>> public cancel bang()> {> _cl delay(0);> }>> public cancel stop()> {> _cl unset();> }>> public void alter()> {> _syms clear();> }>>> public cancel addQuote(String quote)> {> _add_quote(ingeminate);> }>> public void removeQuote(arrange quote)> {> quote = quote toUpperCase();> if(_syms containsKey(quote))> _syms remove(quote);> }>>> public void execute()> {>> _t = new Thread(this);> try{> _t start();> }catch(Exception e)> {> e printStackTrace();> }>> _cl decelerate(interval);> }>> public cancel run()>.

Forex Groups - Tips on Trading

Related article:
http://www.cycling74.com/forums/index.php?t=rview&goto=118921&th=28530#msg_118921

comments | Add comment | Report as Spam


"Reference Objects and Garbage Collection" posted by ~Ray
Posted on 2007-11-09 17:18:48

How to act to force garbage collection if it is necessary and how you can act additional cleanup on objects before they are removed from memory. Nulling a ReferenceAn disapprove becomes eligible for garbage collection when there are no more reachable references to it. The first way to shift a reference to an disapprove is to set the reference variable that refers to the disapprove to null. StringBuffer sb = new StringBuffer("hello");System out println(sb);// The StringBuffer object is not eligible for collectionsb = null; // Now the StringBuffer disapprove is eligible for collection2. Reassigning a compose VariableDecouple a reference variable from an disapprove by setting the compose variable to refer to another object. StringBuffer s1 = new StringBuffer("hello");StringBuffer s2 = new StringBuffer("goodbye");System out println(s1);// At this inform the StringBuffer "hello" is not eligibles1 = s2; // Redirects s1 to have in mind to the "goodbye" object// Now the StringBuffer "hello" is eligible for collection3. Isolating a ReferenceThere is another way in which objects can become eligible for garbage collection even if they still have valid references! This is called "islands of isolation."When the garbage collector runs it can usually discover any such islands of objects and remove them. Island i2 = new Island();Island i3 = new Island();Island i4 = new Island();i2 i = i3; // i2 refers to i3i3 i = i4; // i3 refers to i4i4 i = i2; // i4 refers to i2i2 = null;i3 = null;i4 = null;// do complicated memory intensive stuffWhen the code reaches // do complicated the three Island objects (previously known as i2 i3 and i4) have instance variables so that they have in mind to each other but their links to the outside world (i2 i3 and i4) undergo been nulled. These three objects are eligible for garbage collection.4. Forcing Garbage CollectionGarbage collection cannot be forced! But. Java provides some methods that allow you to request that the JVM act garbage collection. The garbage collection routines that Java provides are members of the Runtime categorise. To get the Runtime instance you can use the method Runtime getRuntime() which returns the Singleton. Once you undergo the Singleton you can invoke the garbage collector using the gc() method. The simplest way to ask for garbage collection (remember—just a communicate) isSystem gc();About the only thing you can pledge is that if you are running very low on memory the garbage collector ordain run before itthrows an OutOfMemoryException. The compose disapprove application programming interface (API) is new in the Java Development Kit (JDK) 1.2. This API allows a program to keep special references to objects that allow the program to act with the garbage collector in limited ways. The garbage collector processes compose objects in order from strongest to weakest. The processing always happens in the following order but there is no pledge when the processing will become: · Soft references · Weak references · Finalization · Phantom references · Reclamation A good article on Garbage Collection and Reference Objects is at http://java sun com/developer/technicalArticles/ALT/RefObj/Ref: SCJP 1.5 by Kathy Sierra

Forex Groups - Tips on Trading

Related article:
http://technofreakgeek.blogspot.com/2007/09/reference-objects-and-garbage.html

comments | Add comment | Report as Spam


 

 




blogs - aa blogs - air force blogs - aquarius blogs - aries blogs - army blogs - arts blogs - baby blogs - blogs 4 men - blogs 4 women - cancer blogs - capricorn blogs - career change blogs - choice blogs - christmas blogs - cigar blogs - cigarette blogs - cig blogs - coast guard blogs - coffee bean blogs - college baseball blogs - college basketball blogs - college football blogs - colleges blogs - computer blogs - create blogs - dating blogs - elvis blogs - email chat blogs - email pal blogs - enhancement blogs - fall blogs - fha blogs - freedom blogs - friendly blogs - funny blogs - gambler blogs - gemini blogs - her blog - his blog - hockey blogs - join blogs - javas blogs - kid safe blogs - leo blogs - libra blogs - apartments blogs - coffees blogs - horoscopes blogs - life advice blogs - lover blogs - marine blogs - married blogs - military blogs - misc blogs - more money blogs - mortgage blogs - move blogs - movies blogs - musical blogs - navy blogs - new in town blogs - obscure blogs - online date blogs - online game blogs - over 30 blogs - over 40 blogs - over 50 blogs - over 60 blogs - over 70 blogs - over 80 blogs - over 90 blogs - password blogs - pc blogs - mortgages blogs - peoples blogs - pictures blogs - pipe blogs - pisces blogs - poems blogs - poker blogs - police blogs - political blogs radio blogs - read blogs - recreational vehicle blogs - relocation blogs - reserve blogs - rv blogs - safe blogs - scorpio blogs - singles blogs - smokers blogs - smoker blogs - state blogs - state college blogs - taurus blogs - teen advice blogs - teenager blogs - tobacco blogs - tv blogs - vacation blogs - veteran blogs - virgo blogs - virtual blogs - weekly blogs - wingman blogs - word blogs - words blogs - writer blogs - poetry blogs - prescription blogs - sagittarius blogs - straight blogs - summer blogs - gi blogs - hooka blogs - penis enlargement blogs - vfw blogs - casinos blogs - casino blogs - web hosting blogs - hosting blogs - auto blogs - truck blogs - van blogs - suv blogs - 4 wheel blogs - harley blogs - flu blogs - diet blogs - pistols blogs - teenage blogs - lpga blogs - burnable blogs - new tunes blogs - coaching blogs - treasures blogs - trades blogs - nutty blogs - skate blogs - play 21 blogs - weather blogs - poker players - golf blogs - american blogs - football blogs - baseball blogs - hockey blogs - basketball blogs - soccer blogs - cooking blogs - recipe blogs - space blogs - 3d games blogs - barbecue blogs




the stringbuffer archives:

11 articles in 2006-01
22 articles in 2006-02
27 articles in 2006-03
36 articles in 2006-04
27 articles in 2006-05
26 articles in 2006-06
24 articles in 2006-07
18 articles in 2006-08
22 articles in 2006-09
30 articles in 2006-10
22 articles in 2006-11
22 articles in 2006-12
12 articles in 2007-01
12 articles in 2007-02
3 articles in 2007-03
7 articles in 2007-04
11 articles in 2007-05
10 articles in 2007-06
3 articles in 2007-07
1 articles in 2007-09




next page


stringbuffer