A quick dip of Java — Chapter 1

How does Java work?

Learning how before the what might actually make sense in this case. Java’s magic happens in 4 stages which could be broken down into 4 places namely, 1) the source, 2) the compiler, 3) the output (aka the bytecode) and 4) the virtual machine. Now lets look into each step in more detail.

The compiler used in the second stage is called “The Java compiler” and is used by typing javac, followed by the source code file name on the command as below.

javac Party.java

The above command will create the Party.class, bytecode” file which is interpretable using the JVM. One special thing about this .class file is, its platform independent and could be run using a Java Virtual Machine(JVM) configurable to any Java installable device, enabling the underlying platform to understand the set of commands.

History of Java?

Starting off with Java 1.0.2 with only 250 classes, Java 5.0 has grown into around 3500 classes in the standard library. The table below shows the progress in the number of classes over the years.

Anatomy of a class

When the JVM starts running,

  1. Look for the class you give it at the command line.
  2. Look for the main method: public static void main (String() args)
  3. Run everything between the curly braces { } in it.

Note: Every Java application has to have at least one class. and at least one main method per application.

Important things to note

  • A “class” is a blueprint for an object, nearly everything in Java is an object.
  • Other than the main “main” method, you can write test classes that have main methods for testing your other classes.
  • Java doesn’t allow boolean test on any other data type than boolean. Eg: if(3){} would give a syntax error.
  • The filename should have the same name as the public class name in that file, which is the way to tell the JVM that this is what the entry point is for you.
  • Fetching a random element from an array could be done this way,

int rand1 = (int) (Math.random() * arr.length);

  • Job of the compiler is to stop anything that would never succeed at runtime. However, there are some datatype exceptions that can emerge at runtime, but some of those is necessary for dynamic binding.

New Vocabulary

Jini surrogate architecture: Controlling a devices where Java can’t be enabled, through some other interface (like a laptop) that is running Java.

dynamic binding: Happens at runtime, when new objects that weren’t even known to the original programmer are created.

Thanks for reading so far. Until next time! 👋🏽



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Upulie Handalage

Upulie Handalage

Everything in my point of view. Here for you to read on....