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 basics concepts and their application in detail. Let’s get started with our discussion….

Learn 7 Basics of Java Programming to Start Coding Today.jpg

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 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 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 variables.
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 among all the instances of the class. Memory allocation for static variable only once when the class is loaded in the memory.
3) Datatypes: Data types can specify different sizes and values that can be stored in the variable.

Datatypes.jpg

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

Boolean: Boolean hold 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 byte.
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 byte.
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 byte.
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.

a) Arithmetic operators:

b) Assignment operators:

c) Logical operators:

d) Relational operators:

e) Bitwise operators:

f) Unary operators:

g) Ternary operators:

Operators.jpg

a) Arithmetic operators: Arithmetic operators are used to perform arithmetic operations like addition, subtraction, multiplication, and division.

Arithmetic operators.jpg

b) Assignment operator: Assignment operator assigns values to variables.

Assignment operator.jpg

c) Logical operator: Logical operators operates on boolean expressions. They are used in conditional statements and loops for evaluating conditions.

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

d) 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.

Relational operator.jpg

e) Bitwise operators: Bitwise operators are used in Java that operates on bits and performs the bit-by-bit operation.

Bitwise operator.jpg

f) Unary operators: Unary operators are used to perform the operation on only one operand.

Unary operators.jpg

g) Ternary operators: Java ternary operator consists of three operands and it is used to evaluate Boolean expressions.

h) Shift operators: There are two shift operators in Java. They are

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.
Right shift operators: The Right shift operator >> is used for moving the left operands value to 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:

a) Single dimension array: It is a list of variables of the same type that can be accessed by a common name.

b) Multi dimension array: It is a type of array where data is stored in matrix form.

6) Loops:

While writing programs sometimes you 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 several types of loop statements to handle looping requirements.

Loops1.jpg

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 these basics.

Question for you: Which basics from today’s post are you going to master first OR maybe you would like to add anything 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.

Next related article to 3 Components of Java Programming Language

Author's Bio: 

Simpliv LLC, is a platform for learning and teaching online courses. We offer a rich variety of educational courses that have been prepared by authors, educators, coaches, and business leaders. Whether you're interested in healthy living, nutrition, natural healing, computer programming, or learning a new language, you'll find it here