Member-only story

From Python To Java (Part 2) — If Else Loops

Liu Zuo Lin
3 min readDec 12, 2021

--

This series of articles is written for those of you who are somewhat comfortable in Python, and are looking to pick up some Java. In this article, we’ll run through the difference in writing if-else loops in Python and in Java.

Relational Operators

Relational operators (equals, greater than etc) are the same in Python and Java

Both Python & Java

  • == → equals
  • > → more than
  • < → less than
  • >= → more than or equals to
  • <= → less than or equals to
  • != → not equals to

Primitive Data Types vs Objects

Java has 2 types of data types — primitive data types and objects:

  • Primitive data types → byte, short, int, long, float, double, boolean, char
  • Objects → everything else eg. String, List etc

Note that the relational operators in Java works well only for primitive data types, but not for objects.

int a = 5;
int b = 5;
a == b // this will return true

Using .equals instead of == for Objects

--

--

Liu Zuo Lin
Liu Zuo Lin

Written by Liu Zuo Lin

SWE @ Meta | [Ebook] 101 Things I Never Knew About Python: https://payhip.com/b/vywcf

No responses yet