A very fast and easy way to debug your JavaScript applications on mobile devices is to use a remote JavaScript console listener, like jsconsole.com.
All you have to do is:
- Insert this code snippet with a unique id:
<script src="http://jsconsole.com/remote.js?BE73V55D"></script>
- Go to http://jsconsole.com/
- Type in:
:listen BE73V55D
- Watch your
console.logstatements, when using your application
If you are used to MySQL then you probably know the MySQL function NOW() which inserts the current date and time in a MySQL query. But if you use JDBC and prepared statements, then you can reconstruct this function with a GregorianCalendar (which is the successor of Date):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public void insertArticle(Article article) throws SQLException { //query = "INSERT INTO articles(title,content,date) VALUES (?,?,NOW())"; query = "INSERT INTO articles(title,content,date) VALUES (?,?,?)"; statement = connection.prepareStatement(query); statement.setString(1, article.getTitle()); statement.setString(2, article.getContent()); statement.setTimestamp(3, new Timestamp(new GregorianCalendar().getTimeInMillis())); logger.info(statement); statement.executeUpdate(); } |
That’s how you can use enumerations for string values:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | /* * ISO 3166 */ public enum Country { DE { @Override public String toString() { return "Germany"; } }, IT { @Override public String toString() { return "Italy"; } }, US { @Override public String toString() { return "United States"; } } } |
1 2 3 4 5 6 | public static void main(String[] args) { System.out.println(Country.DE); // Germany System.out.println(Country.IT); // Italy System.out.println(Country.US); // United States } |
With JUnit 4 it is pretty simple to test if an exception has been properly thrown because you can use annotations:
1 2 3 4 5 6 7 8 9 10 11 12 13 | import static org.junit.Assert.fail; import org.junit.*; public class MyTestClass { @Test(expected = NoMatchFoundException.class) public void testSomething() throws NoMatchFoundException { // Your critical code here! fail(); } } |
If you are using JUnit 3 then it is not that easy because you don’t have annotations. That’s why you have to catch exceptions in the test code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import junit.framework.TestCase; public class MyTestClass extends TestCase { public void testSomething() throws NoMatchFoundException { try { // Your critical code here! } catch (NoMatchFoundException ex) {} } } |
Möchte man einen langen Batch-Befehl auf mehrere Zeilen aufteilen, so muss man den Zeilenumbruch maskieren (escapen). Der Zeilenumbruch wird mit einem ^ angedeutet.
Beispiel:
REM Einzeilig: echo Hello World. REM Zweizeilig: echo Hello ^ World.
JavaScript is able to zoom in and zoom out of a web page. All you need is just this (for 200% zoom):
window.parent.document.body.style.zoom=2.0;

0