Welcome to my blog, fellow developers! Today, we'll embark on a journey into Java programming. Whether you're an advanced developer or a beginner in programming, this article will lay a solid foundation for your Java knowledge. So, let's dive in!
Today, I learned about the basics of the Java programming language, and I will outline the key lessons and implementations of what I learned. We'll discuss:
Java Syntax
Data types
Variables
Type Casting
-
Java Syntax- Every programming language has its unique syntax, and Java is no exception. Understanding the syntax of any programming language is crucial, as it allows us to write code that a computer can understand. In Java, all the code is written inside a class, like
class HelloWorld {}
. The entry point of the code ispublic static void main(String[] args) {}
. When you run the program, the code inside the main method will be executed. For example, let's print "Hello world":
(We use System.out.println()
method to print anything to the console.)
-
Data Types - In Java, there are two types of data types: - primitive
-
non-primitive
Primitive data types are those defined in Java such us
int, String, boolean, float, double
. Non-primitive data types are those that the programmer defines such asArrays, objects, classes, methods
.
-
non-primitive
Primitive data types are those defined in Java such us
Variables - A variable is memory allocation. In other words,storing data in the memory. Here are examples of how to declare a variable in Java:
Good Morning
1977
3.14
5.727
-
Type Casting - This is the changing of the value of a variable from one data type to another. i.e changing from an
int
to adouble
or vice versa. Here's an example of converting anint
to adouble
:
Outputs:
502
502.0
Example of converting a double
to an integer int
:
Outputs:
502.77
502
This is what I managed to grasp on day 1 of learning Java. More will be covered in the next article. I would greatly appreciate your feedback and suggestions regarding this article. If you notice any errors or have any recommendations for improvement, please feel free to share them below. Your input is invaluable in helping me provide accurate and engaging content.
Thank you in advance for taking the time to review the article. I look forward to hearing your thoughts!
Top comments (0)