Remember back in the days of college when you were allowed to make one sheet of notes for math exams? Well, think of this as a cheat sheet for you Java exam.
Client client = new Client() {{ setId(1); setName("Client 1"); }};
private static final URL SOME_URL_CONSTANT; static { URL url = null; try { url = new URL("http://example.com"); } catch (MalformedURLException e) { e.printStackTrace(); } SOME_URL_CONSTANT = url; }
System.setProperty( "org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog" );
for ( Method method : candidate.getClass().getMethods() ) { if ( "getCode".equals( method.getName() ) && !method.isSynthetic() ) { System.out.println( "Type is: " + method.getGenericReturnType() ); break; } }
Type is java.lang.String
candidate is an instance of an implementation where T=java.lang.Integer.for ( Type interfaceType : candidate.getClass().getGenericInterfaces() ) { if ( interfaceType instanceof ParameterizedType && ( (ParameterizedType) interfaceType ).getRawType().equals( CustomInterface.class ) ) { System.out.println( "Type is: " + ( (ParameterizedType) interfaceType ).getActualTypeArguments()[0] ); break; } }
Type is java.lang.Integer
public <T> T giveMeWhatICameFor( T whatIWant ) { return belongings.get( whatIWant ); }
Method method = beanClass.getDeclaredMethod("setIntegers", List.class); System.out.println(((ParameterizedType) method.getGenericParameterTypes()[0]).getActualTypeArguments()[0]);
$> mvn deploy -DupdateReleaseInfo=true
<dependency> <groupId>com.example</groupId> <artifactId>artifact</artifactId> <version>[1.1.12]</version> </dependency>
mvn archetype:create -DarchetypeCatalog=file://$HOME/.m2
| Phase | Description |
|---|---|
| validate | validate the project is correct and all necessary information is available. |
| generate-sources | generate any source code for inclusion in compilation. |
| process-sources | process the source code, for example to filter any values. |
| generate-resources | generate resources for inclusion in the package. |
| process-resources | copy and process the resources into the destination directory, ready for packaging. |
| compile | compile the source code of the project. |
| process-classes | post-process the generated files from compilation, for example to do bytecode enhancement on Java classes. |
| generate-test-sources | generate any test source code for inclusion in compilation. |
| process-test-sources | process the test source code, for example to filter any values. |
| generate-test-resources | create resources for testing. |
| process-test-resources | copy and process the resources into the test destination directory. |
| test-compile | compile the test source code into the test destination directory |
| test | run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed. |
| prepare-package | perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above) |
| package | take the compiled code and package it in its distributable format, such as a JAR. |
| pre-integration-test | perform actions required before integration tests are executed. This may involve things such as setting up the required environment. |
| integration-test | process and deploy the package if necessary into an environment where integration tests can be run. |
| post-integration-test | perform actions required after integration tests have been executed. This may including cleaning up the environment. |
| verify | run any checks to verify the package is valid and meets quality criteria. |
| install | install the package into the local repository, for use as a dependency in other projects locally. |
| deploy | done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. |
http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide
To do anything in Maven 2, you have to have a POM file in place (pom.xml). First create a minimalistic POM file containing the library you wish to download.
<project> <modelVersion>4.0.0</modelVersion> <groupId>none</groupId> <artifactId>none</artifactId> <version>1.0</version> <dependencies> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.0.20070617</version> </dependency> </dependencies> </project>
Then use the Maven 2 dependency plugin to resolve the dependency into your local repository.
mvn dependency:resolve
com.mysql.jdbc.Connection#execSQL( Statement callingStatement, String sql, int maxRows, Buffer packet, int resultSetType, int resultSetConcurrency, boolean streamResults, String catalog, boolean unpackFields, boolean isBatch )
Generally you should try to avoid cloning objects blindly (you are probably doing something wrong in your application). But if you really need to do it, one approach is to serialize then deserialize the object (all containing objects must be serializable):
ByteArrayOutputStream byteArrOs = new ByteArrayOutputStream(); ObjectOutputStream objOs = new ObjectOutputStream(byteArrOs); objOs.writeObject(this); ByteArrayInputStream byteArrIs = new ByteArrayInputStream(byteArrOs.toByteArray()); ObjectInputStream objIs = new ObjectInputStream(byteArrIs); Object deepCopy = objIs.readObject();
$> ./run.sh --host=0.0.0.0
(?s)\A((?!string_not_present).)*\Z (check Regular Expression box)