Wednesday, October 3, 2018

I watched the beginning of a chunk of training on Java today.

In the folder for a version of the JDK there will be a javac.exe file and this file is the compiler. You may use it to convert your code to an executable. If you want to run your code however, you use a version of the JRE. When you open Red Hat JBoss Developer Studio and create a new project you will be prompted to pick a version of the JRE to use. When you right-click on class in Red Hat JBoss Developer Studio and pick "Java Application" from under the "Run As" menu it will attempt to run the method with this signature:

public static void main(string[] args) {

 
 

Looks a lot like C#, huh? The packages should be named in all lowercase letters by convention and the classes in Pascal case just like in C#. At the top of a class inside of a package, the package will be called out like it's the immediate namespace like so:

package foo;

 
 

...assuming a package named foo. If we have a variable named bar, we could print its contents like so:

System.out.println(bar);

 
 

...and something tricky with this is that we have to instantiate bar first if bar is a local variable (or else the compiler will squawk), but we do not have to instantiate bar first if bar is an instance variable. The training I saw drew distinctions between instance, local, and static variables. Static variables are the same thing they are in C#. The concepts of instance and local variables could apply to C# too, I just haven't personally heard these terms thrown about in that space. Variables that are just inside of an instance class (without being inside of one of its methods) which have property accessors at the beginning of their definitions, i.e. class-wide variables in an instance class, are instance variables. Variable nested inside of a method with no property accessors are local variables, local to that method.

No comments:

Post a Comment