View on GitHub

reading-notes

Code 201 Reading Notes

Java Imports

Went here to get an idea for imports, as the current link doesn’t resolve.

About Java Imports, they are imported with the import keyword right from the get-go, first thing stated in the code. With them it allows you to bring what you need in to the code, but only what you need, so as to keep the file size / code base size down. However, it’s not necessary: you could - if you wanted to - bring in the necessary parts, you would just have to write out the entirety of that class and object each time you reference it. On the other end of the import philosophy, you could bring the whole package by using a * to bring in that whole library.

Different types of loops in Java

The standard for loop is just like in JavaScript

for (initialization; Boolean-expression; step) {
  statement;
  }

nothing fancy, nothing exciting. But! You can label them by prepending the for loop with

There is also the “enhanced” for loop

for(Type item : items) {
  statement;
  }

in which you first declare the type within the item that will be looped over, then you name the item, and then specify the item that will be iterated over. So it feels very similar to the .forEach() method in JavaScript, but I’m sensing that theoretically, you could loop over a string, or different types of primitives, and not just arrays, I think?

Iterable.forEach() oh hey look. It’s a forEach() method, here to save a few lines of code and keystrokes!