I've been struggling with my first regex. During the compile, Pattern and Matcher kept getting cannot find symbol errors.
I just changed import java.util.* to import java.util.regex.* and it works like a dream.
I was under the impression that importing java.util.* would also bring in java.util.*.* etc. Is that not the case? I can't find any documentation that addresses this specific question....
No, package imports only get the direct classes in that package (java.* will not import everything, only ones such as Java.SomeClass, not java.util.SomeClass)
Importing java.util.* will not import java.util.*.*.
Yes, that is how package imports work (and are supposed to work) in Java. For example, doing import javax.swing.*; will import all classes within javax.swing.* but not sub-packages and their classes.
Ergo, javax.swing.* will not import javax.swing.event or javax.swing.event.*
Read the following blog for some friendly newbie advice.
See a link and a quoted excerpt from the link below.
http://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
Importing java.awt.* imports all of the types in the java.awt package,
but it does not import java.awt.color, java.awt.font, or any other
java.awt.xxxx packages. If you plan to use the classes and other types
in java.awt.color as well as those in java.awt, you must import both
packages with all their files:
import java.awt.*;
import java.awt.color.*;
Related
package esta.fontend;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import esta.dbConnection.ConnectionDB;
import net.proteanit.sql.DbUtils;// This is where i find the problem;
Image Link explaining my problem
rs2xml.jar doesn't contain the needed java class.
The most probably reason is that it was built incorrectly.
As you may see it contains 'src.net.proteanit.sql' which is empty.
So to fix the problem the jar should be rebuilt
The package should not include 'src' prefix
The DbUtils class should be truly included into it.
Java Servlets use usually the following import statements:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
If I get it right then javax.servlet.* imports everything inside the package. And because .http is a subpackage of .servlet:
Isn't the third statement unnecessary?
import javax.servlet.* should include .http already.
Or is my assumption wrong. Then please correct me.
No, Java don't do that.
Importing javax.servlet.* imports all of the types in the javax.servlet package but not the types declared in javax.servlet.http.
See tutorial (Apparent Hierarchies of Packages section)
I wanted to import a java package "TestPackage" into jython script,
import TestPackage
print TestPackage.SampleClass().getMessage();
I am getting the following error,
ImportError: No module named TestPackage","errorPoint":"","lineNumber":"1","errorPointMessage":"in <module>\nImportError: No module named TestPackage
When I use from TestPackage import SampleClass works fine. If I execute from <pacakage> import <anyclass> statement once, then import <pacakage> works without the import error.
I tried setting PySystemState.add_package("TestPackage"), this works but leading to memory leakage.
Is there any alternative way to make use of import TestPackage ? How can I use "import <packagename>" in jython without memory leakage?
This is due to a difference in Java and Python.
In Java you can import classes, and static import constants and static methods. You cannot import a package. import java.util; is a compile error, but import java.util.Collections; or import java.util.Collections.*; are fine. A Java package is a way of organizing a bunch of classes but doesn't isn't a class with a constructor, methods, or constants. I like to think of a Java package as a zip file containing all the classes that belong to that package. A Java package is merely a namespace.
In Python you can import modules, classes, and from-import classes, functions, and constants. However, a Python module is a lot more like a Java class than a Java package. It is not merely a "zip file of classes", but a class that contains subclasses. A Python module is a collection of scripts in a folder with an init.py, which defines classes and methods for that module. Thus, you can do things like import collections. Python also lets you do import collections.OrderedDict, from collections import OrderedDict, and from collections import OrderedDict as OD.
I hope this explains why you can't import your Java package. You have to import something (probably a class) from that Java package in order for python to create a variable.
Anyone used these imports in your files...?
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
I have an example that uses these imports. I have commons-codec-1.6.jar/httpclient-4.1.2.jar/httpcore-4.1.2.jar/commons-logging.jar in my classpath. Still the import fails. any inputs?
That's Apache commons-httpclient. And the Javadocs for that library.
What is difference between java.awt.* and java.awt.event.*?
It's just two different packages.
When you say import java.awt.* it imports only those classes which belong exactly to java.awt package, not to its subpackages.
That's why when you want to use events you have also import java.awt.event.
Do you mean while importing? They are different packages. They aren't necessarily related. Importing java.awt.* doesn't import java.awt.event.*