330 thủ thuật Java - 330 Java Tips

203 14 0
  • Loading ...
1/203 trang
Tải xuống

Thông tin tài liệu

Ngày đăng: 01/04/2019, 20:39

Tài liệu cung cấp 330 thủ thuật lập trình Java, tài liệu dưới dạng tiếng anh thích hợp cho học sinh, sinh viên chuyên ngành công nghệ thông tin (lập trình) dùng để tự học lập trình Java, và thích hợp cho giáo viên, giảng viên dùng làm tài liệu tham khảo khi giảng dạy Va nT ho ng Start Here! page file:///C|/330_new/330_new/first_page.htm [2003-07-22 22:07:44] Contents at a Glance Hello dear friend! I am very glad that you are here! "330 Java Tips" is my collection of good questions and answers from my site, numerous Java forums and newsletters ho Please visit my site at: http://JavaFAQ.nu ! ng Please read the answer to question that I published on my site about reading file lists from current directory in section "Code Examples" here nT Receive our newsletter with new tips! More than 13,500 subscribers (by 10 July 2003) can not be wrong! They read our tips every week! Va To subscribe to the "Java FAQ Daily Tips" weekly edition newsletter please send e-mail with "subscribe" word in the header and the body (write just subscribe without ""!!!) to: javafaqtips-request@javafaq.nu or on the web: http://www.javafaq.nu/plm2html/my_subscription.shtml Contents at a Glance ••••••••••••••••••••••••••••••••••••••••••••••• Applets Code Examples Databases & beans Distributed systems File Systems - I File Systems II Graphics, AWT, Swing-I Graphics, AWT, Swing-II General Java - I General Java -II General Java -III General Java -IV General Java -V Java Hardware page file:///C|/330_new/330_new/index.htm (1 of 2) [2003-07-22 22:07:45] Contents at a Glance Job, fun Miscellaneous-I Miscellaneous-II Networking OSs & Java Servlets & Servers Threads Sound & Multimedia String, text, numbers, I/O- I String, text, numbers, I/O- II About Book ho ng About Author Va nT Excuse me for possible mistakes! English is not native language for me I will be glad if you send me your corrections of my mistakes! (c)1999, 2000, 2001, 2002, 2003 http://JavaFAQ.nu All rights reserved worldwide This document can not be changed, either in whole or in part without the express written permission of the publisher All questions please page file:///C|/330_new/330_new/index.htm (2 of 2) [2003-07-22 22:07:45] Code Examples Receive our newsletter with new tips! More than 13,500 subscribers (by July 2003) can not be wrong! They read our tips every week! To subscribe to "The Java FAQ Daily Tips" weekly edition newsletter send email with "subscribe" word in the header and the body (write just subscribe without ""!!!) to: javafaqtips-request@javafaq.nu ng or on the web: nT ho http://www.javafaq.nu/plm2html/my_subscription.shtml Va Code Examples Code example: I want to show you one funny thing! The code is shown below is simplest that you can imagine and does very unusual thing! It is slightly bigger than "Hello World!" program but does much more It lists all files in the current directory if you run it like this: java test * (of course after compilation) in DOS/CMD prompt on Windows or in any shell in UNIX The program shows all files both in Unix and Windows If you do: java test * on UNIX it also shows all hidden files class test{ public static void main(String args[]){ for (int i = 0;i < args.length; i++) { System.out.println("File " + i + ":" + args[i]); } if (args.length65) Yes And just be aware that ASCII only runs from through 127 Anything higher needs to be addressed differently, since Java is using Unicode values Q: How to "Press any key to continue"? I want to it at Console Answer: // ReadConsole.java import java.io.*; public class ReadConsole { page 198 file:///C|/330_new/330_new/stings_text date_numbers_io-II.htm (8 of 10) [2003-07-22 22:08:09] String, text, numbers, I/O II part public static void main(String args[]) throws IOException { System.out.print("Press Enter to continue: "); System.in.read(); } } You cannot have "press any key" from the console, for various system-dependent reasons You need to press Enter -Paul Lutus www.arachnoid.com ng Q: Just wondering how people generally convert BufferedOutputStream into a BufferedInputStream to be read from ho This seems really stupid, but I can't find a way to it in the API nT Answer: if you want to just take what's coming in and send it out then something like this Va BufferedInputStream in = new BufferedInputStream(some inputstream); BufferedOutputStream out = new BufferedOutputStream(some outputstream); int i = 0; while((i = in.read()) != -1){ out.write(i); } of course you will have to handle exceptions, but that should be the general way to it -michael Q: I have heard that String concatenation operator + affects performance of program if it used much Is it true? Answer: Yes, it affects your program performance if you a lot of "+" operations with strings: A new StringBuffer must be created, then two arguments are added to it with append(), and the final result must be converted back with a toString() Your time and space is wasted In case if you are appending more than one String, try to use a StringBuffer directly -Alexandre P (J.A.) page 199 file:///C|/330_new/330_new/stings_text date_numbers_io-II.htm (9 of 10) [2003-07-22 22:08:09] String, text, numbers, I/O II part (c)1999, 2000, 2001, 2002, 2003 JavaFAQ.nu All rights reserved worldwide This document can not be changed, either in whole or in part without the express written permission of the publisher Va nT ho ng All questions please page 200 file:///C|/330_new/330_new/stings_text date_numbers_io-II.htm (10 of 10) [2003-07-22 22:08:09] About Book Receive our newsletter with new tips! More than 13,500 subscribers (by July 2003) can not be wrong! They read our tips every week! To subscribe to "The Java FAQ Daily Tips" weekly edition newsletter send email with "subscribe" word in the header and the body (write just subscribe without ""!!!) to: javafaqtips-request@javafaq.nu ng or on the web: nT ho http://www.javafaq.nu/plm2html/my_subscription.shtml Va About this e-book This book is my collection of numerous advices, tips I have collected on numerous Java forums, newsgroups and my site Here also many answers from my letters to people that asked me questions by email This book is a result of my daily work during last few years All answers can be found somewhere on Internet, but it takes much time to find them Having all of them in one place, in the form of e-book, saves you hundreds hours The answers are in form of advices, tips This book for "researcher" kind of people, who can manage to overcome obstacles without asking always full receipt That's why this book, I think, will be very useful not only for beginners but for advanced programmers as well Many questions in this book are not frequently asked and furthermore, easily answered even by Java Gurus They will show you that Java has many advantages that are not so obvious during your first study of it I bet that, if you even passed Java Certification Exam, you can not answer most of them stright away! This kind of questions demands not only understanding of JLS (Java Language Specification) but more broad knowledge as well, often from another languages and computer platforms Part of questions are touching a few languages simultuoneously and comparison of pros and cons Thus, they will give you more knowledge, better perspective to programming and computer science especialy In modern live we have to be better prepared for fast changing world Computer world changes even faster! This is most dynamically developing area of human knowledge and get updated page 201 file:///C|/330_new/330_new/about_book.htm (1 of 2) [2003-07-22 22:08:09] About Book fast - most difficult problem I often feel that it is like ice cake riding Small delay and you are in a cold water! As I mention above, this book is collection of tips that are given by many people on different Internet forums I had no possibility to contact to all of them about right to include their advices into this book Since they were published on public forums and are redistributed by many sites (that give access to newsgroups and their archives) I believe it will not be a problem if I will collect some of them into one book I kept the names and signs under tips that often points to their sites I think it will be even beneficial for them to be included into this book Va Alexandre Patchine nT ho ng Anyway, if somebody of you recognize the tip as yours and not agree to be included into my book, please send me e-mail and I will exclude your tip from this book The price for this book is a price of my job on collection and distribution this book (unfortunately big traffic costs money today) I will be glad to hear your comments and wishes on improving this book! As I mentioned on main page of this e-book, English is not native language for me and this book can (probably does) be in some extent grammarless Send me your correction of my mistakes! (c)1999, 2000, 2001, 2002, 2003 JavaFAQ.nu All rights reserved worldwide This document can not be changed, either in whole or in part without the express written permission of the publisher All questions please page 202 file:///C|/330_new/330_new/about_book.htm (2 of 2) [2003-07-22 22:08:09] About Author Receive our newsletter with new tips! More than 13,500 subscribers (by July 2003) can not be wrong! They read our tips every week! To subscribe to "The Java FAQ Daily Tips" weekly edition newsletter send email with "subscribe" word in the header and the body (write just subscribe without ""!!!) to: javafaqtips-request@javafaq.nu ng or on the web: About author Va nT ho http://www.javafaq.nu/plm2html/my_subscription.shtml John Andersson is my pseudonym which I use in my newsletters and on my website JavaFAQ.nu It will be probably long explanation why I, as well as other people, use pseudonyms So, I skip it for "clarity" :-) I am planning to continue my job in the future and collect more tips for you! Alexandre Patchine (c)1999, 2000, 2001, 2002, 2003 JavaFAQ.nu All rights reserved worldwide This document can not be changed, either in whole or in part without the express written permission of the publisher All questions please page 203 file:///C|/330_new/330_new/about_author.htm [2003-07-22 22:08:09] ... - I File Systems II Graphics, AWT, Swing-I Graphics, AWT, Swing-II General Java - I General Java -II General Java -III General Java -IV General Java -V Java Hardware page file:///C| /330_ new /330_ new/index.htm... http://www.javaworld.com/javaworld/javatips/jw-javatip101.html http://www.twf.ro/calculatoare/TricksJavaProgramGurus/ch1.htm http://www.galasoft-lb.ch/myjava/CommTest/backup00/ http://www.rgagnon.com/javadetails /java- 0181.html... page 16 file:///C| /330_ new /330_ new/applets.htm (1 of 13) [200 3-0 7-2 2 22:07:47] Applets String ss = System.getProperty(String key): java. version java. vendor java. vendor.url java. class.version
- Xem thêm -

Xem thêm: 330 thủ thuật Java - 330 Java Tips, 330 thủ thuật Java - 330 Java Tips

Gợi ý tài liệu liên quan cho bạn

Nhận lời giải ngay chưa đến 10 phút Đăng bài tập ngay