`

Java Programming Tricks 1

    博客分类:
  • Java
阅读更多

1、计算时间

 

       long StartTime = System.currentTimeMillis(); // 取出目前時間

// ==============================
// 你的程式
// ==============================

long ProcessTime = System.currentTimeMillis() - StartTime; // 計算處理時間

 

 

2、线程休眠

 

       try {

       Thread.sleep(500);

} catch (InterruptedException e) { }

 

 

3、生成随机数

 

       int randomNumber=(int)(Math.random()*8)+1

 

 

4Runtime.getRuntime( ).exec( ) 的运用

 

1)打开本地文件

public class OpenFile {

    public static void main(String[] args) {

        String path = "c:/temp/SW.txt";

        try{

            Runtime.getRuntime().exec("cmd /c start "+path);

        }catch(Exception e) {

           

        }

    }

}

2)运行.bat文件

public class RunBat {

    public RunBat (String cmdline) {

        try{

            Process p = Runtime.getRuntime().exec(cmdline);

        }catch(Exception e) {

        }

    }

    public static void main(String[] args) {

        new RunBat("c:/temp/test.bat");

    }

}

3)运行exe 文件

public class OpenFile {

    public static void main(String[] args) {

        try{

            Runtime.getRuntime().exec("c:/temp/WinRAR.exe");

        }catch(Exception e){

        }

    }

}

 

 

 

5HashMap 用法

 

private static final String FUND_KEY = "fund";

private static final String SUB_KEY = "subaccount";

 

HashMap resultMap = new HashMap(2);

List mrFunds = new ArrayList();

List mrSubaccts = new ArrayList();

resultMap.put(FUND_KEY, mrFunds);

resultMap.put(SUB_KEY, mrSubaccts);

return resultMap;

 

HashMap mrAccts = getSelectedChildrenForMRGroup(groups);

List mrFunds = (List)mrAccts.get(FUND_KEY);

List mrSubacctouns = (List)mrAccts.get(SUB_KEY);

 

6Log

 

public void save_old(AddClient addClient) {

              log.debug("execting AddClient");

              try {

                     getHibernateTemplate().save(addClient);

                     log.debug("AddClient successful");

              } catch (RuntimeException re) {

                     log.error("AddClient failed", re);

                     throw re;

              }

       }

 

 

分享到:
评论

相关推荐

    JAVA-TricksoftheJavaProgrammingGurus.zip_java programming_tricks

    以上只是一部分可能包含在"Tricks of the Java Programming Gurus"中的知识点。这些技巧可以帮助开发者成为真正的Java编程大师,提升代码质量,降低维护成本。深入学习和实践这些技巧,将使你在Java开发道路上...

    TRICKS OF THE JAVA™ PROGRAMMING GURUS

    TRICKS OF THE JAVA™ PROGRAMMING GURUS

    Java.Crash.Course.1541019245.epub

    "Java Crash Course" contains a multitude of tips and tricks, examples and exercises you can do to grow your Java programming skills to unprecedented levels. We chose the content of this book carefully...

    Java Crash Course [2016]

    "Java Crash Course" contains a multitude of tips and tricks, examples and exercises you can do to grow your Java programming skills to unprecedented levels. We chose the content of this book carefully...

    hands-automation-testing-java-beginners(2018)

    Write any Java program logic with strategies, tips, and tricks Leverage advanced topics in Java collections to solve Java-related problems Understand and use objects, classes, methods, and functions ...

    Manning Java Reflection In Action

    英文经典原著 Java Reflection in Action Java Reflection in Action is unique in presenting a clear account of all the cool things you can do with reflection, and...author of Concurrent Programming in Java

    Java 9 Concurrency Cookbook - Second Edition

    As a teacher, has taken over 1,000 hours of training in basic Java, J2EE, and the Struts framework. As a researcher, he has worked in the field of information retrieval, developing applications for ...

    学java该看的一些书~

    - **《Java Tips and Tricks》**:该书通过一系列的小贴士和技术要点帮助读者解决常见问题,并掌握一些高效编程的方法。 - **O'Reilly 出版的《Java I/O》**:深入介绍了 Java 输入输出流的概念和使用方法,对于理解...

    Java Reflection in Action

    sometimes perplexing programming techniques along with enough background to understand how to extend and vary them. This book overcomes reflection’s reputation as a mysterious and esoteric philo- ...

    Agile.Java.Development.with.Spring.Hibernate.and.Eclipse

    Also, Extreme Programming (XP), Agile Model Driven Development (AMDD) and refactoring are methods that can expedite the software development projects by reducing the amount of up front requirements ...

    Agile.Java.Development.with.Spring.Hibernate.and.Eclipse-part3

    Also, Extreme Programming (XP), Agile Model Driven Development (AMDD) and refactoring are methods that can expedite the software development projects by reducing the amount of up front requirements ...

    Android.Programming.The.Easy.Way

    This step-by-step guide has examples on every page and is filled with bonus tips and tricks to make your app stand out. If you follow this guide you will have a completed app in as little as one day. ...

    Groovy in action

    Groovy in Action is a comprehensive guide to Groovy programming, introducing Java developers to the new dynamic features that Groovy provides. To bring you Groovy in Action, Manning again went to the...

    翻写拍砖游戏--说明Windows编程原理

    并且有一本《Tricks of the Windows Game Programming Gurus》英文(或者中文)书籍正在阅读。 说明:当看到André Lamothe大师所著游戏编程书籍时非常兴奋。本人在学习《Tricks of the Windows Game Programming ...

    [Wrox] C# 5.0 Programmer's Reference

    Author Rod Stephens is a well-known programming authority and has written more than 25 programming books covering C#, Java, VB, and other languages. ☆ 出版信息:☆ [作者信息] Rod Stephens [出版...

    PHP.and.Algorithmic.Thinking.for.the.Complete.Beginner.1503015

    This book is for anyone who wants to learn computer programming and knows absolutely nothing about it. Of course, if you are wondering whether this book is going to teach you how to create amazing ...

    C# 5.0 Programmer’s Reference

    Author Rod Stephens is a well-known programming authority and has written more than 25 programming books covering C#, Java, VB, and other languages. His books have sold more than 60,000 copies in ...

Global site tag (gtag.js) - Google Analytics