java is a case sensitive language, that means there is a seperate recognization for uppercase letters and lower case letters.
Exampleabcis not equal to ABC(ABC != abc).
java has the following naming conventions, they are
all classes, abstract classes, and interfaces Names must be started with uppercase letters and their subsequent symbols must be uppercase letters.
Example:
String
StringBuffer
all variables must be started with lowercase letters and subsequent symbols must be uppercase letters.
Example:
nameIsZaheer
all methods must be started with lowercase letters and subsequent symbols must be uppercase letters.
Example:
additionWithTwoParameters()
additionWithThreeParameters()
all constant variables must be in uppercase letters only.
Example:
GLOBAL_VARIABLE
All the package names must be in lowercase letters.
Example:
com.zaheerintrovert.javanamingconventions
Scanner class is used to read data from keyboard, and it is from util package.
below program "addition of two numbers"
package basics;
import java.util.Scanner;
public class readFromKeyboard {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int FirstNumber;
int SecondNumber;
int Result;
System.out.println("enter first number");
FirstNumber = read.nextInt();
System.out.println("enter second number");
SecondNumber = read.nextInt();
Result = FirstNumber + SecondNumber;
System.out.println("the result is " + Result);
}
}
note:
To know the methods present in that scanner class we have the command javap java.util.Scanner
To check it open the command prompt and enter the command, then you will get the list of methods present in the scanner Class.
Some of the methods are listed below
nextInt()
nextFloat()
nextDouble()
next()
nextLine()
nextBoolean()
nextByte()
nextShort()
nextLong()
etc...for learn java programming we required JDK
JDKthat is java development kit used for compiling java programs or debugging etc... it consists of compiler and other tools along with JRE
Once we compiled the program we need to execute it for that we need JREjava runtime environment which is the part of jdk.
JRE it contains class libraries along with JVM.
JVM it is java virtual machine, its a part of JRE.
you can imagine like JDK is for developing and JRE for executing and for executing we required JVM which is the part of the JRE.
JVM will execute the programs
Example:
HelloWorld.java it is a our program file.
Now, we will compile the file using the command javac HelloWorld.java
note: javac is a part of JDK, aftering compiling the program file we get the .class i.e HelloWorld.class
Now, for running this .class file i.e HelloWorld.class we have the command java HelloWorld, helloworld is the file name.
java command is nothing but jvm which is the part of JRE therefore JDK will compile and JRE will execute the program.
its better to download the latest version. you can download the required version from the above link.
install the java into your machine.
and now check the version of the java by running the following command in the command prompt java -version
If you get the version then congratulations you have successfully downloaded the java into your machine and have already set the path.
If you doesn't get the java version and instead of version if you the message like java is not recognized as internal or external command,operable program or batch file then you need to set the path.
To set the path follow the below procedure...
we can set the path as local as well as global. the advantage of setting the path as global is we can able to use it from any location from the machine.
To set the path as local, open the command prompt set the path by running the command set path=C:\Program Files\Java\jdk-11.0.14\bin;%path%;
In my case the java is located at this location. C:\Program Files\Java\jdk-11.0.14\bin and %path% is for not to delete the other paths which have already set by default or by manually.
copy the java path in my case C:\Program Files\Java\jdk-11.0.14\bin now open control panel and click on system and security
now click on the advanced system settings then you will find the Environment variables button below.
click on Environment variables and here you will find the two halfs. i.e., user settings and system settings.
In both settings you will find the Path named value click on that and then press edit option below, and now paste the java bin link and apply and close it.
Note: If you pasted the java link in user settings it is for particular user only. and if you pasted the java path in system settings then java can be used globally and any user of your system can use the java.
Tips:
you can use the command cls in command prompt to clear the screen.