Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38233
| From | Martin Gregorie <martin@mydomain.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: package statement in standalone Java class |
| Date | 2018-04-07 18:23 +0000 |
| Organization | albasani.net |
| Message-ID | <pab2a5$2qe$1@news.albasani.net> (permalink) |
| References | <d25b03ed-607f-45d0-8b45-25f3835d44bb@googlegroups.com> <paakd4$scj$1@dont-email.me> <57ad7674-0fca-4169-81a8-e98b5b084567@googlegroups.com> |
On Sat, 07 Apr 2018 08:25:47 -0700, Morten W. Petersen wrote: > I'm new to Java, and having Java, Maven and different libraries to > consider if I get an error seems too complex to debug. > Some points to consider: To a first approximation you should treat Java's 'import' statements as the equivalent to C's #include <header.h> preprocessor statements. Just as as you can't compile a C program that does anything much without using #includes and linking it with the relevant libraries, the only Java program you can compile without imports is one that only uses external classes from the java.lang group. The big difference it that you never need to mention imported classes and packages anywhere else. I use 'ant' rather than 'maven' - it may be closer to the way make works than maven is. The main differences from make are that build.xml is an XML document rather than the plaintext with strange ways of using TABs and spaces and you find in Makefile and there are built-in XML definitions for almost every tool you'll need to build a Java program and generate documentation for it. Don't even think of using 'make' to compile Java. Been there, done that, discovered it caiuses problems. While 'make' can be used to build very simple programs, the recursive nature of a multi-class Java compile soon ties 'make' in knots while 'ant' just gets it done. The package names give context to class names, so the custom has grown up of using your domain name as the most significant part of a package name to guarantee uniqueness, e.g. "com.example.mypackage.MyClass". This pretty much guarantees that, although every man and his dog might write their own MyClass class and publish it, if you also use this convention you'll never end up referencing his MyClass rather than your MyClass. The compiler expects this type of structured naming to be reflected in the sources its compiling, which is why the source files get names like "com/example/mypackage/MyClass.java". So you'd be well-advised to get used to working this way as soon as you start writing Java programs that contain more than one class. -- Martin | martin at Gregorie | gregorie dot org
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
package statement in standalone Java class "Morten W. Petersen" <morphex@gmail.com> - 2018-04-07 04:38 -0700
Re: package statement in standalone Java class Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-04-07 10:25 -0400
Re: package statement in standalone Java class "Morten W. Petersen" <morphex@gmail.com> - 2018-04-07 08:25 -0700
Re: package statement in standalone Java class Martin Gregorie <martin@mydomain.invalid> - 2018-04-07 18:23 +0000
Re: package statement in standalone Java class Arne Vajhøj <arne@vajhoej.dk> - 2018-04-07 15:58 -0400
Re: package statement in standalone Java class Martin Gregorie <martin@mydomain.invalid> - 2018-04-07 20:28 +0000
Re: package statement in standalone Java class Arne Vajhøj <arne@vajhoej.dk> - 2018-04-07 16:32 -0400
Re: package statement in standalone Java class Martin Gregorie <martin@mydomain.invalid> - 2018-04-07 21:35 +0000
Re: package statement in standalone Java class Eric Douglas <e.d.programmer@gmail.com> - 2018-04-09 04:57 -0700
Re: package statement in standalone Java class Arne Vajhøj <arne@vajhoej.dk> - 2018-04-09 18:01 -0400
Re: package statement in standalone Java class Arne Vajhøj <arne@vajhoej.dk> - 2018-04-09 18:07 -0400
Re: package statement in standalone Java class Arne Vajhøj <arne@vajhoej.dk> - 2018-04-09 19:34 -0400
Re: package statement in standalone Java class "Morten W. Petersen" <morphex@gmail.com> - 2018-04-10 16:28 -0700
Re: package statement in standalone Java class "Morten W. Petersen" <morphex@gmail.com> - 2018-04-07 16:14 -0700
csiph-web