~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess this is meant for people who are facing problems uploading attachments but yeah, even I am confused.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Ah, so you want to extract the sequence of digits 0 and 1 from the given string. It can be done easily by using a simple regular expression ([01])+ where the () are capturing/memory parentheses for recording or capturing the match.

I will leave the formation of an equivalent representation of the regular expression in Java to you. Look into the Pattern and Matcher class; the javadocs have everything you need to get started. Make an attempt and post the compilable code if you have any problems.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just to get the terminology right, a string is just a sequence of unicode characters, there is nothing `binary' in it. In the end, everything is stored as a byte, the way the byte sequence is interpreted is what makes all the difference.

If your intention here is to grab the underlying byte representation of the string, use:

String s = "bac01010111pqr14 ";

// Encodes this String into a sequence of bytes
// using the platform's default charset
byte[] bytes = s.getBytes();

// Encodes this String into a sequence of bytes
// using the given charset
byte[] bytes = s.getBytes(charSetName);
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Slim chances since this seems to be a question from a programming course and not a tricky interview question. Though it is one of the logically correct solutions, if this really were the case, no break would be needed in the original snippet. Plus the breaking condition can be something which can't be computed before hand or placed in the loop conditional, hence the suggested solution.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's pretty simple.

  • Parse the expression entered and iterate over it on a character by character basis.
  • If the given character is not a parenthesis or bracket, move over to the next one. If it is an opening parenthesis or bracket, push it on to the stack and move on to the next one.
  • If the given character is a closing parenthesis or bracket, check its compatibility by peeking at character at the top of stack. If it matches, pop the top of the stack and move on to the next character. If it doesn't, throw an error.
  • If the stack contains extra characters even after the entire expression has been parsed, throw an error.

Though I have ignored the details out there, I am pretty sure you can take it from here. Implement the above logic and post the entire code if you have any problems.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maybe have a look at Starting Java?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The 2009 Winter Preview is here!

Though I would be shameful enough watching each one them, eagerly awaited would be:

  • Akikan [since I am a harem/romance lover at heart]
  • Asu no Yoichi!
  • Birdy the Mighty Decode:02
  • Tower of Druaga ~Sword of Uruk~

...and the best of them all "Zoku Natsume Yuujinchou".

John A commented: Alright! +17
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Since all of the checkboxes have the same ID

You would be violating the specification if you had more than one HTML element with the same value of ID attribute. There are better/valid ways of identifying or a grouping together form elements. Read this.

And since you have asked for additional comments, regarding CSV's, any database design which requires the application logic to slash and hack the retrieved data is broken IMO. Also, I would assign a unique name to each check box and each check box would have one of the two class names: checked and unchecked; this would facilitate easier processing via JavaScript and application of style sheets.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes it does, since primitive member variables are assigned their default values when the instance is created; which in case of integer numeric types is 0.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> He stated that both methods are bad programming practices.

No, it isn't; don't fall into such debates as anyone who tries to convince you such is just selling snake oil. If it really were that bad, you wouldn't have found Sun's internal implementation of most of the library classes to be cluttered with them.

IMO, not all things are bad in an absolute sense; there are just good and bad ways of using the same thing.

Ezzaral commented: Exactly what I thought when I read that. +16
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's pretty easy; make full use of the conditional expression which gets tested before the body of the loop is executed. When the given condition is reached or encountered within the loop body, set a boolean flag and test the same in your loop conditional.

for(int i = 0; i < 10; ++i) {
  if(i == 5) {
    break;
  }
}

boolean done = false;
for(int i = 0; i < 10 && !done; ++i) {
  if(i == 5) {
    done = true;
  }
}

Of course you can use anything instead of a boolean but the basic premise of the solution remains the same. Make sure you skip normal execution after setting the flag otherwise the semantics of the solution changes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> people who find this query very obvious and basic,please don't
> respond.Please don't make personal attacks.

You are too oblivious to realize that you never asked a query; it was a request for someone else to do your homework. Nowhere in your post have you shown any traces of having put any effort to solve the problem at hand.

And BTW, dear `Ninad16', don't PM me telling me what I should and shouldn't do. You can't tell someone to *not* reply to your threads as long as they replies follow the forum rules and stay on topic. And yes, I felt a need to chastise an *obvious* question since you were violating a forum rule and I felt it necessary to put you on track. Read the forum announcements.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yahoo media player might just relieve you of doing things the difficult way; it's worth a look if you plan on providing streaming audio.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The value of `this' depends on the context in which the function was invoked and hence can only be known at runtime. Hence saying that "here `this' refers to XXX" holds little truth since I can very well have a object with its property set to func.a in which case the `this' will refer to the object in consideration rather than `func'.

A sample script [untested]:

<!--
`this' in ECMAscript

Copyright (C) 2008  sos aka Sanjay

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Script-Content-Type" content="text/javascript">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Example</title>
    <script type="text/javascript">
      function func() {
        return "In func() with this=" + this.name;
      }

      function A() {
        this.a = func;
        this.name = "A";
      }

      function B() {
        this.b = func;
        this.name = "B";
      }

      window.onload = function() {
        window.name = "WINDOW";
        var invokeA = new A().a();
        var invokeB = new B().b();
        var …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

From what I understand, your web page has a text field which allows the user to enter his search criteria. Based on the user input, a new set of check boxes are fetched from the server but before doing that, you need to persist the state of the check boxes currently visible to the user. Is your requirement the recording of the state of the check boxes before the new content replaces them?

If yes, then you can make two async requests; one which serializes the state of the form [the one containing the check boxes] and sends it to the server and another which fetches the new content based on the search criteria. You can even glue together both the parts by sending both the serialized form state and the search criteria in the same request.

If it's something else, you need to be a bit more explicit with some pseudo code or illustrations.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> i need to know why this problem occured and how to solve it???

Post the relevant code snippets. Are you sure you are releasing the database resources after performing the read/write?

Are you working with the database using the sqlite console and at the same time trying to query/insert into that database via your program? If yes, then try closing the console / sqlite process which uses the same file and then try again.

We need some code to figure out exactly what is going wrong.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I haven't worked with Axis so wouldn't know the context involved but like I previously suggested, either mark the field as transient or implement your own readObject and writeObject methods to get around the restriction. Search for 'serialization java' with the search engine of your choice and you should find something to get you started.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

lepetitevoddy, use code tags when posting code next time; makes reading the code snippets presented easier to read. Also read the forum rules and announcements.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What is food? What is water? What are the advantages of eating food and drinking water...?

At least make an attempt at understanding things before posting obvious questions whose answers can be easily found out using search engine of your choice.

Let's say that putting a bit of effort on your part and trying to understand things on your own is the first step towards enlightenment, my young padawan.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Templates make Template metaprogramming possible; you might want to take a look at it, pretty interesting stuff.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to mark the field of type MessageContext as transient so that the serialization mechanism doesn't attempt to serialize it. This only works if the state of the MessageContext has no significance whatsoever to the newly reconstituted SoapPair object. If it does, then you have to manually write out the state of the MessageContext object for which you will have to provide an implementation for readObject and writeObject methods for your SoapPair class.

But given that if the MessageContext class isn't Serializable , there might be a good reason behind it. Are you sure the MessageContext instance *really* constitutes the state of your SoapPair object? Also given that any context logically belongs to a given environment, serializing it or clubbing it with something which is meant to be serialized doesn't make much sense.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Read the sticky at the top of the forum meant specifically for people starting out with Java.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A few recommendations:
- Javascript the definitive guide 5th edition
- ppk on Javascript
- Professional javascript for web developers [wrox]

You can take a sneak peak at these books at google books.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Proper encoding headers need to be set when requesting and serving the resource e.g. Content-Type and Content-Encoding. Just having utf-8 charset doesn't mean the content is not encoded in some other encoding. Inspect the requested .js file in a unicode aware text editor and see if it really is unicode encoded or just platform default encoded data served with a unicode encoding.

Encoding related issues mostly revolve around incorrect encoding used when serving data or having data which isn't utf encoded and being served as unicode.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I can't figure out how to write to a specific line of a text file.

An efficient way would be to open the file using a RandomAccessFile in read/write mode though things can get pretty nasty if care is not exercised. Almost all other methods include reading a line from the target file, processing it and then writing it to a destination file.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Every call cause store whole array on the stack.

No it doesn't. Arrays in Java are objects and when invoking methods with object references, copy of the reference is created and copied to the stack frame which is then pushed onto the call stack [the stack which maintains the state (stack frame) of the currently executing methods]. The actual array still lives in the heap.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It would be appreciated if you used the actual links instead of referring them via some redirection service; read this. Many firewalls out there block any request made via the redirection services, McAfee being one of them. BTW, even my firewall/anti-virus software blocks TinyURL links.

Daniweb has a feature which is available in both quick reply and advanced reply mode known as `Insert link' which can be used if you have a problem with long and ugly URLs.

stephen84s commented: Dint know Tiny URLS could cause BIG problems like those. +4
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Read this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I meant post a reply here once it is completed and up on sourceforge, so that I can get a notification; it might interest the kids new to Java.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

So, were you trying it on Eclipse or windows console? BTW, bump this thread when your project is completed. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> String[] sentences = str.split("(?<=[\\.!?]+)(?![\\.!?]+) *");

Like previously mentioned, you don't need to escape regular expression meta characters inside bracketed character classes. Hence [.!?]+ to be used instead of [\\.!?]+ .

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If you plan on viewing the output on Eclipses's console, it shouldn't be that big a problem. Try following the advice in this post.

But if you are stuck with windows console, then there isn't a reliable / sure shot way of getting it to work. Many have suggested setting the code page to 65001 though I am not very sure whether it works in all cases.

Let me know if the above suggested fixes work in your case. Best of luck for your project; hoping to see it on sourceforge. ;-)

puneetkay commented: Superb! Thanks for help! +2
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Because number can be greater or smaller then other number,
> however you can not apply same logic to characters

Yes, you can, because characters form a part of numeric data type. There are only two primitive types in Java: boolean and numeric.

Directly comparing characters can be troublesome if your application is aimed at providing internationalization in which case some sort of unicode sensitive comparison needs to be provided.

> Couldn't you also convert the char to an integer, then compare
> the two chars?

Not applicable to the discussion here; read above.

> My program keeps looping when asking for seat letter. Can anyone
> help me out as to why that is?

As I see now, your program is a complete mess with the core logic tightly coupled with I/O and hard coded magic number everywhere. Try redesigning your application and assigning proper responsibilities to well thought out classes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There is as such no problem with your code; IMO the fault lies with the incompetence of the shell to render fonts correctly. I assume you are on a windows box? Anyways, this is just a rendering issue. Maybe a little more background on what you are trying to achieve here would be required to offer some advice.

Anyways, to mess around with code points and to get a feel of how the characters looks, try this sample snippet which creates an HTML document 'test.html'.

// Error handling and best practices omitted for brevity

public class HtmlTester {

  private final static String HTML = 
  "<html><head><META HTTP-EQUIV=\"Content-Type\" " +
      "CONTENT=\"text/html; charset=UTF-8\"></head><body><div>{0}" +
      "</div></body></html>";

  public static void main(final String[] args) throws Exception {
    testIt();
  }

  public static void testIt() throws Exception {
    String toWrite = MessageFormat.
      format(HTML, String.valueOf("\u0A72 \u0A73 \u0A74"));
    writeData(toWrite, new File("test.html"));
  }

  public static void writeData(String s, File f) {
    try {
      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
          new FileOutputStream(f), "utf-8"));
      out.write(s);
      out.flush();
      out.close();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }

}

The gurmukhi characters are displayed correctly since I guess browsers have their own font rendering engine.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use Apache Ant as a build tool to compile your application with dependencies or just use the command line invocation of `javac' and `java' which supports classpath options.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

At least post your attempt in terms of indexOf and substring indicating the problem you are facing.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You have two options:
- If your delimiters are simple single character sequences [. and !] in your case, you can try looping over the entire string and extracting the relevant parts using indexOf and substring
- If your delimiters end up being multi-character sequences you can try to use the hammer of text processing i.e. regular expressions.

A sample implementation:

import java.util.regex.*;

public class SentenceTester {

  public static void main(final String[] args) {
    splitTest();
  }

  // Implement a splitting logic using regex which also works for 
  // multi line strings.
  private static void splitTest() {
    String line = "hello there!!!!! how're you doing? " + 
      "\ni am pretty sure you are doing well.\nright?";

    // Pattern: Any-of-.?!{1, n} followed by whitespace{0, n}
    Pattern pat = Pattern.compile("[.?!]+\\s*", Pattern.DOTALL);

    // Create matcher instance which will match the given regex with
    // the line in consideration.
    Matcher mat = pat.matcher(line);

    int start = 0, end = 0;
    while(mat.find()) {
      start = end;
      // return a `1 based index' into the string where the pattern
      // match ends. Hence when `end' is 17 means character at 
      // position 18 in the string.
      end = mat.end();
      System.out.println("#" + line.substring(start, end) + "#");
    }    
  }

}

> So in effect when the regex parser encounters it the expression is reduced
> to "\.?!", this "\" indicates to the regex parser that the following "." is not a
> regex quantifier.

The quantifiers lose their special meaning when used inside …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> But, sometimes, I just don't feel like taking the effort to try
> talking them out of it.

Yes, even I get that sort of feeling but seeing that VernonDozier is a Daniweb regular, I took my chances. ;-)

> that calling getRed () really slowed the program down and that
> there was a lot of overhead with it, but that's not true, is it?

No, it isn't, really. If you are still concerned about calling the same method again and again, instead of having your class maintain the state or cache the `red' value, shove the responsibility to the invoked method instead.

private void mutate() {
  int red = color.getRed();
  // some complicated, multi step calculation using `red'
  color.setRed(red);
}

And talking of terms like overhead for a program without any concrete profiling data whatsoever is wrong IMO.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

...and don't let anyone convince you otherwise; we have got prooof [sic]. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It gives me immense pleasure to mark this thread as solved. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Ah, this is what I get for posting a reply based on the thread title. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No, at least not when using the standard library because in *nix, the creation time isn't stored anywhere. If you are running on a windows box, you have two options:
- spawn a shell process which fires the command 'dir /a' and extract the creation time [easiest]
- Use JNI, maybe something like FileTimes library

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Wha..?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In Java, everything is passed by value; in case of primitive types, a copy of the value is created and then passed as an argument to the method invoked.

private void mutateItNot(int v) {
  v = 10; // no effect on the original integer value
          // this `v' is just a copy of the `int' being passed
}

In case of references, a copy of the reference variable is created and then passed as an argument to the invoked method. Think of this as a remote control used to regulate the functioning of a T.V. When a reference type is passed to the method, a copy of it i.e. a copy of the remote is created which in the end is used to manipulate the same T.V. You can regulate the T.V. with this cloned remote in the same way as you would do with the original but destroying this remote has no effect on the original.

private void mutateItNot(SomeThing s) {
  // use the reference to manipulate the object it points to
  // [assuming we are not talking about immutable classes here]
  s.setField(someValue); 
  s = null; // the clone is now made to point to nothing
            // with absolutely no effect on the original
}

> I'm also storing the red, green, blue, alpha values as integer
> attributes in those classes because I am using them a lot

Why? Ease of use? Performance? This is no sane reason to duplicate data; your class instance …

stephen84s commented: Earlier had created a mess answering a similar question, this was very well put. +4
VernonDozier commented: Good explanation +10
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

One of the important things you should know as a Java developer is to find the classes in the standard library which contain the functionality you desire. As an example, since you need to operate on Strings and need to generate a char array, looking into the documentation of String and Character classes should be your first step. If that fails, try looking into the java.util package for utility methods which operate on your data. If you need help with text processing and formatting, java.text package should be good to go. This is a pretty good exercise and will actually make you aware of the functionality provided by the Java standard library.

If that fails, use your favorite search engine to give you a solution to your problem. In your case, searching for 'convert string to char array' hit the spot right on.

When everything fails, use discussion groups as your last resort. It's not too much work, really, and if you feel it is, then think that it for your own good. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In the code posted I don't see the stream/writer being closed. Variable names like cloudOut1 through cloudOut11 suggest there is something seriously wrong with your design. Try writing out a small and compilable test case which illustrates the problem at hand at post it here.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Tsk tsk, let's not get into unproductive discussion here. I am pretty sure you both understand that there is no point in nitpicking each others' post to the point that it turns into name calling.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> This also assumes that encoding won't be problem.

If this is what he actually wants, encoding shouldn't be a problem as long as an appropriate character set is specified when creating the string. String text = new String(bytes, "UTF-8"); .

> byte[] b = new byte[f.length]; .

Array bites? ;-) byte[] bytes = new byte[f.length()];

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Terms like efficiency make little sense when used in an absolute context. For finding the most efficient way to solve a problem you first need to track down your applications' usage pattern i.e. what kind of file reading does your application need? Is the data read promptly consumed or is stored for future use? Profiling your application is by far the best approach to selecting an efficient solution.

BTW, StringBuilder & StringBuffer are mutable companion classes to the immutable class String ; one being non-thread safe and the other being thread safe respectively.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I felt a bump was in order for this one...

> Unfortunately, the implementation of ArrayList<T> looks
> [something] like this--

Doesn't seem unfortunate to me; as long as the state is persisted and can be recovered from the flattened representation of the object, it doesn't matter which approach is taken to serialize the object. In this case, the implementer chose not to serialize the array which backs the ArrayList but the individual elements for obvious reasons [hint: the size of the array is not always equal to the number of elements in the ArrayList ].

The only thing you need to look out for is that the objects contained in the ArrayList can be serialized [the concrete class implements either Serializable or Externalizable ].

If my memory serves me right, you posted something along the same lines in a thread you created; maybe it's time to go back and edit it. :-)