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

Though I'm not exactly the 'powers that be' let me hazard a reply.

One of the reasons pics in snippets are not allowed since they are not present in any of the online code snippet repositories out there. Take a look at DZone snippets.

Another reason that I can think of is that since the snippet feature is a hacked version of the original vBulletin implementation, the features which you can come up with are pretty much limited.

But then again, it's AFAIK, IMO etc. etc. :-)

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

AFAIK, it's not exactly *free*.

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

> closer to around 40,000

40,000 is nothing, unless you have some specifications which you would need to meet and you have *confirmed* that doing things your way is much faster than the other simpler approaches.

IMO just go with the normal way of doing things i.e. writing data as comma separated values. If you are feeling adventurous, rather screw around with an embeddable database than get involved with all the bit-fiddling. Optimize when needed and that too after profiling; premature optimization is the root of all evil.

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

The 2009 Summer Anime Preview is here!

Sadly, not many of these look promising to me except:
- Umi Monogatari ~Anata ga Itekureta Koto~
- Tokyo Magnitude 8.0
- Spice and Wolf II
- Princess Lover!

From the ones mentioned, I've seen the first episode of Princess Lover and it indeed seems entertaining. I would have loved to watch Zan Sayonara Zetsubou Sensei given the hype surrounding it but given that I have yet to see the first two seasons, it's on hold as of now.

Oh BTW, Anime FTW! :-)

ahihihi... commented: :D +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> 0-5 : 4 bits
I wonder how you came up with 4. ;-)

@llemes4011
Coming up with your own serialization mechanism is hard; continue if you are doing this for fun but do remember that there are many other good binary serialization formats out there which can lessen your work and reduce the agony. A comparison of various serialization libraries can be found here.

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

If you can afford eager loading, a better way would be to declare your singleton instance as:

public class MySingleton {

  private static final MySingleton instance = 
    new MySingleton();

  private MySingleton() {
    // initialization code goes here
  }

  public static MySingleton getInstance() {
    return instance;
  }

  public void doSomething() {
    // do something useful
  }

}

This approach does away with all the crazy synchronization stuff and is guaranteed to work since we can be rest assured that by the time `getInstance' is called, the static field `instance' would have been initialized to a new instance of `MySingleton'.

As of Java 5, the best way to implement the Singleton Pattern is to use an `enum' [as mentioned in Effective Java 2nd Edition].

public enum MySingleton {

  SINGLETON;
  
  private MySingleton() {
    // initialization code goes here
  }

  public void doSomething() {
    // do something useful
  }

}

This provides all the serialization and synchronization for free [serialization gotchas exist when using Singletons].

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

> The 910 was probably a typo

Hint: No, it wasn't. :-)

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

You need the mail.jar in your classpath; you need to download the JavaMail jars if you already don't have them.

You would also be needing the Java Activation Framework libraries [activation.jar] if you are not using Java 6.

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

Also, no need to do calendar.setTime(time) ; the new instance of the calendar has the current time.

BTW, if you find yourself fiddling around a lot with time related methods in your application, take a look at JodaTime.

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

@narendrachandu
Please read the forum announcements regarding asking code without any effort whatsoever. And continue with your other thread in case you decide to mend your ways. Closed.

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

I do get to see a couple of new faces in the Daniweb IRC channel these days, so I guess the efforts are kinda paying off. :-)

> I got kicked.. Plus the bot is crappy(because I say so).

Swearing / use of cuss words is not allowed in the channel in case you didn't know. ;-)

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

Yes, Java 7 indeed seems to bring a lot of interesting things to the table. More confusion FTW!

> What I meant by "real" file system was simply that [...]

My explanation was actually aimed at the OP since I thought he was getting confused between the `File' class and the file-system file. :-)

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

> but it seems to work with a "real" file system on a "client side".

I'm not really sure what you mean by a `real' file system; the File class provides an `abstract filesystem independent view' of the path names i.e. your File object does *not* map to a real file on your file system. It's more of an abstraction provided to deal with `file' resources represented using path names.

BTW, I'm personally in favor of having a separate application specific class to represent a File or Directory structure. At first it might end up being just a thin wrapper for the File class but as and when features are added, it would serve as a good abstraction for containing all `File' or `Directory' specific state and behavior of your application.

stephen84s commented: For every post you write I find it difficult not to give a good rep +9
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> 90% of it is deleting spam.

...with the remaining 910% being dealing with issues unknown to mere mortals. ;-)

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

> Are you going to edit my post or not?

As per the site rules, no. Locked.

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

> When I run my servlet in my web browser, everything runs fine ...
> until i press one of the option buttons, Deposit, Withdraw or
> Balance, then i get the following error:

This is because HTML doesn't know anything about your servlet project. Is the name of your project "servlet"? If no, then you need to specify the name of your Servlet project since you are specifying the absolute URL in the `action' attribute of your FORM.

BTW, the reason for the error is pretty simple; there is no resource mapped to the URL "/servlet/HTMLBank". How do you originally access the servlet which is working? How is your web.xml configured?

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

Let's suppose that your program creates regex patterns based on the input provided by the user. Assuming the user enters `*' as the pattern and `hello' as the input string, the regular expression string would look like:

patrnStr = ".*" + ptrn + ".*";
patrnStr = ".**.*";

...which isn't a valid regular expression since it has a dangling meta-character, which is the *.

BTW, you can drop the ".*" present at the beginning and the end of your pattern string; they aren't required for detecting a match.

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

> Is the best way to do this using a Trie?
Judging by its description, it does seem to be a good way of doing things, better than regular expressions at least when used over a large data set.

A simple program to get the ball rolling:

package net.sos.playground;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexTest {

   public static void main(final String[] args) {
      new RegexTest().run();
   }
   
   public void run() {
      Scanner in = new Scanner(System.in);
      String input = null, pattern = null;
      while(true) {
         System.out.print("Enter the pattern: ");
         if(in.hasNext()) {
            pattern = in.next();
         }
         System.out.print("Enter the input: ");
         if(in.hasNext()) {
            input = in.next();
         }
         if(testExistence(input, pattern)) {
            System.out.println("Match found\n");
         } else {
            System.out.println("No Match found\n");
         }
      }
   }

   private boolean testExistence(String input, String pattern) {
      pattern = Pattern.quote(pattern);
      Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
      Matcher matcher = p.matcher(input);
      return matcher.find();
   }

}

Pay special attention to the testExistence method. The method Pattern.quote is required to escape all the regex special characters and treat them as literals. If, for example, the user enters a `*', which happens to be a special character signifying `zero or more occurrences', your Regular object creation will fail. The Pattern.CASE_INSENSITIVE flag is required since the default regular expression matching done by the String.match method is case sensitive.

Once the Pattern object for the given pattern and the Matcher object for the given user input is created, all that remains is to test for the presence of the given pattern in …

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

Use of StringTokennizer and Vector isn't recommended; use String.split and ArrayList as their alternatives.

What do you mean by "extract file into columns"? You can represent the entire file in-memory as a list of lists or a list of objects of your custom class where each object would represent one line of the text file. Retrieving the `n'th column would be just a matter of accessing the `n'th item of the list.

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

Marking this thread as solved since you already started a new thread which is a continuation of this one.

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

Duplicate thread; closed. Refer the above post for the original version.

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

A simple way would be to remove all opening brackets "(" in your String and then split on ")," to get the desired result.

Another way would be to use the Pattern and Matcher object to do the same job.

Pattern p = Pattern.compile("\\(([^)]+)\\)");
Matcher m = p.matcher(s);
while(m.find()) {
    // Group 0 would be the entire string matched ('A', 'B')
    // and hence we are using group(1) which would give us
    // 'A', 'B' as desired
    System.out.println(m.group(1));
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Converting a String like "12" to an integer shouldn't be a problem; just make sure you trim() your strings before parsing them.

By the looks of your stacktrace, it seems that your program is trying to parse an integer out of the string ""0
8 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08" which would fail for obvious reasons.

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

> ok so i want to read a .txt file line by line.

Since you are reading textual data, consider using a BufferedReader wrapper up in LineNumberReader to ease your task.

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

> My conclusion was perhaps a hashtable

Doesn't seem logical since there are no "key => value" semantics here, just data which could be stuffed in a hash map. The solution here would be to let the DAO layer handle the querying of data, the controller handle the merging of data and what your UI/presentation layer gets is a nicely formatted list of Fruit objects. The Hash map approach breaks in case the data comes from more than 2 files [e.g. more attributes are added to the fruit object].

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

> The Java API can easily put you in that situation, for example if you
> are using the Scanner class to parse user input then nextInt()
> throws InputMismatchException if the user has mis-typed

The onus lies on the code which uses exceptions to do business processing rather than the API which throws the exception. Would the below code be wrong given that ArrayIndexOutOfBounds exception is thrown by the API:

int counter = 0;
int[] arr = new int[10];
while(true) {
  try {
    arr[counter] = counter++;
  } catch(ArrayIndexOutOfBoundsException e) {
    break;
  }
}

In the above case, the logic which relies on the exception thrown can be easily replaced by a single bounds check. Compare this to a online banking application which throws the InsufficientFundsException when a user tries to withdraw from an account having no balance. An exception throw here and caught at the UI layer seems logical since it is so much better and elegant than propagating error codes along the call hierarchy.

The case presented by you is fair enough given that it allows the API user to do processing like recording the number of times the user has failed to provide a proper answer, repeat the question or quit the application in case the user has exceeded his maximum tries. The only thing I don't agree with is considering 'accepting user input' as part of business logic; it isn't, it's a part of presentation logic.

BTW, creation of an …

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

They are called 'symbols' in Ruby.

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

Guess I'm late for the party but a simpler way of doing it would be:

require 'fileutils'
FileUtils.copy_file(ARGV[0], ARGV[1])
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Write the primitive data [long data in your case] using DataOutputStream and read the same if required using DataInputStream.

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

BTW, consider using prepared statements / parameterized queries instead of creating queries on fly using string concatenation to avoid SQL Injection.

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

Look into the batch execution capabilities of JDBC.

javaAddict commented: Thanks, I didn't know that +7
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> want to learn JNI , please suggest me some basic guide.

If you are doing it for fun, refer to the links posted above. But if you actually plan on writing a *real* application which requires interfacing with native code with the least possible fuss, try out some of the high level JNI wrappers and their likes out there.

JNA and Swig are few of them.

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

> Why do some of the "similar threads" listings under this post box
> point to threads from 5 years ago?

Because it says "similar threads" and not "recent similar threads"...

> Did you not read my post? I have no permission to install
> anything.

AFAIK, if you already have FF installed, you don't need any special permission to install the plugins/themes/addons. Just make sure the proxy settings are in place[if any] and you should be good to go.

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

Does the server migration problem still exist since I can't seem to access Daniweb from my home most of the times? The request just times out. All other sites just work fine.

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

> I am asking that you delete all of my postings

You posted here when you were in a pinch, got others to help you out and now you want the time and effort put in by others to be "deleted" just like that? Sorry, it doesn't work that way.

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

Posting complete solutions never has and never will help. How about giving the OP a chance to try out a few things before handing out a solution?

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

Let me again point you to my first post in this thread which clearly mentioned:

BTW, the `java' command expects a "package qualified" class name and not just a class name. So if you are using a package, make sure you use the fully qualified class name when invoking `java'. If not, then executing the `java' command from the same directory in which the class file lies shouldn't be a problem as such.

Does that ring a bell? Think what could have gone wrong, give it a second try and reproduce the entire session again in case you still face problems.

BTW, it's advisable to have the project placed in your personal folder; something like D:\personal\projects to avoid dealing with excessively long paths which IMO is messy.

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

Post the code of the class "as it is" without *any* modification, including the package declaration. Also paste the *exact* error message along with a screenshot of the entire session.

This shouldn't be happening if you are well aware of the points I mentioned in my previous post.

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

> So you would have to execute the command in this way :
> javac HelloWorldApp the class loader would look for a file with that
> name and a .class extension

A typo maybe? It should be java HelloWorldApp

> Exception in thread "main" java.lang.noclassdef

This question has been asked a lot of times on almost all java related message boards. Have you tired a web search with the given error message? Have you tried the solutions suggested in the existing threads?

BTW, the `java' command expects a "package qualified" class name and not just a class name. So if you are using a package, make sure you use the fully qualified class name when invoking `java'. If not, then executing the `java' command from the same directory in which the class file lies shouldn't be a problem as such.

Also, is the NoClassDefFoundError error thrown for the main class or some other class which the main class is using? In this case, you might have unresolved runtime dependencies which you will have to resolve by setting the appropriate classpath entries.

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

> Or is this affection that I'm hungary?

Don't turn this into a country thingy; reputation is a subjective concept so it can't be helped if someone thinks that your post was eligible for a bad one. But if you feel that someone is abusing the reputation system by repeatedly giving out bad reps for no real reason, feel free to report this to a mod/admin.

BTW, bumping threads is bad enough since it sends back the recent threads which are in need of help. Also, wasn't the reply you posted from some man page or online resource? Plus if you would read carefully, the OP was not having a problem with the command itself but more of a network issue.

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

> I really can't suss this one out, any help would be greatly
> appreciated.

A small example/project which demonstrates the problem at hand might help others in hacking on the issue. Without knowing the way you have organized your project, it would be difficult to come up with a solution.

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

Is this a web application or a desktop application?

If it's a standalone desktop application, then consider using a serverless & embeddable database which is most suitable for replacing such ad-hoc file/folder storage. An embeddable database like SQLite uses a single file for storage which is *really* minimalistic.

If it's a small scale web application, consider using a small footprint pure Java database like Derby since it would help you get started in a small amount of time without any server setup headache. Of course, MySQL, PostgreSQL etc. also are good production ready alternatives.

> Since an application using your tool might be logging hundreds of
> entries in a matter of a few seconds and needless to say you are
> certainly not going to achieve that kind of speed with logging into
> a database system

That statement can be thought of as "premature optimization" in the absence of proper profiling. Sure, it might be so that the performance of raw writes is better than using a database but is that kind of performance really required? Embeddable databases can be thought of as flat files which come pre-packaged with tools for processing the file data.

What happens if there arises a need for pulling out entries between a given date range? Implementing a custom logic which iterates through all the log entries might prove out to be really troublesome esp with the sheer amount of data a logging tool might …

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

The talk of vajinas[sic], strip clubs, mod infractions and tetris in a thread meant to *bring* Rashakil back does a bit of injustice to the "keep it on topic" and "daytime television" rules.

Locked to preserve the sanity of the remaining Daniweb members. KTHXBI.

Salem commented: <burns>Excellent</burns> +31
John A commented: Wut? There's sanity left? +21
Sulley's Boo commented: مشكور و ما تقصر +6
BestJewSinceJC commented: Rashakil for the loss. S.o.S for the win. +5
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Can we see how many guy(s) look at our profile?

AFAIK, you can't. This feature is much more common with social networking sites than programming forums. Join one in case you are more interested in stalking those who stalk you. ;-)

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

I'm pretty sure there isn't much of value which could to added to this thread. Locking it to prevent more shaman interference seems like a sane decision.

For those who have come to this thread via a search engine and are starting out with C, I'd recommend reading the Starting C thread for a list of compilers/IDE.

Salem commented: thanks! +30
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

[a new post since I can't seem to edit the original one]

> Users learn from both snippets and tutorials.

Here you're speaking from the end users' perspective and not from the site owners' POV.

> I guess this is the sort of thing im talking about. [link]

How is spam handled on that site? What if I just do a copy-paste of someone elses' work and paste there? Are tutorials reviewed before they are made available to public? Is any sort of review done, ever, on that site? How long does it take for the tutorial to be reviewed and accepted? How credible is the reviewing committee?

Nick Evan commented: editing is the newest problem... I was afraid I was the only one and had doubts about my mental health :) +17
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Users learn from both snippets and tutorials.

Here you're speaking from the end users' perspective and not from the site owners' POV.

> I guess this is the sort of thing im talking about. [link]

How is spam handled on that site? What if I just do a copy-paste of someone elses' work and paste there? Are tutorials reviewed before they are made available to public? Is any sort of review done, ever, on that site? How long does it take for the tutorial to be reviewed and accepted? How credible is the reviewing committee?

> You may think it could bring down the name of Daniweb, I think it
> could promote it.

Then it should have happened on a large scale already since the user submitted tutorial feature was brought down a few months ago. Plus there are a lot of other implications the site owner needs to take care of like content stealing etc.

Though what you suggest sounds good enough it can't be done "just like that". Maybe trying it again for a limited time period might just give us idea whether the suggestion really works or not.

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

> i'm just wondering, "where's the love?"

It's a bit complicated; you probably won't understand even if I told you so let's just leave it at that, KTHXBI. :-)

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

> but I don't think that means it should just be totally closed off

The code snippet section of Daniweb is very much similar to other online code snippet repositories like Dzone snippets wherein members can submit snippets with a brief description. Such repositories can have snippets ranging from extremely helpful to obviously useless ones. As long as it isn't spam, the code snippet section can contain any sort of code snippet out there; hence the ability to create language categories or tags on fly when submitting them. There is a difference between a public "code snippet or repository" and a tutorial; you're comparing apples to oranges here. :-)

> I somehow doubt there would be people with 50+ solved
> threads, a high post count and a good reputation who would
> submit a tutorial which would be less than helpful to newbies.

Those who do wrong aren't necessarily aware of it. So even if there would be no spam if such a rule is enforced, the fear of sub-standard tutorials turning up would be still there. You've got to realize that any technical content posted in the name of a tutorial or book if not reviewed is FAIL. Though I agree that if Daniweb can afford substandard tutorials which improve over time with user feedback, this clause would be a good starting point.

> Submitted tutorials can then be published when they are reviewed.

Re-read my previous post, esp …

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

> How about restricting the tutorial section for members with a
> certain amount of (useful) posts and reputation

Two points:

  • useful is subjective term.
  • (Reputation + Post count) =/= (measure of ones' technical expertise)

Reviewing technical content is time consuming and can't be done by *anyone*. Heck, some people get paid to review third party technical content. The expertise and time required for reviewing a tutorial [lets say around 3-4 pages] doesn't come cheap.

It's better to have no or very few tutorials rather than a lot of substandard tutorials which eventually might bring down the name of Daniweb.