• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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?




0
vincent_cp88
Asked:
vincent_cp88
  • 4
  • 2
1 Solution
 
mbormannCommented:
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 .
0
 
mbormannCommented:
Read the book 'Thinking in Java' by Bruce Eckel
available at among others

http://www.softseek.com/Programming/Tutorials_and_Reference/Review_25131_index.html


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
0
 
mbormannCommented:
from the Java Language specification

8.4.3.2 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.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Ravindra76Commented:
Hi amit,

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

Bythe way
 How is your two week trip?

0
 
mbormannCommented:
sure,

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?
Enjoy...
0
 
vincent_cp88Author Commented:
Thank you very much. It solves my problem and teach me a lot.
0
 
Ravindra76Commented:
No man. I did n't get
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now