How can I use the URLEncoder?

Since there is no constructor in the class URLEncoder, the javac always show me a error message.

URLEncoder iEncoder = new URLEncoder();
error: No matched constructor.

URLEncoder iEncoder = new URLEncoder;
error: '(' expected.

URLEncoder iEncoder;
iEncoder.encode("ssss ds ");
error: no initialize;

What can I do?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

URLEncoder has a single public static method, so u use it as

String encodedString = URLEncoder.encode(String toEncode);
If you want a detailed explanation pls ask .

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Read the book 'Thinking in Java' by Bruce Eckel
available at among others

The static keyword
Ordinarily, when you create a class you are describing how objects of that class look and how they will behave. You don’t actually get anything until you create an object of that class with new, and at that point data storage is created and methods become available.

But there are two situations in which this approach is not sufficient. One is if you want to have only one piece of storage for a particular piece of data, regardless of how many objects are created, or even if no objects are created. The other is if you need a method that isn’t associated with any particular object of this class. That is, you need a method that you can call even if no objects are created. You can achieve both of these effects with the static keyword. When you say something is static, it means that data or method is not tied to any particular object instance of that class. So even if you’ve never created an object of that class you can call a static method or access a piece of static data. With ordinary, non- static data and methods you must create an object and use that object to access the data or method, since non- static data and methods must know the particular object they are working with. Of course, since static methods don’t need any objects to be created before they are used, they cannot directly access non- static members or methods by simply calling those other members without referring to a named object (since non- static members and methods must be tied to a particular object).

Some object-oriented languages use the terms class data and class methods , meaning that the data and methods exist only for the class as a whole, and not for any particular objects of the class. Sometimes the Java literature uses these terms too.

To make a data member or method static, you simply place the keyword before the definition
from the Java Language specification static Methods
A method that is declared static is called a class method. A class method is always invoked without reference to a particular object. An attempt to reference the current object using the keyword this or the keyword super in the body of a class method results in a compile time error. It is a compile-time error for a static method to be declared abstract.
A method that is not declared static is called an instance method, and sometimes called a non-static method). An instance method is always invoked with respect to an object, which becomes the current object to which the keywords this and super refer during execution of the method body.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Hi amit,

Is it necessary to decode when we are getting encoded variables?.

Bythe way
 How is your two week trip?


Ravi it was smashing we went to Goa and danced the whole night away till 7 am in the morning,had lotsa beers and some good clean fun.
did u get the new year card I sent u?
vincent_cp88Author Commented:
Thank you very much. It solves my problem and teach me a lot.
No man. I did n't get
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.