I'm tossing around the idea of writing and publishing a book on the Amazon Kindle platform about Java or Python. The name of the book would be something like "Basic and Simple Programming with Java" or "Learn to code with Python".
I would probably start with a chapter on how to set up an IDE, and have the book cover the basics such as variables, strings, conditionals, etc. using code examples. A simple example would be like
String name = "Sally";
Python states that "Python is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use", so I assume the answer is yes for Python.
Java seems more legally complicated and I can't find anywhere if writing and publishing a book using and citing Java code is legally allowed.
Am I allowed to commercially publish and use samples of different coding languages in a book?