Tuesday, October 4, 2016

Assignment Operator in Java

Hi All...!

Today I'm going to teach you about assignment operator, symbol of the assignment operator is " = ". We use this operator to assign the value on it's right to the operand on it's left

Ex: int x = 0 ; (value 0 assign to x)


Monday, May 16, 2016

Operators Evaluation From Left To Right & Right To Left

Hi All...!

Today I'm going to talk about "Operators Evaluation From Left To Right & Right To Left",
Let's see what it is,

All binary operators except for the assignment operators are evaluated from left to right, assignment operators are evaluated right to left.


Note
Binary Operators are the operators which has two operands in it's both sides.
Ex: 1 + 2  (+ mark has two operands in it's both left and right so + mark is a Binary Operator)


Let's go to today's topic,
All binary operators are evaluated from left to right except assignment operator 
(assignment operator is " = ").

Ex: 1+2 operates in this way 1 adding to 2

Assignment operator evaluate from right to left.

Ex: x = 1 operates 1 is assigning to x 
Let's see how following operation is evaluated

Ex: x = 1 + 2 operates in this way 1 adding to 2 then the result of that assigning to x

In there Black arrow take place in first, Then Red arrow happens.

See you soon...Bye

Wednesday, May 4, 2016

Java Operators

Hi All...!

Now we know how to declare variables and how to initialize them, today I'm going to teach you how to operate those variables to do meaningful stuff. Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.

 
Note
1+2 here the 1 and 2 are the operands and + sign is the operator.

The operators in the following table are listed according to precedence order. The closer to the top of the table an operator appears, the higher its precedence. Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right, assignment operators are evaluated right to left.  


Operator Precedence
Operators
Precedence
postfix
expr++ expr--
unary
++expr --expr +expr -expr ~ !
multiplicative
* / %
additive
+ -
shift
<< >> >>>
relational
< > <= >= instanceof
equality
== !=
bitwise AND
&
bitwise exclusive OR
^
bitwise inclusive OR
|
logical AND
&&
logical OR
||
ternary
? :
assignment
= += -= *= /= %= &= ^= |= <<= >>= >>>=


From the next post I'm going to teach you guys each and every operator and how to use it until then Bye....!

Thursday, February 18, 2016

Java Identifiers Part 2

Hi All...!

Today post is about the regulations we have to follow when we creating a Java Identifiers, this is not a must to follow if we follow these regulations we can create easy to read codes and quality code.

Let's see what are these regulations,

1) class names

class names must start with capital letters and if class name have more than one word each words' first letter must be capitalize.

ex: NewClass, MyClass

2) Interface names

Same as the class names

3) package names

all letters in package name must be simple

ex: newpackage, homepackage

4) method names

Method names must follow camel case, that means all letters in the first word must be simple and if there are more than one word for the name all words after first word must capitalize it's first letter.

ex: printBill, selectLetter

5) variable names

Same as the method names.

6) constant names

All letters must be capitalize and if name contain more than one word those words must connect by using underscore "_".

ex: MAX_VALUE, MAX_HEIGHT

Tuesday, February 2, 2016

Java Identifiers Part 1

Hi All...!

To I'm going to teach you guys what are the Java Identifiers, Java Identifiers are names of Java classes, interfaces, variables, methods, packages, objects and constants.

There is some rules and regulations to follow when we create names (Identifiers). If we break those rules it will cause to compilation errors but if we don't follow the regulations it will make our code difficult to read and also difficult to maintain and modify.

Let's take a look at what are those rules we must follow when creating a Identifier.

  1. We can't use spaces in Java identifiers.
  2. We can't use spacial characters like !@#%^&*() in Java identifiers. 
  3. We can't use Java Key-words as identifiers.(you can find Key-word chart bellow)
  4. We can only use a letter, _, $ to start identifier.
  5. After we start a identifier by using a letter, _, $ we can use any combinations of letters, _, $ and NUMBERS
If we follow above rule we can create a legal identifiers.



Let's take a look at some examples,


Sunday, January 31, 2016

Local variable, Global variable (Instance variables) & Class (static variables) Part 3

Hi All...!

This post going to be the last post about Local, Global & Class variables, and in this post I'm going to teach you guys what are the Class Variables (static variables). Class or static variables are the variables which we declare using static key-word. For this lesson just don't worry about what is the static key-word is, we will cover these topics in upcoming lessons.

For now just keep it in mind whenever we declare a variable using static key-word, we can access that variable just only using class name with out creating objects.

I will recap this lesson after we learn about Object Oriented Programming.

Wednesday, January 27, 2016

Local variable, Global variable (Instance variables) & Class (static variables) Part 2

Hi All...!

Let's learn about Global variables,

Global variables are the variables that we declare inside the class but outside the method, and that variable can use through out the program scope, that means you can use that variable in any method of that class.

Let's use global variable in a program,

Here I'm going to static key word to declare the variable because we are about to use the variable we create in side the main method, main method is a static method so we can't use non-static things inside the static one without creating a object. As we don't know about the Object Oriented Programming yet just follow the code and get the idea of Global Variable.








Tuesday, January 26, 2016

Local variable, Global variable (Instance variables) & Class (static variables)

Hi All...!

Today I'm going to teach about forms of variables, There are 3 types of variables we have to deal with commonly, those are  Local variable, Global variable (Instance variables) & Class (static variables).

Local Variables


Local Variable are the variables that we declare in side the method scope. These variables are born, live and die inside the method.

We can't access these variables from outside the method.

Let's use this local variables in a program,


We can't use local variables outside the method scope







Friday, January 22, 2016

Java Data Type Conversion

Hi All...!

Today I'm going to teach you what is Java Data Type Conversion and how to use this concept in your programs.

Java data type conversion enables conversion of small size data types' variables to large size data types' variables.

To make this concept easy to understand, think byte, short, char, int, long, float, double are water buckets.


Now you can see that things in byte can put into short with out any trouble. Like wise short can put into int and also char can put into int as well, like wise int can put into long, long can put into float, float can put into double.

Let's do some coding to understand this properly,










Sunday, January 17, 2016

Casting part 4 (Final Casting Lesson)

Hi All...!

This is my last post about the Casting cause I think now you guys can manage casting part in Java program. Up to this I have shown you how to cast "int" data type variables in to "byte", "short" and ''long" data type variables in to "int". Today I'm going to teach you how to cast "double" in to "float".

Following is the code,


In my next post I will teach you about the data type conversion.