Learn 7 Basics of Java Programming to Start Coding Today

In this post, I will cover 7 basics of Java Programming to help you start coding in Java today. Before going ahead, I would recommend you go through our blog on How to Learn Java from Scratch, which ensures you have a clear learning roadmap in your mind.

I probably don’t need to tell you that without mastering basics in Java or any programming language, you cannot do coding efficiently.

Whether you are a recent graduate who is looking to learn a major programming language like Java or an experienced programmer who wants to increase the potential for future career growth, having a solid knowledge of basic concepts of Java is must.  Java is an easy programming language for one who has paid attention to the basics, however, it can be equally frustrating for one who tries to take the shortcut.

If any of the above points sounds familiar, I have a great news: There are 7 basics concepts of Java which can help you to start coding better right today. You can also find a list of Java online courses which will cover these basic concepts and their application in detail. Let’s get started with our discussion….

Fundamental concepts of Java

We will cover 7 Java Coding basics elements in the following manner:

  • Basic Program Syntax

  • Variables

  • Datatypes

  • Operators

  • Arrays

  • Loops

  • Conditional Statements

Let’s get started with the first basic. Let us consider a basic sample program in Java, “Hello World” program.

1. Basic Program Syntax:

public class MyfirstJavaProgram{
public static void main(String[]args)
{
System.out.println(“Hello World”);
}
}

Let’s see some basic syntax to write this program:

  • Case sensitivity: Java is case sensitive. Here, upper case letters and lower case letters are treated completely different.
  • Class name: For all class names the first letter should be in upper case.  If several words are used in class name, each inner word should start with upper case letter. For example, in the above program, the class name is MyFirstJavaProgram.
  • Method name: Each method name should start with a lower case letter. If more words are included in Method name, then each word should start with Upper case word. For example, method name: Public void myMethodName().
  • System.out.println(): It is used as a print statement. System is the class, out is the object PrintStream class, println() is the method of PrintStream class.

2. Variables:
A variable is used to store the data value. These are associated with data types. There are different types of variables as discussed below:

  • Local variable: A variable that is declared inside the body of the method is called as local variables.
  • Instance variable: A variable declared inside the class but outside the body of the method, is called instance variable.
  • Static variable: A variable which is declared as static is called static variable. A static variable cannot be local. It is not possible to create a single copy of the static variable and share it among all the instances of the class. Memory allocation for static variable is made only once when the class is loaded in the memory.

3. Data types:
Data types can specify different sizes and values that can be stored in the variable.

Different Data types present in Java

a. Primitive data types: There are totally eight primitive data types present in Java. These are:

  • Boolean: Boolean holds either true or false information. The default value is false.
  • Char: Char is used to store any character. The default value is ‘\0000’. The default size is 2 bytes.
  • Byte: Byte can hold the numbers in the range of -128 to 127. The default value is 0. The default size is 1 byte.
  • Short: Short can hold the numbers in the range of -32,768 to 32767. The default value is 0. The default size is 2 bytes.
  • Int: Int can hold the numbers in the range of -2,147,483,648 to 2,147,483,647. The default value is 0. The default size is 4 bytes.
  • Long: Long can hold the numbers in the range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The default value is 0L. The default size is 8 bytes.
  • Float: Float is mainly used to save memory in large arrays of floating point numbers. The default value is 0.0f. The default size is 4 bytes.
  • Double: Double is generally used as the default data type for decimal values, generally the default choice. The default value is 0.0d. The default size is 8 bytes.

b. Non-primitive data types: Non-primitive data types include Classes, Interfaces and Arrays.

4. Operators:
Java provides a rich set of operators. An operator is a character that represents an action. Let us see some of the different operators in Java:

  • Arithmetic operators
  • Assignment operators
  • Logical operators
  • Relational operators
  • Bitwise operators
  • Unary operators
  • Ternary operators.
Different Operators present in Java
  • Arithmetic operators: Arithmetic operators are used to perform arithmetic operations like addition, subtraction, multiplication, and division.
Operator Description
+ Performs additional function
Performs subtraction function
* Performs multiplication function
/ Performs divisional function
% It acts as a reminder function
  • Assignment operator: Assignment operator assigns values to variables.
Operator Description
= It assigns values from right side operator to the left side operator
+= It is add AND assignment operator. It adds value of right side operand to the value of left operand and assigns the result to left operand
-= It is subtract AND assignment operator. It subtracts the value of the right side operator from left side operator and assigns the result to the left operand
*= It is multiple AND assignment operator. It multiplies the value of the right operator with the value of left operator and assigns the result to the left operand
/= Divide AND assignment operator. It divides the value of the left operator with the value of the right operator and assigns the result to the left operand
%= Modulus AND assignment operator. It takes the modulus using two operands and assigns the result to left operand
<<= It is left shift AND assignment operator
>>= It is right shift AND assignment operator
&= It is bitwise AND assignment operator
^= It is bitwise exclusive OR and assignment operator
|= It is a bitwise inclusive OR and assignment operator
  • Logical operator: Logical operators operate on boolean expressions. They are used in conditional statements and loops for evaluating conditions.

Logical operators in Java are &&, ||, !.

  • Relational operator: Relational operator determines the relationship between two operands. It checks whether the operands are greater than, less than, equal to and not equal to, etc.

Below table shows the relations between the two operands.

                       Operator                  Description
                            ==                     Equal to
                            !=                 Not equal to
                             >                 Greater than
                            <                    Less than
                           >=         Greater than or equal to
                           <=            Less than or equal to
  • Bitwise operators: Bitwise operators are used in Java that operates on bits and performs the bit-by-bit operation.
Operator Description
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise compliment
<<  Left shift
>>  Right shift
>>>  Unsigned right shift
  • Unary operators: Unary operators are used to perform the operation on only one operand.
Operator Description
+ Unary plus
Unary minus
++ Increment operator
Decrement operator
! Logical complement operator
  • Ternary operators: Java ternary operator consists of three operands and it is used to evaluate Boolean expressions.
  • Shift operators: There are two shift operators in Java. They are:
    1. Left shift operators: The left shift operator << is used for shifting all the bits in a value to the left side of a specified number of times.
    2. Right shift operators: The Right shift operator >> is used for moving the left operands value to the right by the number of bits specified by the right operand.

5. Arrays: It is a common type of data structure which is a collection of similar type of elements that have a contiguous memory location.

Types of Arrays in Java:

  1. Single dimension array: It is a list of variables of the same type that can be accessed by a common name.
  2. Multi dimension array: It is a type of array where data is stored in matrix form.

6. Loops:

Different Loops statements present in Java

While writing programs, you sometimes need to execute a block of code multiple times in order to get the desired result. In such cases, loop statements allow to execute statements or group of statements multiple times which allows to build the software application efficiently. Java comes with several types of loop statements to handle looping requirements.

Loop Description
While loop While loop repeats a statement or a group of statements while a given condition is true. Before executing the loop body, it tests the condition
for loop For loop executes a sequence of statements several times which allow you to manage the loop variable
do while loop It works like do while loop, but it tests the condition at the end of the loop body.

7. Conditional Statements:

Conditionals Statements are used to execute a set of statements based on certain conditions. Some of the conditional statements are:

  • If statements: The if statements execute a certain section of code only if a test evaluates to true
  • Nested if statements: The nested if statements consist of an if statements inside another if statements.
  • If else statements: Here in if else statements if the condition is true, then the section that comes under if would execute else the section of code under else would execute
  • If else if statements: If else if statement is used to check when there is a need to check the multiple conditions
  • Switch statements: When the number of choices is more, and we may need to perform a different task for each choice then switch statements are used.

Conclusion

There are plenty of online Java courses right here at Simpliv which can help you to master the basics of Java programming language.

Question for you: Which basics from today’s post are you going to master first? Or, is there something you would like to add to the above list?

Either way, let me know by leaving a comment right below and do share the post on social media if you have enjoyed reading it.

Recommended blogs for you

40 COMMENTS

  1. I have been exploring for a little for any high quality articles or weblog posts in this kind of house . Exploring in Yahoo I ultimately stumbled upon this website. Reading this information So i’m happy to convey that I have a very excellent uncanny feeling I discovered exactly what I needed. I most for sure will make certain to don’t disregard this website and give it a look regularly.

  2. fantastic post, very informative. I ponder why the other experts of this sector do not realize this. You should continue your writing. I’m confident, you have a huge readers’ base already!

  3. What i do not understood is actually how you are not really much more well-liked than you might be now. You are very intelligent. You realize therefore significantly relating to this subject, produced me personally consider it from a lot of varied angles. Its like women and men aren’t fascinated unless it is one thing to do with Lady gaga! Your own stuffs great. Always maintain it up!

  4. Good day! I know this is kind of off topic but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having trouble finding one? Thanks a lot!

  5. An fascinating dialogue is worth comment. I think that you need to write extra on this subject, it might not be a taboo subject but usually individuals are not sufficient to speak on such topics. To the next. Cheers

  6. you are really a good webmaster. The web site loading speed is amazing. It seems that you are doing any unique trick. Also, The contents are masterwork. you’ve done a excellent job on this topic!

  7. Thanks for the sensible critique. Me & my neighbor were just preparing to do a little research about this. We got a grab a book from our local library but I think I learned more clear from this post. I am very glad to see such fantastic information being shared freely out there.

  8. Hello! I’ve been following your website ffor a
    long time now and finally got thhe bravery to go ahead and give you a shout out from Neew Caney Texas!

    Just wanted to say keep up the good work!

  9. After study a few of the blog posts on your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls check out my web site as well and let me know what you think.

  10. I have not checked in here for some time because I thought it was getting boring, but the last few posts are great quality so I guess I will add you back to my daily bloglist. You deserve it my friend 🙂

  11. Simply desire to say your article is as amazing. The clearness in your publish is just spectacular and that i can think you’re knowledgeable on this subject. Well together with your permission allow me to seize your RSS feed to keep updated with forthcoming post. Thanks 1,000,000 and please keep up the enjoyable work.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Pin It on Pinterest