Hello everybody 🙋♂️
Today I've met some excellent articles and I'm happy to share them with you.
https://catonmat.net/bash-one-liners-explained-part-one - working with files
https://catonmat.net/bash-one-liners-explained-part-two - working with strings
https://catonmat.net/bash-one-liners-explained-part-three - this one made my day 😍 It's about redirections of input/output
We believe that almost every developer should be in close acquaintance with bash. If you didn't read https://t.me/yajc_java/9 yet, don't waste your time and get to it as soon as possible.
In one of the coming articles we'll mix user input and file redirections to process file with a Java program.
#beginner #bash #linux
Today I've met some excellent articles and I'm happy to share them with you.
https://catonmat.net/bash-one-liners-explained-part-one - working with files
https://catonmat.net/bash-one-liners-explained-part-two - working with strings
https://catonmat.net/bash-one-liners-explained-part-three - this one made my day 😍 It's about redirections of input/output
We believe that almost every developer should be in close acquaintance with bash. If you didn't read https://t.me/yajc_java/9 yet, don't waste your time and get to it as soon as possible.
In one of the coming articles we'll mix user input and file redirections to process file with a Java program.
#beginner #bash #linux
catonmat.net
Bash One-Liners Explained, Part I: Working with files
I love being super fast in the shell so I decided to do a new article series called Bash One-Liners Explained. It's going to be similar to my other article series - Awk One-Liners Explained, Sed One-Liners Explained, and Perl One-Liners Explained. After I'm…
Hello everybody! I've just explored a cool web application: https://hyperskill.org/
It's a web app developed by JetBrains which creates the best IDE for Java: Intellij IDEA.
The learning path is project based and you study topics which are building blocks for the project.
Unfortunately Java is not free but Kotlin is. If you wanted to learn Kotlin I hope it's a good way to do it. Anyway they will give you some trial period and you can learn Java for that period.
If you would like to try it use my join link please: https://hyperskill.org/join/e95f20c89
It's a web app developed by JetBrains which creates the best IDE for Java: Intellij IDEA.
The learning path is project based and you study topics which are building blocks for the project.
Unfortunately Java is not free but Kotlin is. If you wanted to learn Kotlin I hope it's a good way to do it. Anyway they will give you some trial period and you can learn Java for that period.
If you would like to try it use my join link please: https://hyperskill.org/join/e95f20c89
🔥2
The great article about essential Linux commands. Get to it to be a more confident user of Linux terminal.
https://maker.pro/linux/tutorial/basic-linux-commands-for-beginners
https://maker.pro/linux/tutorial/basic-linux-commands-for-beginners
Maker Pro
Basic Linux Commands for Beginners | Linux
Learn basic commands for Linux, a free and open-source operating system that you can make changes to and redistribute.
Let's solve something fundamental and easy: https://telegra.ph/Reverse-a-word-01-29
Any feedback is appreciated
#java #beginner
Any feedback is appreciated
#java #beginner
Telegraph
Reverse a word
Hello! 👋 In this short post we will solve a typical task in programming which is given to every beginner. Task You are given a word, you need to reverse it.Examples: word → drow; radar → radar; sequence → ecneuqes; Solution There are many possible solutions…
We always say Linux is a great tool for almost any developer. Here is another video how to improve your terminal experience: https://youtu.be/AVXYq8aL47Q
YouTube
18 Commands That Will Change The Way You Use Linux Forever
New to Cloud Computing? Get started here with a $100 credit → https://www.linode.com/lp/youtube-viewers/?utm_source=youtube&utm_medium=dev_advocacy&utm_content=18cmnds_jl_03_02_22
When it comes to using Linux, there's usually a few ways to accomplish a task.…
When it comes to using Linux, there's usually a few ways to accomplish a task.…
🔥2
While we are preparing an article about Maven try to solve another quiz.
What does this code print?
What does this code print?
Anonymous Quiz
15%
-3
15%
-1
0%
0
5%
1
65%
3
We're not converting to a Linux channel 😁 but you need to know these commands
https://www.hostinger.com/tutorials/linux-commands
#linux #bash
https://www.hostinger.com/tutorials/linux-commands
#linux #bash
Hostinger Tutorials
60 essential Linux commands
60 most commonly used Linux commands: 1. ls command · 2. pwd command · 3. cd command · 4. mkdir command · 5. rmdir command · 6. rm command + more.
❤1👍1
Hello! Let me introduce you a brilliant feature that will enhance your enjoyment of learning Java.
https://telegra.ph/Single-Source-File-Java-Programs-04-23
https://telegra.ph/Single-Source-File-Java-Programs-04-23
Telegraph
Single Source File Java Programs
As we already know, Java is a versatile and powerful programming language that is widely used for developing complex software applications. One of the features of Java is that you can write and run programs using a single file without the need to compile…
👍1👨💻1
Hey 👋
In order to start with Maven we need to learn some basic topics. It’s time for you to choose the next!
Welcome to the chat to discuss what each topic is.
In order to start with Maven we need to learn some basic topics. It’s time for you to choose the next!
Welcome to the chat to discuss what each topic is.
👍1
What is the next topic
Anonymous Poll
64%
Testing Framework
27%
Application distribution
9%
External libraries
👍1🔥1
What is the value of Math.abs(Integer.MIN_VALUE)
Anonymous Quiz
22%
0
44%
-2147483648
0%
-2147483647
0%
2147483648
11%
2147483647
22%
Exception
Why Math.abs(Integer.MIN_VALUE) equals Integer.MIN_VALUE in Java ☕️
In Java, we often use the
However, an interesting trick happens when you apply
In Java, an int is a 32-bit signed integer, which means it can represent values defined as:
Notice that the absolute value of
Why Does This Happen?
Here's what happens under the hood when you try to get the absolute value of
1. Two's Complement Representation (wiki https://en.wikipedia.org/wiki/Two%27s_complement): Java uses two's complement to represent signed integers. In this system, the negative of a number is formed by flipping its bits and adding 1. However, in the case of
2. Overflow: When applying
In other words it’s similar to
3. Special Case in Java: Java's
Explanation Through Bit Representation
To better understand this behavior, let's examine the binary representation of
10000000 00000000 00000000 00000000
(the leftmost 1 indicates that the number is negative in two's complement).
Negating this value in two's complement results in an overflow back to the same number because no positive counterpart exists within the 32-bit int range.
Conclusion
The reason
#java #beginner
In Java, we often use the
Math.abs()
function to calculate the absolute value of a number. It’s supposed to return the positive equivalent of any number by stripping away its negative sign.However, an interesting trick happens when you apply
Math.abs()
to Integer.MIN_VALUE
. Surprisingly, it returns Integer.MIN_VALUE
itself, not its positive counterpart. Let’s explore why.In Java, an int is a 32-bit signed integer, which means it can represent values defined as:
Integer.MIN_VALUE = -2,147,483,648
Integer.MAX_VALUE = 2,147,483,647
Notice that the absolute value of
Integer.MIN_VALUE
would theoretically be 2,147,483,648, which is one greater than Integer.MAX_VALUE
. But Java's int type cannot represent numbers larger than Integer.MAX_VALUE
. This creates a situation where the positive equivalent of Integer.MIN_VALUE
doesn't exist within the int range.Why Does This Happen?
Here's what happens under the hood when you try to get the absolute value of
Integer.MIN_VALUE
1. Two's Complement Representation (wiki https://en.wikipedia.org/wiki/Two%27s_complement): Java uses two's complement to represent signed integers. In this system, the negative of a number is formed by flipping its bits and adding 1. However, in the case of
Integer.MIN_VALUE
, there’s no positive equivalent because of how two’s complement works. The range for negative values is slightly larger than for positive values.2. Overflow: When applying
Math.abs()
to Integer.MIN_VALUE
, the function tries to negate the value. Negating Integer.MIN_VALUE
would result in 2,147,483,648, which is beyond the representable range of the int type. As a result, the value overflows and remains Integer.MIN_VALUE
.In other words it’s similar to
Integer.MAX_VALUE + 1
wichi is equal to Integer.MIN_VALUE
.3. Special Case in Java: Java's
Math.abs()
function doesn’t throw an error in this situation but recognizes that the result is out of bounds and simply returns Integer.MIN_VALUE
.Explanation Through Bit Representation
To better understand this behavior, let's examine the binary representation of
Integer.MIN_VALUE
:Integer.MIN_VALUE
in binary:10000000 00000000 00000000 00000000
(the leftmost 1 indicates that the number is negative in two's complement).
Negating this value in two's complement results in an overflow back to the same number because no positive counterpart exists within the 32-bit int range.
Conclusion
The reason
Math.abs(Integer.MIN_VALUE)
equals Integer.MIN_VALUE
is due to Java’s use of two's complement arithmetic and the limitations of the int data type. Because Integer.MIN_VALUE
has no positive counterpart in the int range, applying Math.abs()
to it causes an overflow, returning the same negative value. This behavior is a consequence of how integers are represented and negated in binary.#java #beginner