Posts

Showing posts from November, 2019

Java Packages

Image
Java Packages Learning a Programming language and especially a robust OOP language such as Java is a process--or rather many processes.  This post covers an example of such a process. I knew what namespaces were/are.  I thought of a namespace as a dictionary, or glossary, or maybe a reference codebook.  I still think that works for me, but I found this definition in one of the links below: A namespace is a group of related elements that each have a unique name or identifier. Just as computer operating systems, domain names, and so many other structures need namespaces, so does Java. I learned how to use packages I just told my IDE (yes, more on command line preferences in other posts) to make a package, then when my classes and interfaces were inside that package they had access to each other. I knew that Java comes with its own packages which provide ways to extend visibility among various classes/java files The package keyword, if it appears, must be ...

Java: Reference vs. Object

Image
Declaring and initializing reference variables When learning Java we see reference variables declared and initialized like this: Case A:  ABC varName = new ABC(); Later in our learning, we see something like this: Case B:  ABC varName = new DEF(); Let's take this as an example for discussion: Dthing varName = new Othing(); What is Dthing and what is Othing? From the first chapters of introduction to Java we know that Dthing is the type, and Othing is a constructor, and so is the class of varName. More advanced instruction shows: Dthing is the Declared Type, or Reference Type (I have found them used interchangeably) Othing is the Object Type This vocabulary is needed for reasons including discussion about when to declare/instantiate with the Declared Type being the same as the Object type, and when they should be different. An example of that decision would be in the below. The why is another subject/post: List<String> varStrin...

Java classpath: showing Java where the classes are

Java ClassPath...its purpose Some of my posts are "what I have learned", others are more "what I am learning".  I prefer the former, bu this one is more the latter. The subject of classpath has been hard for me to internalize...more below on why (IDEs). When I installed my JDK I needed to alter my environmental variables on my computers so I could run java from the command line.  I had to add the location of my JDK to the path.  Installation instructions include this point: Include JDK's " bin " Directory in the  PATH They then show how to access the path and variables on Windows 10 and other platforms. So, of course I already did that. with C:\Program Files\Java\jdk1.8.0_231\bin But then I kept seeing Java documents, textbooks, tutorials saying I must add JARs or packages, or such to the classpath.  I wondered why my projects were working without doing any of that. I wondered about classpath because I had already done the abo...