masijade 1,351 Industrious Poster Team Colleague Featured Poster

This (!=p) is not a statement/expression. What is "not equal to" p?

sbhavan commented: Good Solution +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster
peter_budo commented: Cookie goes to Sun admin for advertising Sun ;) +22
masijade 1,351 Industrious Poster Team Colleague Featured Poster

According to the API docs, countTokens() returns

the number of tokens remaining in the string using the current delimiter set

So, before you call nextToken on a "tokened String" with 5 elements it returns 5, after calling nextToken once it returns 4, so, what do you think is happening with your for loop?

Add

int size = tok.countTokens();

and use size in both places where you currently use countTokens() .

javaAddict commented: Good call. I didn't bother to examine it that closely +8
masijade 1,351 Industrious Poster Team Colleague Featured Poster

What are you talking about? What from apache commons do you want to use? Are you thinking of using the FTP library from commons, or something else? The question, IMHO, doesn't make a lot of sense.

tux4life commented: Look at his username, I guess you'll have to guess it :P +21
masijade 1,351 Industrious Poster Team Colleague Featured Poster

i am java fresher a have good logic skill still i want to improve any guidence

This post, in this thread, is not, exactly, an endorsement of your claim of having "good logic skill".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Hi masijade,
I'm a little bit confused with longest dup counter and current dup counter.
How do I keep the longest counter and reset the current dup counter when the value changes? Could you please give me an example code.?
Truyly appreciate,
VM

With two different variables, of course. That is why they are referred to with two different names.

valleymorning commented: Great idea! +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Please explain your problem properly. Cant get it what you want.


From what I have understood... to find whether a string that ends with "," or ".",
eg.

String str = "Hello World.";
if(str.charAt(str.length-1)==',' || str.charAt(str.length-1)=='.')
{
    // Your Code
}

Huh? What's wrong with the "endsWith" method of String?

iamthwee commented: Common sense prevails! +22
masijade 1,351 Industrious Poster Team Colleague Featured Poster

No, they don't necessarily need to be in the same place, but it does need to be on the class path.

Say you have /classes on your classpath. And your class is my.package.MyClass. Then your class is located at /classes/my/package/MyClass.class. Assuming there are no other packages, then your file (named myfile) could be located in the following locations

/classes/myfile                          getResource("/myfile")
/classes/my/myfile                       getResource("/my/myfile")
/classes/my/package/myfile               getResource("/my/package/myfile")
                                         getResource("myfile")
/classes/my/package/some/sub/dir/myfile  getResource("/classes/my/package/some/sub/dir/myfile"
                                         getResource("some/sub/dir/myfile")
/classes/some/other/dir/myfile           getResource("/some/other/dir/myfile")
kvprajapati commented: Thanks +7
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay. Finished.

VernonDozier commented: Good program. +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay, finished.

Salem commented: :) +36
masijade 1,351 Industrious Poster Team Colleague Featured Poster

The only way to prevent decompilation is to not distribute your app. Provide it as a web-app and hope no one breaks into the server. Obfuscation makes it harder, and obfuscating and then, also, native compiling can make it even harder than that, but it would still be possible, and those people who will actually abuse that for their own profit and your loss will do it anyway. All of this only scares off the "casual" pirate, not the ones who could actually do some real damage.

kvprajapati commented: Informative +6
masijade 1,351 Industrious Poster Team Colleague Featured Poster
System.out.println("Please Enter 2 values:(number must range from 1 to 9)else display error message");
System.out.println("value 1: 3");
System.out.println("value 2: 8");
System.out.println("Fibonacci numbers are:");
System.out.println("11 19 30 49 79 128 207 335 542");
System.out.println("Even numbers are:");
System.out.println("* * 30 49 * 128 * 335 542");
System.out.println("Odd numbers are:");
System.out.println("11 19 * * 79 * 207 * *");
System.out.println("Try Again?:");
masijade 1,351 Industrious Poster Team Colleague Featured Poster

How about a grammar and spell checker?

kvprajapati commented: eye-opener +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Make a data class with methods for the varying actions that might taken on the PDFObject and give it also an addListener and fireEvent methods. The "Panel" class to display the PDF will be added as a Listener to the data object so that it can actually display everything that changes. Then I would make an abstract class with varying methods for calling the "data" methods and I would make all of my swing listeners extend this class. Those swing listeners then simply need to call the method from the abstract class which will then call the "data" method.

If you wanted to be complete, you would have the normal Swing and listeners running in the main (and of course event thread), the "panel" class in another thread (using invokeLater, or invokeAndWait to display the changes), and the "data" class in a third thread, with a synced queue between the listeners and the "data", and use wait/notify between the "data" and the "panel" classes.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What html file?

If you mean one of the arguments such as

--inputHtml /Harvester_new/build/classes/sample/data/rsearch.html

then make sure you have the argument correct.

Also, if you copied jars somewhere, then you still need to include those jars on the class path (or unjar, which I wouldn't suggest) as including a directory in the classpath will not automatically include all jars within those directories.

multicoder commented: "still need to include those jars on the class path" +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I am sorry. Which collection class has sort method?

Collections

That is a Class in and of itself, much like Arrays.

kvprajapati commented: Great eyes! +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

The error is nullpointerexception, right?

kvprajapati commented: right +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

No we did not create a problem, simply got the code to run far enough for that already existing problem to be noticed. This thread is already too long IMHO, and this current error has nothing to do with the original error, so it is time for a new thread.

You are not "creating" any classpaths in your code, you are simply executing the program with a classpath so that it can find anything at all. It now looks as though you are attempting to compile some code within your code, which, as already said, is a new problem.

You are, however, in really very far over your head attemtping this SOS with the level of knowledge you've shown here for the basic tenants of the language that every programmer should learn as one of their first lessons.

multicoder commented: Sounds very knowledgeble person +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

The ability to use any character regardless of the current system character set.

Be careful though. Unicode is translated as the first step in compilation, so you might wind up with some unforeseen complications.

See http://en.wikibooks.org/wiki/Programming:Java_Comments

puneetkay commented: Thanks for the info! +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I'm sure it has documentation.

Ezzaral commented: What a crazy suggestion! +23
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Also, although the API docs for java.sql.Date state that the time will be rounded, in my experience, it has always only done that when formatting a String representation of the Date, and that the actual Date object still retains the entire Date value. Try the following and see if that is not the case

public class UtilSqlDateTester {
	public static void main(String[] args) {
		java.util.Date d = new java.util.Date();
		System.out.println(d);
		java.sql.Date s = new java.sql.Date(d.getTime());
		System.out.println(s);
		java.util.Date sd = new java.util.Date(s.getTime());
		System.out.println(sd);
	}
}
javaAddict commented: OK +7
masijade 1,351 Industrious Poster Team Colleague Featured Poster

In your inital post, you were to take an intpustream as the argument and count the number of bytes in it. Now you're talking a byte array? Well, if in that case the purpose is to return the number of bytes in the byte array smply return b.length.

Somehow or another, you seem to keep slipping sideways whenever you "correct" something, rather than coming closer to your goal.

Go back to the very start of this thread, and the code that was posted there, then, go through the first few posts changing only those parts of that code that you were told you needed to change and you will have your solution as of post #6.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sorry, but his question started

create a method where it takes a InputStream as a parameter

and not, necessarily, anything to do with a file.

If you want the size of a file, simply use the length() method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Do you know how to declare an int variable?

Do you know how to increment it?

Well, declare one before the while loop, and increment it within the while loop. And, do nothing else inside the while loop.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I thought you wanted to count the bytes, not write them out to something else (and, actually, you're trying to write it out to the inputstream you're currently reading, don't you see something wrong with that?). That should be where you look. Don't you think you should be incrementing a variable there, instead?

masijade 1,351 Industrious Poster Team Colleague Featured Poster
yourFrame.setContentPane(yourPanel);
yourFrame.repaint();

Or, read the API docs for CardLayout.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

http://java.sun.com/javase/6/docs/technotes/guides/security/index.html

Don't be "quick" be "complete", especially with anything that has to do with security.

Salem commented: Wise words indeed. +30
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Maybe you can get one of your fellow grade schoolers to do it for you for that price. If you multiply the price by ten, you may get some semi-competent unethical "working person" (I won't say professional) to do that simple thing for you, but I wouldn't expect quality, even then.

Salem commented: Quite so. +29
masijade 1,351 Industrious Poster Team Colleague Featured Poster
int answer;

System.out.print("Please type a number < 1 for Ali, 2 for Ahmad, 3 for Ah Chong, 4 for Muthu, 5 for Ramasamy >: ");


if(answer == 1)

Where, above, do you give "answer" a value?

The answer, you don't. I assume you want to read user input some time after the println and before the if?

Salem commented: I think they outsmarted themselves with your signature ;) +29
masijade 1,351 Industrious Poster Team Colleague Featured Poster

A slight correction, since set returns the previous element.

// could also be void, make Vecotr so that it can be "chained"
	public Vector sortContacts(Vector v) {
	   for(int i = 0; i < v.size() - 1; i++) {
		   ContactListLabel cll = (ContactListLabel)v.elementAt(i);
		   for(int y = i + 1; y < v.size(); y++){
			   ContactListLabel cll2 = (ContactListLabel)v.elementAt(y);
			   if(cll.getNameLabel().toLowerCase().compareTo(cll2.getNameLabel().toLowerCase())> 0){
				   v.set(i, cll2);
				   cll = v.set(y, cll);
			   }
		   }
	   }
	   return v;
	}

Very minor difference, but you just well use what Vector provides. ;-)

peter_budo commented: Neat solution, I :* +16
masijade 1,351 Industrious Poster Team Colleague Featured Poster

See if you can spot the reason. If you can't just ask. ;-)

import java.awt.*;
import javax.swing.*;

public class GridBagExperiment extends JFrame {
	JPanel redPanel, bluePanel, greenPanel, yellowPanel;
	double col1Weight = 0.4;
	double col2Weight = 0.2;
	double col3Weight = 0.4;
	double row1Weight = 0.4;
	double row2Weight = 0.6;

	GridBagConstraints gbc;
	Container container;

	public static void main (String args[]) {
		GridBagExperiment gbe = new GridBagExperiment();
	}

	public GridBagExperiment() {
		setSize (400, 400);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		container = getContentPane();

		redPanel = new JPanel ();
		bluePanel = new JPanel ();
		greenPanel = new JPanel ();
		yellowPanel = new JPanel ();
		redPanel.setBackground(Color.RED);
		bluePanel.setBackground(Color.BLUE);
		greenPanel.setBackground(Color.GREEN);
		yellowPanel.setBackground(Color.YELLOW);

		GridBagLayout gbl = new GridBagLayout();
		container.setLayout(gbl);
		gbc = new GridBagConstraints ();

		AddPanel (redPanel, 0, 0, 1, 1, 0.0, 0.0);
		AddPanel (bluePanel, 1, 0, 2, 1, 0.0, 0.0);
		AddPanel (greenPanel, 0, 1, 2, 1, 0.0, 0.0);
		AddPanel (yellowPanel, 2, 1, 1, 1, 0.0, 0.0);

		gbl.columnWeights = new double[] { col1Weight, col2Weight, col3Weight };
		gbl.rowWeights = new double[] { row1Weight, row2Weight };
		setVisible (true);
	}

	public void AddPanel (JPanel panel, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty) {
		gbc.gridx = gridx;
		gbc.gridy = gridy;
		gbc.gridwidth = gridwidth;
		gbc.gridheight = gridheight;
		gbc.weightx = weightx;
		gbc.weighty = weighty;
		gbc.fill = GridBagConstraints.BOTH;
		add(panel, gbc);
	}
}
VernonDozier commented: Thank you. +12
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, seeing as how we have no idea what you did, we have no idea what's wrong with it.

Salem commented: Tsk Tsk, you mean you lost your magic crystal ball which allows you to remote view other peoples code ;p +29
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Partly, both StringTokenizer and Scanner (in this case, especially, when reading a file) are not the fastest tools around. StringTokenizer, for one, is all, but, deprecated and shouldn't really be used, but there are more problems with that than just speed. And Scanner is great for verifying data types before reading and for automatically converting the string to the datatype you need as you read it, but with that comes a fairly large performance hit.

The other part though, was the fact that both the Scanner and the FileInputStream (with the only 1024 buffer size) were making far too many disk reads. A Buffered(Reader/InputStream) will fill it's buffer with as few disk calls as possible (usually one if there were no problems, and it has, usually, an, at least, 8k buffer), then your read calls are made against this buffer (automatically removing line endings when using readLine).

Ezzaral commented: Nice work. +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster

4, 3, 3, 3 and 3

Ezzaral commented: Excellent work! +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Don't do it that way. That is Database specific. Read the API docs for DatabaseMetaData.

Ezzaral commented: Good point. +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster

What are you using to compile?

If you are using an IDE, then you need to add that jar as a library in the project properties.

Edit: As that is the CLASSPATH for an IDE. The System CLASSPATH is good for almost nothing, anymore. Do the following concerning classpaths

1. When running from the command line without the "-jar" option use the -classpath option.
2. When running from the command line with the "-jar" option, you must configure the classpath in the manifest file properly.
3. When running/compiling from an IDE, you must configure the librarires in that IDE's project properties.
4. When running from a web container / application server you must place the jars in the proper locaions (see the manula for the web server / application container in question).

IDE's and web containers / application servers ignore the system classpath. When using the -jar option, both the System CLASSPATH and the -classpath options are ignored and only the manifest file's classpath is used. The only time that the system CLASSPATH is still used, is when running or compiling from the command line with neither the -jar nor the -classpath options.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Like I said, though, "-1" says that s1 (which is the lesser number the first time, but the greater number the second time) is less than s2, whereby s1 is significantly greater than s2 the second time, not less than s2 as "-1" indicates.

What I am saying, is that you cannot String compare the entire String at once. That comparison is done alphabetically, not numerically. For single characters, alphabetically and numerically are the same, but not for multicharacter Strings. (E.G. alphabetically 10 is less than 2).

verruckt24 commented: Both your posts previous and this one underline a point which o/w can be missed. Good. +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

An int is 4 bytes which is 32 bits (31 of which is value and the 32nd is a pos/neg toggle). A long is 8 bytes (63 bits data and 1 pos/neg toggle) so use long and parse that String to a long using Long.parseLong(string). If a long is also not large enough use the BigDecimal class. See the API docs.

Killer_Typo commented: Very well written comment. +7
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Just for Fun, I decided to actually set it up last night, and sat down for about an hour, and here it is

package test;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

public class JarStarter extends Thread {

	private File f;
	private JarFile jf;

	public JarStarter(File f) throws IOException {
		this.f = f;
		try {
			jf = new JarFile(f);
		} catch (IOException ioe) {
			System.err.println("Error loading JarFile.");
			jf = null;
			throw ioe;
		}
	}

	public void run() {
		if (jf == null) return;  // Should never be possible, but ....
		try {
			String mainClass = getMainClass();
			if ((mainClass == null) || (mainClass.trim().length() == 0)) return;
			ClassLoader cl = createClassLoader(getClassPath());
			if (cl == null) return;
			setContextClassLoader(cl);
			Class<?> c = cl.loadClass(mainClass);
			c.getMethod("main", String[].class).invoke(null, (Object) new String[0]);
		} catch (InvocationTargetException ite) {
			ite.printStackTrace();
		} catch (IllegalAccessException iae) {
			iae.printStackTrace();
		} catch (NoSuchMethodException nsme) {
			nsme.printStackTrace();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} finally {
			try { jf.close(); } catch (IOException ioe) {}
		}
	}

	private String getMainClass() throws IOException {
		Manifest man = jf.getManifest();
		return man.getMainAttributes().getValue("Main-Class");
	}

	private String[] getClassPath() throws IOException {
		Manifest man = jf.getManifest();
		String classpath = man.getMainAttributes().getValue("Class-Path");
		if (classpath == null) return new String[0];
		return classpath.split("\\s+");
	}

	private ClassLoader createClassLoader(String[] items) {
		String dir = f.getParentFile().getAbsolutePath();

		List<URL> urls = new ArrayList<URL>();
		try {
			urls.add(f.toURL());
			for (String item : items) {
				urls.add(new File(dir + item).toURL());
			}
		} catch (MalformedURLException murle) …
masijade 1,351 Industrious Poster Team Colleague Featured Poster

The classloader is simply so that the executed jar (when you simply call main from the mainclass) has it's own classloader rather than having the classes that it loads, loaded into the rest of the application. Essentially, it is to give it it's own "sandbox", so that you can execute "internally", but still have it "separate" from the application that started it. You can also call main without creating a new classloader (as long as the jarfile is already on the classpath), but then any class loaded from the jar is "visible" to the entire application, which might not be want you want.

Ezzaral commented: Good info. +18
masijade 1,351 Industrious Poster Team Colleague Featured Poster

1. Periodically. When, exactly, is irrelevant and varies from platform to platform. It is an implementation detail of the VM that the programmer doesn't really need to concern himself with. Also, System.gc(), and Runtime.getRuntime().gc() are only "suggestions" to the the VM that now would be a good time to do GC. The VM does not have to follow it though. It may do it then, it may do it after a delay, or it may ignore it altogether.

2. No. That's "humbug" to quote Ebeneezer Scrooge. There are some cases where it may be helpful, but they are real corner cases (i.e. very, very, very little instances) and, as long as the programmer is doing his job right, should never be a worry.

verruckt24 commented: thats a very good point that every one should be adviced on the use of System.gc() +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster

well, first of all thanks for all the inputs. it is the code given by my professor and for us to modify and add things he wants us to add. so please do not assume too early people here are just lazy bums. i would say lazy student wouldn't even bother posting questions.

Well, I would say a non-lazy student would post the questions and his answers to them and ask for corrections and/or confirmation. Simply posting a homework assignment is lazy. It shows that the only effort you are willing to give to your assignment is to ask for somebody to do it for you, i.e. no real effort at all.

stephen84s commented: eggjactly +6
masijade 1,351 Industrious Poster Team Colleague Featured Poster

BURN THE HERETIC.
KILL THE MUTANT.
PURGE THE UNCLEAN.

FOR THE EMPEROR!!!!

Rape the horses and Pillage the women!
<Pause>
Ah, I mean .....

javaAddict commented: Dawn of War II is coming Feb 28 +5
masijade 1,351 Industrious Poster Team Colleague Featured Poster

And I told you that sort of thing would be a lot more work. Good luck with that, we are not going to write it for you.

For arrays:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html

For Collections (which would be better):
http://java.sun.com/docs/books/tutorial/collections/index.html

caps_lock commented: thanks for the links +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

*Ahem*

I have some cold medicine I could give you. ;-)

javaAddict commented: very funny +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Who is stopping you from submitting it?

His dog!

verruckt24 commented: good one +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I assume that these classes are all of the same type (or at least all extend the same type)? In that case simply pass the object itself along with the method call;

Instead of

public class aclass
{
    public static Color CopyAttributes (Color newcolor, int red, int green, int blue, int alpha)
    {
          red = newcolor.getRed ();
          green = newcolor.getGreen ();
          blue = newcolor.getBlue ();
          alpha = newcolor.getAlpha ();
          return new Color (red, green, blue, alpha);     
   }
}

do

public class aclass
{
    public static Color CopyAttributes (someclass bclass)
    {
          bclass.setRed(newcolor.getRed ());
          bclass.setGreen(newcolor.getGreen ());
          bclass.setBlue(newcolor.getBlue ());
          bclass.setAlpha(newcolor.getAlpha ());
          return new Color (red, green, blue, alpha);     
   }
}

Or define an interface with those setmethods and have the classes implement that interface, and then make the interface type the argument.

VernonDozier commented: Helpful approach. I hadn't though of passing a class or interface. +10
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Integer math will return an integer and integers do not have decimal places. You need to cast one of those numbers to a double while doing the division.

PercentTotal = Votes[i] / (double) Totalv * 100;

But, to tell you the truth I would probably simply make "Totalv" a double to begin with.

...
double Totalv = 0.0;
...
Totalv += Votes[i];
...
PercentTotal = Votes[i] / Totalv * 100;
...
Ezzaral commented: Gotta love the int math bugs :) +15
masijade 1,351 Industrious Poster Team Colleague Featured Poster

they haven't provide any code or documentation for that ...

i searched but i didnt find any thing suitable..i need to write that code in myapplication.. i haven't find any smaple code which will help a bit..

You mean you didn't find anything you could block copy and paste.

The documentation describes how you interact with it (usually through http). So now the question is not "how do I send/receive sms", but rather "how do I perform an http connection/interaction". The answer to that is Http(s)URLConnection and another bit of Googling.

Gods, not everything you get will give you 1-to-1 examples of what you need to do in language "X". They will simply tell you what you need to do (I.E. use http protocol in "this manner"). Then it is up to you to implement that in language "X". So then you can start to research how to implement that.

Learn how to do a bit of thinking and research on your own or you will never be anything but a "code monkey" and not a very good one at that.

Ezzaral commented: Absolutely. +15
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Assign that class instance to an instance variable, rather than a local variable, if you want to use that same instance throughout the class.

I.E.

public class A {
    private B bObject;

    A() {
      bObject = new B();
    }

    void whateverOne() {
        bObject.whatever();
    }

    void whateverTwo() {
        bObject.whatever();
    }
}

rather than

public class A {
    A() {
    }

    void whateverOne() {
        B bObject = new B();
        bObject.whatever();
    }

    void whateverTwo() {
        B bObject = new B();
        bObject.whatever();
    }
}
jbennet commented: fast reply +33