Learning Programming #3.0 Using Java: The standard library

Now that you know all the specialties of java it is time to do some actual programming.
Java provides a pretty advanced standard library compared to other languages. That allows you to easily access useful algorithms and classes without needing to install them yourself or downloading any other library. This post is about some classes that are useful in any kind of application.

java.lang.Math

Math is automatically imported → so you don't need to import it when you use it.
Math contains all sorts of mathematical functions. Some of them are listed here:

mathematical expressionjava function
sin(x)Math.sin(x)
cos(x)Math.cos(x)
tan(x)Math.tan(x)
sin⁻¹(x)Math.atan(x)
cos⁻¹(x)Math.acos(x)
tan⁻¹(x)Math.atan(x)
tan⁻¹(Δy/Δx)Math.atan2(y, x)
e^xMath.exp(x)
a^bMath.pow(a, b)
√xMath.sqrt(x)
∛xMath.cbrt(x)
∣x∣Math.abs(x)

java.lang.System

System is a class that handles a lot of general stuff. It is like Math also automatically imported.
Here are some useful functions of system:

functionuse
System.exit(1)Kills your program
System.currentTimeMillis()Returns the time in milliseconds(10⁻³ s). Can be used to calculate the current date.
System.nanoTime()Returns the time in nanoseconds(10⁻⁹ s) with unknown accuracy(usually inaccurate to a few µs(10⁻⁶ s). nanoTime can only be used to determine relative time between two measurements.
System.out.print(string);Prints the string into the terminal.
System.out.println(string);Prints the string + "\n" into the terminal.

java.lang.Thread

Apart from allowing multithreadding through Thread.run(), Thread also contains another generally very useful function:
Thread.sleep(int milliseconds)
This will have the current Thread sleep(being inactive) for the given amount of milliseconds.
But be careful about that. Java tends to oversleep a little → the actual sleep time might be up to 1 ms longer than specified, but that doesn't matter in most applications.

Here an image from a 4d-projection(I'll explain that somewhere in a future post.) class I wrote some time ago. And it contains some Maths:
Screenshot from 2019-07-04 23-53-12.png

If you missed any of my previous posts you can find them at #quantumdeveloper!

Sort:  

Congratulations @quantumdeveloper! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You distributed more than 200 upvotes. Your next target is to reach 300 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

You can upvote this notification to help all Steem users. Learn how here!

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 70880.42
ETH 3658.45
USDT 1.00
SBD 3.75