masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes, the cwd is that of the java program, of course. The linked document (if I remember right) covers this point. If the batch script depends on cwd, then you are going to have to change the batch script or write another batch that does a cd then calls the batch script you actually wanted to call.

The other option is to read the API docs and pay attention to the ProcessBuilder class (and its directory method), as Runtime.getRuntime().exec() should not be done directly anymore. You have finer and fuller control using ProcessBuilder.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Read this completely and thoroughly, and implement its suggestions.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In most languages that might be good advice, but it is a bit unnecessary in Java. In Java using = in an if statement (except in special circumstances and never as the "boolean" operator) will cause a compile error that you must fix before the program will compile, so it is not quite as "important" (or maybe "relevant" is a better word) in Java.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Please, do not attempt to teach "newbies" the ternary operator, and please, also, do not teach them not to use braces ({}) in an if statement (or for/while loops, etc). It is always safer to use braces and both of these things will do nothing but confuse "newbies" at this point.

Just an attempt at constructive criticism.

P.S. The "value" to check (whether year or y) will, of course, depend on how the rest of the code is written. Now, whether or not those used names correspond to the implied names in the assignment description is another matter.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If "year" is the value to check then that, of course, is the value you need to use in the if statement. In any case, the second version is the one to use, as long as you are checking the right value and actually check for 2012, not 2010.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Have you looked at the API docs for Integer yet?

Shouldn't you be saving the result (i.e. the user input) from that input dialog?

Shouldn't you be using that user input in the print statement?

Aren't you suppossed to print only the question at the indicated index (not two questions)?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, the array creation, yes, that works. Displaying a specific index also works (although you should be using user intput for that index).

What's missing. of course, is the user input (and the use of that input in the prints).

I don't understand why you've called the class "apples", though.

Edit: And what is with that extra pair of braces after the last print?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Uhm, in this case, no, simply use that integer to index into the array.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
String[] strings = { "a", "b" };

Then see the API docs for Scanner (as this seems to be the preferred method for most instructors, although it is not my personal choice) and Integer.parseInt(String) (although with Scanner this part is not necessary).

System.out.println(strings[index]);
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Hi
Thank you masijade, it worked. But then in which cases will I have to use mypackage.HelloWorld.java?

You won't. You'll use

java -cp . mypackage.HelloWorld

when you execute.

because as I was reading I heard that I can compile the sourcefiles regardless of been in a certain directory, I heard of something like classpath setting which gave me a bit of confussion.

That "-cp" is the "classpath thing you've heard of and has to do with where the classes are not where the source files are.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

mypackage/HelloWorld.java

performed from

/home/user/workspace

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I'm sticking with this because you do seem to be trying

I agree, he is and I commend both of you. I just think that he could really benefit from "hands-on" help as he seems to be having a really hard time of it on the forum.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Like I said, find someone locally who can sit beside you as you don't seem to be able to digest what we're telling you here. You've been told about split (and other things) more than a few times (for weeks now) and you still can't seem to get it right. Not that I know why you included the braces ({}) in your text file, but hey.

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

Okay?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Seemingly it would have to be an Integer array, not an int array, although it would probably help to know exactly what "namestimesSet" is, I'm assuming a Set<Integer>.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay? And what part of this is giving you problems? Where is your code? We are not going to write it for you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Can not issue data manipulation statements with executeQuery()

Uhm, what do think this might mean?


Look at the API docs for statement/preparedstatement and see if there is another method that is more applicable.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Just let it put the version variable in and don't worry.

Just remember, however, that if the interface of the class changes (i.e. new public/protected methods, etc) to change that number or you will have problems if the class is actually serialised as part of the app.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I have changed that post. Give the new advice a try.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Edit: Nevermind. I misunderstood you a bit. All I can say there is to place those few lines (the asking of the question and the if statements) into a "while(true)" loop and "break" from the loop when a valid answer is encountered.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay? I know that. I am asking you that when the user does not input 1 then what do you need to do to achieve the same effect, and where do you need to do it?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, lets look at this. Your while condition is

while (choice2 == 1)

So, in order for your while loop to "continue", choice2 needs to have what value?

Now, where are you "showing" your error messages? In an if statement block, right? So, what do you think you might add to that block to ensure that condition in your while loop expression is met?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

How do I split?

See the API docs for String (see my hint about looking at the API docs for Double, and now, since you're talking about "splitting" a String it should have been logical to at least look at the API docs for String).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

P.S. why is this called "MatchApplet" (an eventual Applet I would assume) but has a main method? You also know, I assume, that you won't be able to read files on the client from an Applet, right? At least not without signing the Applet and/or security policy changes on the client.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, of course. Why would you assume that parseDouble takes a list of doubles. If you actually look at the API you would see it takes a String representing a single double value, of course. Split the String first, of course, and call parse Double on each element.

I feel obliged to mention that another possibility is to use Scanner. You'll have to get someone else to help you with that though, as I don't use Scanner its performance is not "up to snuff" for what I do.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What problem? I am not going to play compiler and JVM rolled into one to try and figure it out.

Edit: Which means, of course, that I haven't even looked at the code. Give me the complete exception and/or compiler warning/error or explain, in detail, the difference between the expected result and the actual result if there was no error.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Double.parseDouble(str)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Another who thinks they'll learn by not doing anything?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Design, code, test, deploy.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

By arranging them properly (GridBagLayout with proper constraint settings and properly designed components will let you do nearly anything) and letting the layout manager do it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

:sigh: Just see the specs

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If you need a very precise layout, you can do setLayout(null) and then use the setBounds method for coordinate positioning.

No, that will not give a "very precise layout". That will create a very brittle layout that will "break" as soon as the font is changed, or the app is run under a different display size, text size, os, whatever, as most of the components sizes will alter, at least slightly, under those conditions. At the very least it will take alot of work by the programmer to take all the variables into consideration, and resizing will be a real pain. The layout managers manage all of this for you. The "null" layout is not an option, except in very specific instances.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because the package for "B" is "pkg" so it will look for "B" in "pkg", of course.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The default layout option for JPanels (which you use in your class) is FlowLayout with a default flow of left to right, so, as Ezzaral says, use a different layout.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That's why he should be using some sort of "start" protocol in the first place. Either the client or the server blindly expecting a successful socket connection to mean that they have the "right" connection is bad design in the first place.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In that case the "current class version" would be "none", would it not. But how I really should have said it is "the date time stamp of the current compiled classfile associated with that source file".

And it wouldn't be found in the "source directory", it would be found "on the classpath". Now, that might, and might not, be the same place, depending on the setup.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because the compiler you used is setup to search the source directory, as well as the classpath, and compile those items from the src dir if they are newer than the current class versions.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

IOW, Someone else already gave me the code, but I can't defend it to my instructor.

Try writing some code. Try doing your homework and you might actually learn something.

tux4life commented: I agree :) +8
masijade 1,351 Industrious Poster Team Colleague Featured Poster

IOW "give me teh codez". No.

Post your code here along with all compiler messages and/or exceptions as well as a descritpion of what it is suppossed to do and what it actually does and exactly how they differ, and we will help you to correct your own code, but you are going to have to do it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Check out multicast if you really feel the need to advertise. Note that this will probably only be a "local network" feature as most gateways will probably not propagate the signal.

Better, however, would be to simply have a range of, say 5 or so, ports and simply have the clients try one after the other until they get a connection (or not if the server is down or there is a network problem).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Don't use = (or !=) to compare Strings. use "str.equals(str)" (or !str.equals(str)).

Edit: IOW, leave the while condition checking the "null" status (thereby catching the EOS).
And, as the first line of the loop check the String's value with the equals method and break the loop when that value matches a specific "kill" value.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

"key" is an integer, not a String.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because you won't get "null" until the server closes its end of the connection. Which you don't want, I would assume. I would assume you want to continue using the same connection, right? So the server is going to have to send some extra String, or something, to signify that its finished, and the client will have to check for this String and break out of the loop once it gets it (without showing that String to the user, of course. Or, you could simply use the last line of the menu as the "key" to break out of the loop, if it has a fixed, set text.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Try FileLock, but no guarantees, of course.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You are confusing things. An enum is static, it always is. Just like "one" in my example above. That statement that says it is "an instance of enum" means that that static member is an enum, and not a String, or Integer, or whatever. In exactly the same way that "one" above is an instance of Integer. It simply means that "one" is an Integer and not a String, or Enum, etc.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
public static Integer one = new Integer(1);

one is a static member that is an instance of the Integer type. Same same.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because in the second case the compiler knows that b will always have a value, but it does not know that in the first version (the compiler does not compute expression values).

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.