Scala, Java, Unix, MacOS tutorials (page 1)

Java double FAQ: How do I format Java double and float output to two decimal places, such as when I want to format its output for printing or to display in a user interface?

Solution: Java double formatting

There are at least two ways to round a double or float value to two decimal places in Java:

While many people know the famous Ram Dass book, Be Here Now — which is currently the #1 All-Time Best-Selling book in Spiritualism on Amazon — I’d argue that it’s not necessarily his best book. For example, I have met a few people in my travels who were struggling to read and understand it it because of all the art and 1960s “hippie style” stuff — which I personally like — and it was at that time I realized that while Be Here Now is his most famous book, it may not be his best book.

Ram Dass’s best books

IMHO, I think the following books are his best, where I believe best will also depend on a person’s experience with his writings and teachings, and also their own progress on the spiritual path.

In my post on Ram Dass’s best books and other places, I use terms related to the work of Ram Dass, including terms on yoga, Hinduism, Maharaj-ji, Buddhism, meditation, mindfulness, mantras, and the different names of the man he called Maharaj-ji (aka, Maharaji, Neem Karoli Baba, Neeb Karori Baba).

Sources of the terms and definitions

To help understand that article, and the speeches, books, and other writings of Ram Dass, I have put together the following “Ram Dass glossary of terms.” Note that the definitions below come from internet research and the following books:

Sanskrit terms

In The Bhagavad Gita, by Eknath Easwaran, he states in his glossary that these are Sanskrit terms. Wikipedia describes Sanskrit as, “a classical language belonging to the Indo-Aryan branch of the Indo-European languages.”

Glossary

Here’s the glossary of terms:

Scala dates FAQ: How do I calculate the difference between two dates? That is, while using Scala — Scala 2 or 3 — you need to determine the difference between two dates.

Solution: Calculating the difference between two dates (in Scala and Java)

If you need to determine the number of days between two dates in Scala (or Java or Kotlin), the DAYS enum constant of the java.time.temporal.ChronoUnit class provides the easiest solution:

When I first started meditating in the 1990s, I often had a hard time getting into the proper meditative state when I sat down on the meditation cushion. My “monkey mind” would be jumping all over the place, and it would take me a long time to get it to settle down. Many times I couldn’t even get it to settle down before my 30-minute timer went off.

Because of that, and because I really wanted to become better at meditating, I began experimenting with different ways to get into the meditative state faster — as fast as possible.

As a result, this page is a summary of the best ways I know to help you get into a good meditation state when you take time to sit on the meditation cushion (or wherever else you sit). If you’re interested in getting into a deep state fast, these are the “best practices” I know, especially when you’re short on time.

One note

I start off with several tips that I have labeled “All Day.” The intent of those tips is that you can use them all day to keep your mind in a great state all day. If you follow these tips, you’ll be in a great state even before you start with your formal meditation session.

After those initial tips, I get into other techniques that you can use just as you sit down on your cushion (or however else you meditate).

Yesterday I watched the very emotional Elton John “Tiny Dancer” music video, and afterwards I wanted to do some research on how the music video was created, the story behind it, and what its meaning is. To that end, here’s a summary of what I found out about the “Tiny Dancer” music video.

The story and meaning of the Tiny Dancer song

The short story behind the Tiny Dancer song goes like this:

I just took a little time to share some old notes from my meditation practice about “The purpose of mindfulness.” Or, stated another way, instead of asking about the purposes of being mindful you might ask, “Why bother being mindful?”, or “What are the motivations for practicing mindfulness and meditation?”

The purposes of mindfulness

In the following sections I describe the reasons/motivations for practicing both mindfulness and meditation.

I don’t know how many people know Ram Dass or have read his writings, but I updated the first motivation here based on his work, because if you really get into mindfulness and meditation, what he states is the end goal.

As a brief note today, when you’re using SBT and its build.sbt file with Scala projects, use %% in library dependencies when referring to Scala-specific libraries, and use only one % character when referring to other JVM dependencies, like Java dependencies. Here are some examples of this syntax:

I recently started reading the “spiritual classic” book, I Am That, by Nisargadatta Maharaj. The book is rated 4.8 stars on Amazon and 4.4 on Goodreads, so that’s pretty impressive.

After reading the first 100 pages or so, I’m glad to report personally that there isn’t anything significantly new here for me. Even though I never saw Ram Dass refer to Nisargadatta Maharaj, the words in this book are remarkably similar to those in Ram Dass’s best books, which I have already written about. That is, the words are a little different, but all of the concepts are the same, and they are consistent with what I know about meditation.

the small man
builds cages for everyone
he
knows,
while the sage,
who has to duck his head
when the moon is low,
keeps dropping keys all night long
for
the
beautiful
rowdy
prisoners.

~ an old Persian named Hafez

Java date FAQ: How do I get the current date (now, today) in Java? (Also, how do I get the current time in Java?)

Solution

With Java 8 and newer — i.e., Java 11, 14, 17, etc. — use any of the follow “now” methods on these Java classes to get the current data and time:

In my earlier posts on the best Ram Dass book to start with and the best Ram Dass books I know, I didn’t mention his book, Grist for the Mill.

Since I forgot to mention it, today I’d like to note a few things about it. First, I think it’s a really good book, it’s just not the first Ram Dass book I’d recommend.

US Magazine has a little story on the separation of Coldplay singer Christ Martin and Gwyneth Paltrow, and it includes this quote about Rumi’s The Guest House and a book called Man’s Search for Meaning (by Holocaust survivor Viktor Frankl) that I read almost thirty years ago. (I don’t know too many Coldplay songs, but I do like Clocks.)

Coldplay’s Chris Martin: So happy to be alive

Listen with ears of tolerance.
See through the eyes of compassion.
Speak with the language of love.

~ Rumi

My religion is love.
Love is the bridge between you and everything.
Let the beauty of what you love be what you do.
Be a witness, not a judge.
I am not this hair, I am not this skin, I am the soul that lives within.
Wear gratitude like a cloak and it will feed every corner of your life.
You have to keep breaking your heart until it opens.
Past and future veil God from our sight; burn up both of them with fire.

~ Rumi

As a brief note today, the PDF version of my book, Learn Functional Programming The Fast Way!, is now FREE. I wrote this functional programming book for Scala, Java, and Kotlin developers, and you can now download it for free here:

If you’re interested in functional programming, or just want to learn more about data types, generics, pure functions, expression-oriented programming, and functional error handling, I hope this book is helpful.

Free functional programming book (for Scala, Java, Kotlin, etc.)

“As a general principle, any positive state that you experience within the context of silent sitting practice (when you reach the state of samadhi), you must try to attain in the midst of ordinary life.”

~ Shinzen Young’s teacher

“Have you got any cookies?”

~ Frank Burns, in M*A*S*H

Frank Burns, Mash: Have you got any cookies?

Dear diary,

Annihilation of the ego continues to make progress, at least during sleeping hours. In recent nights I’ve gained awareness during the dream state to find “myself” as animals, women, and other men.

Last night I gained awareness as an older black man, talking to other black men about some of the discrimination and injustices we’ve gone through in our lives. We can laugh a little amongst ourselves about them now, but I could feel that under the laughter there’s also a deep sadness and pain.

Lately each nightly occurrence ends the same way: Eventually there’s a realization that “I” am supposed to be “Al,” and that realization startles me, pulls me from the scene, and wakes me.

Yours truly,
The Hopefully-Disappearing Self

P.S. — I don’t know if it’s more correct to say “black man,” “African-American,” or something else. To be clear, if it wasn’t important to the story I would not mention it at all.

In my experience, some “judgy” people will make up their own opinion about you — about what you should do or shouldn’t do — when they don’t know all the facts. I use the word judgy, because if you’re a Christian, Jesus was very clear on this point:

Judge not, that ye not be judged.

To wit, sometimes you just have to let people be wrong about you. (From this tweet by TinyBuddha.)

Sometimes you just have to let people be wrong about you