Posts

Showing posts with the label noob

Java Primitive's little secrets

Here is a bunch of java primitives' interesting behaviour that we ofter ignore or forget! Recap time in 3 - 2 - 1... Data type promotions When you try to perform a numerical operation on a short type for example, the result will be promoted to int, therefore it wont compile if you try to store the result in a short variable unless you explicitly cast it (check line x). The same applies to byte. Adding two numbers of type byte they will automatically be promoted to short. What about int? Adding two number of type int together wont result to a long promotion (of course)... Same as int if you try to to add together two float numbers, the result wont be promoted to double. All the above are great... but... There is an interesting behaviour when you do the following the above is perfectly valid, but the bellow results in a compilation error: Yes indeed! an easier one now: Please welcome the infamous Numeric Overflow!

Make your bash script runnable from every directory on the terminal

Have you ever wanted to create a utility like ls for example and make it available from everywhere in the linux's/mac's terminal? There two ways to do that. Way 1 (lets assume that my script is in a file with the name hello.) a.move your script to /bin sudo mv hello /bin/hello b.make your script executable sudo chmod +x /bin/hello you are ready to ramble! Way 2 create a file with different functions and aliases like the example bellow. Lets assume that the file name is .myfunc the file might look like: Now on your home directory find a file called .bashrc . If you are using a different shell (like zsh) the file might be different. For example if you are using zsh you should look for . zshrc . Mind that the file names starting with dot (.) in POSIX systems (like linux and macOs) are hidden files. when you find the file .bashrc, edit it with VI or the editor of your choice and add somewhere (it does not matter where) the line source {path to yo...