Comp.Lang.Java.FAQ ------------------ FAQ: JAVA-General VER: 1.05 (22MAR96) LOC: HTTP://www-net.com/java/faq/faq-java.txt Written by D'Arcy Smith (dsh@unix.infoserve.net) Mar 11th 1996. Please e-mail me corrections/improvements/suggestions. TOC --- 0. Leagal Stuff 1. Revision History 2. What Is Java(tm)? 3. What do I need to use it? 4. Where do I get it? 5. Frequently Asked Questions Appendix A. Product Descriptions 0. Legal Stuff -------------- "Java and HotJava are trademarks of Sun Microsystems, Inc., and refer to Sun's Java programming language and HotJava browser technologies. Comp.Lang.Java.FAQ is not sponsored by or affiliated with SUn Microsystems, Inc." You are free to distribute this FAQ as long as this section is distributed "as is" along with it. Please direct any questions to me (D'Arcy Smith) dsh@unix.infoserve.net 1. Revision History ------------------- 1.0.0 (Jan 3 1996) - Created. 1.0.1 (Jan 16 1996) - Minor formatting changes. - Addition of History section. - Addition of Appendix A. 1.0.2 (Feb 1 1996) - Changed for JDK 1.0. - Minor changes to some descriptions. - Removed section 5 (Where can I get more info?). 1.0.3 (Feb 23 1996) - Added JDK 1.0 for Mac. - Minor corrections. - Added "How to use multiple mouse buttons". 1.0.4 (Mar 8 1996) - Revisionary history on the version numbers. - Added new Netscape platform (Mac, OSF1). - Added Windows to the Netscape platforms. - Minor changes to wording. - Added "Other IDE's" to Appendix. - Added Symantec IDE for Mac. 1.0.5 (Mar 22 1996) - Added severl products. - Reformatted to about 73 columns. - Updated JDK version number to 1.0.1. - Changed from "Comercial Products" to "Products". 2. What Is Java(tm)? -------------------- Java(tm) is an Object Oriented platform independent programming language from Sun. 3. What do I need to use it? ---------------------------- - The Java(tm) Developers Kit. - A Java(tm) enabled web-browser (optional). 4. Where do I get it? --------------------- The current version of the JDK is 1.0.1. The JDK is currently available from the following places: Sun - http://www.javasoft.com Symantec* - http://cafe.symantec.com IMB* - http://ncc.hursley.ibm.com/javainfo/ Randy Chapman - ftp://java.blackdown.org/pub/Java/linux/ *see bottom for more description. for the following platforms: Solaris (SPARC) - Sun Windows '95 - Sun - Symantec Windows NT (INTEL) - Sun - Symantec MacIntosh (Motorolla 68030 (or greater) or PowerPC) - Sun - Symantec OS/2 - IBM AIX - IBM Linux - Randy Chapman Java(tm) Web Browsers are available from the following places: Netscape - http://home.netscape.com/ for the following platforms: HPUX - Netscape Irix - Netscape Linux - Netscape MacIntosh (PowerPC) - Netscape OSF1 - Netscape Solaris (2.3, 2.4) - Netscape SunOS - Netscape Windows '95 - Netscape Windows NT (Intel) - Netscape 5. Frequently Asked Questions ----------------------------- The Questions: A. Where do I get the documentation? B. How do I make my members protected (like C++) C. Why do I keep getting a "java.lang.NullPointerException" when using arrays? D. How do I declare a constant (like C++ const) in Java(tm)? E. How do I declare enums (like C enum) in Java(tm)? F. How do I get mouse button events? The Answers: A. Where do I get the documentation? ------------------------------------ The documentation is available at JavaSoft: http://www.javasoft.com Many helpfull documents can be found at: http://www-net.com/java/faq B. How do I make my members protected (like C++) ------------------------------------------------ Unlike C++, protected in Java(tm) means that sub-classes AND classes in the same package have access. eg: class A { protected int i; } class B { int f() { A a = new A(); a.i = 0; // in C++ this can't be done // ... in Java it can } } private protected variables do what you want though! eg: class A { private protected int i; } class B { int f() { A a = new A(); a.i = 0; // can't do this! } } Java(tm) has 5 levels of protection: 1) public - world access 2) protected - package and sub-class access 3) default - package access (any class in the package) 4) private protected - class/subclass access 5) private - class access C. Why do I keep getting a "java.lang.NullPointerException" when using arrays? ----------------------------------------------------------- 2 possiblities: 1) You've indexed past the array bounds 2) you haven't initialized the array correctly. example of an incorrectly initialized array: public class Test { public static void main(String args[]) { String sa[] = new String[5]; sa[0].charAt(0); } } example of a correctly initialized array: public class Test { public static void main(String args[]) { String sa[] = new String[5]; for(int i = 0; i < 5; i++) { sa[i] = new String(); } sa[0].charAt(0); } } Of course now you'll get a "java/lang.StringIndexOutOfBoundsException" but that's because all of the Strings are empty. D. How do I declare a constant (like C++ const) in Java(tm)? ------------------------------------------------------------ See E! final variables are non-modifiable. eg: class Test { public final static int CONST = 1; } class UseIt { public void f() { int i = Test.CONST; } } E. How do I declare enums (like C enum) in Java(tm)? ---------------------------------------------------- See D! Another "neat trick" from (Patrick Naughton ) is to use interfaces: "public interface TOKEN { public static final int IDENT = 1; public static final int KEYWORD = 2; } then just "implement" that interface, like: public class parser implements TOKEN { } and your methods in "parser" will be able to refer to IDENT all by itself." Thx Patrick! (An advantage of E over D is that you can implement many interfaces but you can only extend one class) F. How do I get mouse button events? ------------------------------------ This is from someone off of comp.lang.java (I don't remeber who...) public boolean handleEvent(Event evt) { switch(evt.id) { case Event.MOUSE_DOWN: if(evt.modifiers == evt.CTRL_MASK) { System.out.println("Right button pressed"); } else { if (evt.modifiers == evt.ALT_MASK) { System.out.println("Middle btn pressed"); } else { System.out.println("Left button pressed"); } } return true; } return super.handleEvent(evt); } Appendix A. Products Descriptions --------------------------------- 1. Symantec's Cafe ------------------ "Symantec's Cafe is the first integrated development environment for the development of Java applets and applications for Internet World-Wide Web pages. Cafe integrates Sun's Java Development Kit (JDK) 1.0 into Symantec's award-winning development environment for Windows 95 and Windows NT. Cafe provides a fully featured project management system, GUI source level graphical debugger in addition to sophisticated editing and browsing tools for dramatically increasing the productivity of Internet developers." 2. IBM ------ "IBM has been working on Java implementations since Summer 1995 and has a heavy investment in Java, having ported to OS/2 and AIX and with ports to OS/400, MVS and Windows 3.1 in progress. To obtain the current versions of the JDK, visit http://ncc.hursley.ibm.com/javainfo/ To receive announcments on porting status visit http://majordomo.hursley.ibm.com/majordomo/listsavail.html A technology demonstration of a Java-enabled browser for OS/2 is available from http://www.raleigh.ibm.com/WebExplorer/" 3. RogueWave's JFactory ----------------------- "Rogue Wave's JFactory is a visual interface builder and code generator for Java. JFactory provides a palette of visual controls and a set of design tools that help developers build, customize and maintain Java applets and applications quickly. JFactory generates Java source code that can be ported to wherever Java is supported, without any associated fees or licensing restrictions. JFactory is available now for Win95, WinNT and SPARC Solaris." 4. Step Ahead Software's JAVelin -------------------------------- "The latest version of the graphical object oriented development environment for JAVA, JAVelin has just been released. The version number is V4.42. Version 4.42: o Includes extra examples and quick feature summaries in the form of JAVelin projects which make it even quicker to get up to speed with the tool. o Fixes some minor bugs including the misformed comment bug which occured occasionally during code generation. It is available on the Step Ahead Software web site at http://www.ozemail.com.au/~stepsoft. Thank you to all those users who have registered their evaluation copy. Registration of your copy means that we can continue to provide leading edge tools at very reasonable prices." Don't forget if you have any feature requests or other product feedback for JAVelin don't hesitate to email us." 5. Innovative Software's OEW(TM) for Java ----------------------------------------- "The Object Engineering Workbench(TM) for Java(TM) (OEW for Java) is the first cross-platform graphical design and documentation tool for all applications written in Sun Microsystem's Java programming language, featuring relational database schema design and reverse engineering. OEW for Java provides object-oriented analysis, design, implementation and documentation of Java-based applications in a stand-alone, integrated development environment! OEW for Java is available now for Microsoft Windows 95 and Windows NT. Versions for OS/2, Sun Solaris and HP-UX will follow soon. For more information check out http://www.isg.de/" 6. ModelWorks' JPad ------------------- "JPad is a Java editor integrated with Sun's Java tools. JPad makes it easy to write, compile and run Java applications and applets in a single environment using either Windows 95 or Windows NT 3.51. Even finding errors is easy - you just click on the error message and JPad will locate and display the error. JPad costs $29. You can download a 15 trial from http://www.modelworks.com/express" 7. Other Products ----------------- There have been requests for other IDE's - I will include them if they : - support the JDK 1.0.x - provide a write-up