masijade 1,351 Industrious Poster Team Colleague Featured Poster

Your code is basically correct. Please use the tag [CODE] for your code.
I have made a small modification.

Do not simply do other's homework. At the very least explain the changes. Better, just tell them what to change. They don't learn anything this way.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

DEAR FRIENDS, I M NEW TO JAVA,

PLEASE ANSWER MY QUESTIONS:
1. I am trying to use float and double in java? can u tell me how to use it?
By using the types float and double?

  1. I am trying to calculate simple interest in java ? please fix my code:
public class simple
{
    public static void main (String[] args)
    {
        // this program calculates the simple interest.
        int principal, noy;
        double rate, si;

        principal = 1000;
        noy = 3;
        rate = 2.5;
        si = (principal * noy * rate) /1000;

        System.out.printf (" The principal is %d \n number of years: %d, \nrate is: %lf \n The calculated simple interest is:%lf\n ", principal,noy,rate,si);

    }

}

the code has error i know. %lf doesnt work.

please fix this.

Okay. Fixed.

Seriously now. What compiler message and/or exception are you getting? If none, than what is your app actually producing and what do you expect it to deliver, and how do those two differ?

I, for one, am not going to play compiler, jvm, and consumer to try and figure it out, you tell me. Then, also, I am not simply going to "fix your code". I am going to tell you what you are doing wrong and give you hints as to how you can fix it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

:sigh: No. Closing this zombie now.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

By modifying your classpath.

See the documentation for the IDE you are using and these documents for command line and jarfile use:
http://download.oracle.com/javase/6/docs/technotes/tools/solaris/java.html
http://download.oracle.com/javase/tutorial/essential/environment/paths.html
http://download.oracle.com/javase/tutorial/deployment/jar/downman.html

Edit: And that's as much as I am going to say about it. If you can't figure it out from these items than get a tutor to teach you about classpaths and how to use them as it always leads to frustation on both sides when attempted on a forum.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

It doesn't implement it, it uses what the systems provide, logically. To implement it, it would need to be able to reach must deeper into the OS (and probably the hardware) than Java is meant for, of course.

Edit: Besides, the JDK comes with the src. Look at those classes and follow them through and you will see for yourself where it "disappears" into the system with the "native" calls.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If you need to ask this, then you definately do not need a new networking protocol, but simply want a new protocol on top of either TCP or UDP (like HTTP, SSH, most DB protocols, etc, etc, etc).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

FYI, related to this.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Killing this zombie.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Was a long dead zombie. Closing this thread.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The "search" function would be performed in a Thread of its own, of course, but that does not, necessarily, mean that the "search" function need be a class in and of its own. You will need to create a Class extending SwingWorker (if you use that) that does nothing more than execute your "search" function, however you do not, necessarily, need to rewrite whatever classes/methods you already have that actually make up the "search" function. You probably need to study up a bit on threads in general, but for starters, like I said, see the SwingWorker class and tutorial.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

See SwingWorker. Your problem is that you are performing your "action" on the Event Thread, rendering it incapable of responding to "user events".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Then actually use that socket, and have the "second" one simply send a "message" to it and have the "first" react to that.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Do not cobble together statements like this unless you want to allow SQL injection attacks to succeed or want seemingly "random" SQL syntax errors due to invalid characters. See PreparedStatement.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

JEditorPane is the main component you'll be needing though.

(and the decompile advice is just a bit of sarcasm)

In truth, however, this is one of those cases where the old adage "if you need to ask, you probably shouldn't be doing it" applies though. As, when you have to ask this question, it means that you will be in way over your head in that project.

~s.o.s~ commented: QFT indeed. +18
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Download and decompile JEdit

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, what do you have so far and what, exactly, are you having problems with.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Masijade, have you ever paused for a second to take stock of your contribution to this forum? Have you realized that you have not contributed any new knowledge in the site from your 2,998 posts apart from riding on peoples’ backs. Or is this the usual work of a system administrator of maintenance and customer support ….whining boy!
I give you a challenge, create new knowledge by advising Dani on how I can close my account without the site crumbling, and you will have done yourself some service.

http://www.daniweb.com/forums/thread302711.html
http://www.daniweb.com/forums/thread296585.html
http://www.daniweb.com/forums/thread185271.html
http://www.daniweb.com/forums/thread178219.html
http://www.daniweb.com/forums/thread76039.html
http://www.daniweb.com/forums/post1174487.html#post1174487

Just to provide a few examples. Now, I have no idea why I am even attempting to defend myself to someone like you, but, now, tell me again how I contribute nothing here.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And why do you Masijade misuse your privilege by deleting your content so that the next poster looks stupid. This is very unethical and stupid of you.

Anyone can edit there own post. And the editing (in my case) always takes place before the next reply.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Then I apologise, but I, personally, did not notice that until now.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sounds like someone who didn't get a cut-n-paste answer for his homework.

mnmw commented: Mean and Arrogant +0
masijade 1,351 Industrious Poster Team Colleague Featured Poster

That's already been siad, and if you check out the cross-post, it's already been solved, the OP simply hasn't been considerate enough to mark it as such, and, now, probably never will.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Have the last command be a call to a shell. You do know, however, that this is rendering your security a moot point, right? Not a good idea IMHO.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What do you have against "parsing librarires"? Especially since there is both a DOM and SAX parser included in the JDK and JRE.

In any case it's called regex. or use toCharArray() and really do it yourself.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Aside from your croos-post see the API docs for the File class and see if you can combine the length and delete methods.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

It's like overriding, it is not "the same as" overriding. Overriding makes it impossible to use the overridden method without instantiating anew instance of the class containing it (not a class that extends that class). Static methods can always be used. Which one you use depends on which Class reference you use to access it (and you should always use a Class reference, not an instatiated instance, to acess them). The tutorial does not "overcomplicate" it, the previous "advice", IMHO, over simplified it. The tutorial is only thorough, but also brief.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I just wan to add one point -
If you define a constructor in a class, you must have to define the default constructor(without parameter) also, otherwise you will get an compilation error.

Sorry, but not if you don't want that the "default constructor" be used, or when it is not applicable. Such as when a class revolves around a specific instance variable and that a class that doesn't have it defined is "useless" and a default value makes no sense, than a "default constructor" also makes no sense, so you define a constructor with which that value can be set and do not define a "default constructor". That way, any class extending that class must explicitly call that super constructor, thereby keeping the "extended class" valid.

I.E. here is an example (a bit construed but valid)

package ages;

public class Age {
  private int age;

  public Age(int age) { this.age = age; }

  public int getAge() { return age; }
}

---------------------------------------

package ages;

public class OldAge extends Age {
  private static final int minAge = 65;

  public OldAge() {
    super(minAge);
  }

  public OldAge(int age) throws NotOldEnoughException {
    super(age);
    if (age < minAge) throw new NotOldEnoughException();
  }
}

See, the Age class needs an age, and what should be the default age? There is no sensible value, and an Age without an age value is also nonsensical, so there is no default constructor. Therefore, all constructors of OldAge must explicitly call the super(int) constructor.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I'm sorry, but those are features. They are only advantages when applicable.

#1 is not applicable if the system being designed is only going to run on a single platform (regardless of which).
#2 is only applicable if it is needed. A simple site with a few pages of only minorly interactive content won't
#3 so are many others, and, I can repeat the #2 statement
#4 a complete repeat of the #3 advice.


Once again, I'm sorry, I don't mean to be harsh, but not all features of a language are necessarily an advantage in all situations. In fact, each of those features is a distinct disadvantage when my counter points are applied.

Discover the requirements, then analyse your choices, don't attempt to use a pat list of "features" as "advantages" and blind yourself to the realities. And, when offereing it as advice than qualify the statements.

kvprajapati commented: Great answer. +10
masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Like I said, the foreach splits the input line, so now you do have a list of distances. The body of the foreach (the part between the braces) then uses each of these distances, one at time, as a key in the hash and increments the value at that position. If you know that the first part splits the line into individual distances, and you know what a hash is, and you know what foreach is, then I don't understand what it is you don't understand about that line.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If you'll notice, $_ in the hash is inside the foreach loop, meaning that it refers to that individual value for that iteration of the loop, or a single value resulting from the split of "string of distances" making it refer to a single distance.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Unless you need to use regular expressions, then use "replace" rather than "replaceAll".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

P.S. unless the spot where you're using a StringBuffer is "thread" sensitive, use a StringBuilder rather than a StringBuffer. A StringBuffer is "synchronized" whereas a StringBuilder is not, making a StringBuilder more performant when synchronization is not an issue.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

One thing you should know about "static final" variables (at least "public static final", but probably also for "static final" and "protected static final", although I haven't tried those), and that is that their values get compiled directly into the classes using them. I.E.

compile both of these classes

package test;

public class bogus1 {
  public static final int a = 1;
}

--------------------------

package test;

public class bogus2 {
    public static void main(String[] args) {
        System.out.println(bogus1.a);
    }
}

Then execute bogus2 and it will print "1", obviously.

Now change bogus1.a to 2 and compile only bogus1 (note do not do this in an IDE as that will automatically compile both classes, per default)

Now execute bogus2 and it will still print "1".

Just a small note of warning.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Your available heap space.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And much more complicated than need be. simply split on one or more whitespace or one or more "/" characters (as I did) and ignore the first index.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

"\\s+" not "\s+"

masijade 1,351 Industrious Poster Team Colleague Featured Poster

BufferedReader, readLine(), and split("/+|\s+")

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And still the wrong tool for the job, but I think I'm finished talking to the walls now.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Why are you instantiating a ClassTest1 instance in ClassTest2? Simply call "display1()", not "t.display1()".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because it's not. In that example it is the "MainTest" class, not the "ClassTest2" class that is attempting to access the method. It is simply using an instance of ClassTest2 to try and access it, but it is MainTest that is trying to access it. Add a call to "display1" inside the ClassTest2 class and you'll see that ClassTest2 does have access to it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

thank you for your reply, their server is Windows, but the database is oracle!

Must be a pretty small bank.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Although there are ways to run .net on (eg) Linux

Yes, .Net has a VM much like Java, which, theoretically means that it is also multi-platform. That, at the moment, is a complete and utter pipe-dream, however. There is a VM for Linux, but it is severely restricted (it is, essentially, only a demo/proof-of-concept item) and even in that form comes with license costs.

The problem is, there is a hefty, continuing, license cost to produce a .Net VM, and, the "functionality" that it is suppossed to be able to provide mirrors (unsurprisingly) Windows functionality. Which means, that producing a fully functional .Net VM on any other platform will involve all sorts of "workarounds" that are about guaranteed to come heavy performance costs, and probably still not be completely compatable.

Microsoft is also not producing any "free" .Net VMs for other platforms, so the problem of producing one, combined with the license costs of producing one, combined with the fact that Java already has one nearly everywhere, means that .Net will almost definately remain a Windows specific domain that "claims" to be platform independent.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Depends on the environment. Do they have only Windows servers on which this might run (and I am not talking about the clients, I am talking about the servers). My guess would be no. They probably have a group of mainframes, AIX, Solaris, HP, etc machines, on which .Net won't run.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Here's a start for you

// declare the package

// define the imports

// declare the class

// possibly add some instance and/or class variables

// possibly declare a constructor

    public int mode()
    {
        // add some code for determining the mode
    }

    public double mean()
    {
        // add some code for finding the mean seemingly using the following hint
        //if even add the two median..
    }

    public double median()
    {
        // add some code for finding the median
    }

// end the class definition
masijade 1,351 Industrious Poster Team Colleague Featured Poster

No. Why should I?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

AJAX / JavaScript to send a post request to another page.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Looks like the reader can't find what it is it is suppossed to be reading. The real question, though, is what that has to do with anything. You don't plan on directly incorporating this demo code into your code, do you? If so, we're back to "teh codez".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

This?
The first hit, looks promising (it "says" textfield, but uses textarea).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes, okay, it seems you already have an idea, so work with it. What, exactly, are you asking? (although I would say that "FileDialog" is wrong, "JFileChooser" is better). I would also use two JTextAreas. One to show the original text (possibly with the "searched" word highlighted), and one to show the search results (although a JTextField would be enough for a single word search.