Comp.Lang.Java.FAQ ------------------ FAQ: JAVA-General VER: 1.04 (11MAR96) 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. Comercial Products 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 - why did nobody ever tell me I missed those?!?!?!? (I use 'em even!) ;-) - Minor changes to wording. - Added "Other IDE's" to Appendix. - Added Symantec IDE for Mac. 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 The JDK is currently available from the following places: Sun - http://www.javasoft.com Symantec* - http://www.symantec.com *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 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 you 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. Comercial 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. Other IDE's -------------- There have been requests for other IDE's - I will include them if they : - support the JDK 1.0 - provide a write-up ----------------------------------------------------------------------------