Monday, August 31, 2015

Data Types In Java



Hi All...!

Today I'm going to show you what are the "Data Type" we can use in Java programming, In Java there are two types of data types. One is "Primitive Types" or "8 Basics" and other type is "An Unlimited Number Of Object Type"


Primitive Types Or 8 Basics


Following 8 data types are known as primitive types or 8 basics,

  1. byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. char
  8. boolean

Note


When we type any of above data type in our Java program we must use only simple letters.



Unlimited Number Of Object Types (Non - Primitive)


For this type "String" is a good example. You will get to know about these data type in future.



8 Basics Or Primitive Data Types Chart




In my next post I will show you how to use these data types in Java programs.

Sunday, August 30, 2015

How To Declare A Variable In Java

Hi All...!

Today I'm going to show you how to declare a variable in Java. Following format is the common way to declare a variable in Java,

(Data Type)(Space)(Variable Name);


For a example,

int x;


Here "int" is the datatype (I will show you what are the datatype in Java in my upcoming posts) and the "x" is the variable name.

Variables

Hi All,

In this post I'm going to teach you about "Variables", Let's take a look at "What is a Variable",

Variable is a container that stores a meaningful value that can be used throughout a program.Variables store this values or information in computer's memory. That vales or information can be change all throughout a program.

Variables can store different types of data, One variable in your program can store numeric data while another variable can store text data.

In my next post I will show you how to declare a variable in Java


Common Escape Sequence In Use

Hi All...!

Today I'm going to show you how to use some commonly used escape sequence in Java program.

Let's take a look at what are the commonly used escape sequences,

"\n" newline character 


This escape sequence use to move cursor to the beginning of the next line,

Let's see how to use this escape sequence,



And this is the output,





Let's try this code with "print",



then the output,




"\t" Horizontal Tab


By using this escape sequence we can move cursor to right with tab space,

Let's use this in code,




Output,






"\r" Carriage return



By using this escape sequence we can position cursor at the beginning of a line and the text before this escape sequence will overwrite with text after the escape sequence,

Let's try this in code,





This is the output,





"\\ Backslash"


Use to print backslash,

Let's see how to use this,




Output,




" \" " Double Quote



Use to print double quotes, Let's see the code,






Output,



Sunday, August 23, 2015

Escape Character & Escape Sequence

Hi All...!

This post is about "escape character" and "Escape Sequence", Let's take a look at what is escape character,

escape character

 

Normally, the characters in a string are display exactly as they appear in the double quotes, when we use System.out's print and println methods. I think you have notice that when we use nextline character, "\n" didn't print on command window, that's because of this escape character in front of the newline command, escape character is "\" Backslash. If you use backslash the next character after the backslash will not display when you run your program. But you can't randomly use backslash to stop printing characters. If you use backslash randomly with out any knowledge you will get compilation error, that says "Illegal escape character".

Correct way to use escape character 

The correct way to use escape character is, use escape character with "Escape Sequence".

Following picture shows you list of a "Escape Sequence" used in Java.




In my next post I will show you how to use some common "Escape Sequence".

Saturday, August 22, 2015

Displaying Multiple Lines Of Text Using Single Print Statement

Hi All...!

Today I'm going to show you how to "Displaying Multiple Lines Of Text Using Single Print Statement ", to do this task we need to use "newline character".

newline character "\n"


newline character use to tell the System.out's print and println methods to when they have to move the cursor to the next line of the command window.

Note


"newline character" is also a white-space character like "blank lines", "space characters" and "tab characters",


Let's see how to use "newline character" in Java program with print method.




Here is the out put,




Now use "newline character" with println method.

Here is the code,


This is the out put,

Thursday, August 20, 2015

Print And Println

Hi All...!

Today I'm going to show you how print a line of text using Java program. To do this task I'm going to use "System" class in Java and it's field call "out" and also println and print methods from PrintStream class.Don't worry about those class, field and methods, you will get to know about them as you go through this blog.

println 


This method is use to print line of text and move cursor to the next line.

Following code is an example for how to use println method in Java


This is the out put of that program.



Let's print two lines using this method, just copy and paste the System.out.println.....line


Let's see the out put,


Now you can clearly see the cursor have moved to the next line after printing the line of text.


print


This method is also use to print line of text, but there is difference between the println and print methods print method does not move the cursor to the next line.

Following code is a example code for print method.






This is the out put,






Let's use print method twice,

This is the code,




And this is the out put,




Wednesday, August 19, 2015

Good Programming Practice Post 2

Hi All...!

I'm going to show you another "Good Programming Practice". It's better to get a knowledge about "Good Programming Practices" before you start your programming moves.

If you type "Curly Braces" to mark scope of a class, scope of a method or scope of a any type of block, you have to leave a "One Line" and the keep writing your code.

When you get to the line after the blank line you have to keep "Tab" or "Three Spaces" from "Left Margin" and start writing your code.

Following code is an example for these "Good Programming Practice" Tips,





By using these "Tab" or "Three Spaces" we can get simple idea about what is inside the class,method or block scope.



Tuesday, August 18, 2015

Good Programming Practice Post 1

Hi All...!

Today I'm going to show you some "Good Programming Practices" for Java programming.


Tip 1


When you write a Java program, you can begin that program with multiple line comment that tells about the program,

  • Purpose of the program.
  • Author (Programmer who write the program).
  • Date and Time when the program was last modified.

For a example look at the following Java code


Tip 2


Use White-spaces to make your code easy to read (enhance readability).

For a example look at the following Java codes




Monday, August 17, 2015

White Spaces

Hi All...!

This post is about White Spaces,

White Spaces are the Blank lines,Tabs and Space Characters in the Java code. They make programs easier to read.

White Space is ignored by compiler so they will not make an effect to Java Program.

Let's take a look at Java programs that have and have not White Spaces in it,

Following code don't have White Spaces,


Following code have White Spaces,





Java Comments

Hi All...!

This post is about Java Comments, commenting makes your code easy to read and easy to understand, The Java compiler ignores comments, so they do not cause the computer to perform any action when the program is run.

There are two types of Java comments commonly in use among Java programmers,

1) Single Line Comment

Single line comments begins with two forward slashes  "//".

Following example shows how to use Java single line comments in source code.





Let's take a look at what will happen when we compile and run this commented code.





That code runs normally, as I told you earlier Java compiler simply ignores comments.


2) Traditional Comment (Multiple Lines Comment)

This traditional comments begins with the forward slash and asterix symbol and ends with asterix symbol and forward slash.

Let's take a look how to use this multiple line comments in Java program


Let's compile and run that program,


It's run normally because compiler ignores comments.

Hello World Program With Geany IDE

Hi All...!

Today I'm going to show you how to create a simple "Hello World...!" program using Geany IDE.

Following is the video of the hello world code.


Step 1 (Open Geany IDE)


Open your Geany IDE it will look like the following picture as you open your Geany IDE for the first time.





Step 2 (Create a new file on Geany)


Click On "New" and open a new file




Step 3 (Save created file)


Save newly open "Untitled" file as "Demo.java"



Go to desktop, create a new folder, name it as "My Java Program"



Go inside that folder, Type name as "Demo.java" and click "save"


Step 4


Then it will look like this




Step 5 (Write "Hello World...!" on Geany)


Now you can start writing your Java program on "Demo.java" file,




Write actually same code as I have shown above  


Step 6 (Compile and Run "Hello World...!" using Geany)


To compile our code we can click on the "Compile" button or you can press "F8" key







 After you compile your code, Geany IDE will show you a message,

If your code compiles correctly,



If your code has some errors,




( If you guys can find the error please comment it below ).

If your code compiles successfully, now you can run your program, to run your program again you can click on the "Run" button or you can press the "F5" key.





After you run your compiled code Terminal will open and run your code,