Search Help

Query Types

This section shows by example, the query types supported by our Java Examples database (what to enter in the search field -- note that queries are case sensitive).
  • Class-name - Find all examples for class "Thread". Returns a list of every method on Thread that we have examples of; in addition it will show an entry labeled "new" if we have examples that instantiate the class and an entry for any extends/implements examples. Each entry in the list is a link, and clicking it will run a query for that Class.method, or instantiation, etc.:
  • Invoke Class.method - Find example code that invokes the Class.method "URL.openConnection" (note: case sensitive):
  • Invoke package.Class.method - Same as above, but specify full package name (do this if, for example, a class named 'URL' is found in multiple packages -- a message in the query results will tell you when this occurs):
  • Implements Classname - Find classes that implement interface "Runnable". The search results will show classes which implement the interface. Note that for this type of query the search results cannot always pinpoint the class statement where the implements clause occurs; when we can't pinpoint it, we will point to the first executable code or constructor that follows the implements clause:
  • Extends Classname - Find classes that extend (subclass) a class (note: direct inheritance -- not transitive). Note that for this type of query the search results cannot always pinpoint the class statement where the extends clause occurs; when we can't pinpoint it, we will point to the first executable code or constructor that follows the extends clause. Example, find classes that extend class "DateFormat":

Complexity

Our database also contains a measure of the complexity of the method in which each example lives. You can use this to further qualify your Class.method query by specifying an optional "complexity:n" clause with an n value of 1, 2 or 3, where 1 is low complexity and 3 is high. If you specify 2, for example, then only Java examples that occur in methods of medium complexity will be returned. For example, to find examples of Date.getTime in medium complexity methods, enter the query:
Note that this "complexity:n" clause cannot be used in Class-name queries, and is not used for implements and extends queries, since these usually do not occur within methods. Also, if your query does not specify a complexity clause then all complexities are returned.

Troubleshooting

If you have a problem with a query or its results:
  • Nothing found for my Class or Class.method. Verify the correct, case sensitive spelling of the Class and method name. If it is correct, and if you have specified a "complexity" clause, then drop that clause and run it again. If still nothing is found, then there is no usage of that Class or Class.method in our database. Alternate sources for examples: check the documentation for that API, or do a web search for that Class or Class.method name.
  • The Class I entered exists in multiple packages. JExamples detects if the Class name you entered exists in multiple packages. When that happens, it recognizes that those are very different Classes which just happen to have the same name, and it asks you to click the one you intended (also shows you how many examples there are for each). Click the one you intended to re-run the search for just that package.Class (i.e. just click the link, rather than pressing the Search button again); clicking the link is equivalent to copying that package name and then prepending it to your Class name in the Search Field and pressing Search (see example above).
  • Multiple examples of the Class.method I specified appear in the source file. A given source file may contain multiple invocations of the Class.method you specified in the search field. At the time you click a particular source file in the previews, we query the database to check for all invocations of that Class.method within the source file, and we highlight all of them (emphasize the line number) as well as show links to all of them in a table at the top of the page.
  • Can't find package for my class or interface. You enter a valid class or interface name (possibly even a fully qualified one), and get the error message "Unable to find package for class 'someClassName'." This means that our database does not contain example invocations of this class or interface name, and because of this, no query will be run. So it doesn't necessarily mean that the class or interface name you entered is invalid -- but just that none of the Open Source code in our database invokes it.
  • When I copy and paste source code, I also get the line numbers. Press the "Remove Line Numbers" button before copying the code. The View Source page has two buttons at the top: "Remove Line Numbers" (mapped to accesskey Alt-r) and "Restore Line Numbers" (mapped to accesskey Alt-s). Before you copy source code press Remove Line Numbers; that will keep line numbers from showing up in the code you copy and paste. After that you can press Restore Line Numbers if you want them displayed again. Note that there is also a table at the top of the page that shows a list of links to all examples of the type you searched for, within the source file; after scrolling up to press "Remove Line Numbers", or clicking Alt-r, you can click the line number in this list to return to your example. Please be aware of the license terms of any product whose code you want to copy.
  • Dragging the mouse over code to select it doesn't work correctly. We have seen this problem in the Internet Explorer browser. Unfortunately, we don't know of a fix except to use another browser, for example Firefox.
  • Unable to Rate examples. If nothing happens when you click a Rate link in a source file, then your browser probably has popups disabled. Rating is implemented with a popup browser page that appears when you click a Rate link in a source file. In some browsers, disabling popups will prevent this Rate page from appearing. Note that you also need to have cookies enabled in order to rate examples.
  • I Rated an example but my vote isn't showing up. The ratings are updated in a batch process that is run periodically. Thus, when you rate an example, your vote may not affect the rating for that example immediately.

Query Types - Not

Query types that JExamples does not currently support:
  • Java statement type. We do not support searching for an example of how to use, for example, the java while, or try statement. However, when you are viewing a source file found in JExamples, you can use your browser's Find feature to search for java keywords.
  • Method overloads. You cannot specify method argument information in your search.
  • Other programming languages. Our database only contains code from Java Open Source projects.