Hi people, this blog is going to discuss about very basic points and main concepts you must know before using JAVA language. This first article will be helpful for very beginners in JAVA programming. In this tutorial we will learn about:-
- What is JAVA?
- JAVA programming starting points.
- Data types in JAVA.
- Simple HelloWorld program.
- How to run java program in CMD (command prompt).
What is JAVA?
There are several brief definition will be appear when you Google it. Simply java is an object-oriented programming language which has platform independency (it is intended to let application developers WORA-write once, run anywhere). Java is simpler to use and it can be used to create complete application that may run on a single computer or be distributed among servers and clients in a network. Java is developed by Oracle Corporation.
After you install the Java to your computer, you can see two folders inside the Java folder.
- Jdk – Java development kit.
- Jre – Java runtime environment.
- Javac – Java compiler
- Jvm – Java virtual machine
JAVA programming starting points
1.Key words – when we programming in java language we use some words constantly. Those are key words in java.
Ex:- public, class, static, void, abstract, Boolean, try, if, int, new …
- But like String, system, println are not key words. We will discuss about those in future articles.
2.Class name –
- A class name must start with alphabets, underscore (_) or dollar symbol ($).
- Can’t start with digits (1,2…) but can use digits in the middle and end of the name.
- Can’t use space and other symbols (*,/…) in the class name.
- There is standard way to create class names which capitalize starting letter and the first letter of each subsequent word.
- Class name must not be a keyword or reserved word.
3.Variable name –
- Everything apply that we discussed under Class name without the standard way.
- When we declaration a variable name, the standard way is starting letter keep as lowercase letter and capitalize the first letter of each subsequent word.
- If your variable stores a constant value (static final int NUM_GEARS = 6), the convention changes slightly, capitalizing every letter and separating subsequent words with the underscore character.
4.Comments in java –
- Single line comments,
//this is a single line comment
- Multiple line comment (block comment),
is a multiple
line comment */
- Java documentation comment,
*is a java
5.Error types in java –
- Syntax error (compilation error).
- Run time error.
- Logical error – to identify a logical error we need to do test our code and see whether it gives a right output. If it isn’t give the right output it known as logical error.
6.Testing in java –
- Black box testing in
- White box testing
(We will discuss about testing furthermore in future articles.)
7.Debug and dry run –
- Debug – this is a mechanism of finding bugs and errors in our code. In editor we can add some block points and run the code part by part (debugging).
- Dry run – without run the code we just put some inputs by our own and check the output by going through the code known as dry run.
Data types in JAVA
- Data types are divided to two categories.
1.Primitive data type –
- char – one character -16bit
- byte – discrete number – 8bit
- short – discrete number – 16bit
- int – discrete number – 32bit (default data type)
- long – discrete number – 64bit
- float – continuous number- 32bit
- double – continuous number -64bit
- boolean – true/false
Ex:- int literal – 32
char literal – ‘c’
long literal – 32L (use L or l)
doble literal – 25.5
Float literal – 25.5f (use F or f)
- char has some characters to do something else without appearing as a character.
Ex:- ‘\n’ – new line character
‘\t’ – tab space
‘\r’ – return (more)
2.Object / Reference data type – Reference variables are created using defined constructors of the classes. They are used to access objects. (further details in next article -topic Classes & Objects)
- Class objects
- various type of array
Ex:- Animal animal = new Animal(“cat”);
Simple HelloWorld program
Code :- type this code in notepad and save as HelloWorld.java (same as class name )in desktop.
How to run java program in CMD (command prompt)
- follow these steps to set the path to java and run HelloWorld.java file in CMD.
1.go to C drive -> Program files -> Java -> 8.0_65 -> bin -> copy the address .
2.go to Control panel -> System and Security -> System -> Advance system settings -> Environment variables -> click new in top of the window and enter “path” for variable name and paste the copied address to the variable value .
3.then click OK for all windows. open the CMD and set the path to desktop.
4.Type javac HelloWorld.java (file name) and enter. (the java file will be compiled and will be created the HelloWorld.class file).
5.Then type java HelloWorld (class fill will be run and the output will be displayed).
Thank you for reading, leave your questions and suggestions in the comment section below .