JAVA is one of the most popular programming languages all across the world. It is mainly used for developing a lot of application software. Since it is platform-independent, all this software can be executed on all devices.
However, JAVA has a lot of functions and methods that can make your task much simpler in the time of coding. So we brought you all the useful and important commands and features of JAVA that you must know.
- JAVA supports all sorts of arithmetic operations. To perform those, you have to simply use the addition (+), subtraction (–), division (/), or multiplication (*) operators if and when required.
- Relational operators such as “==, <,>, <=,>=,!=” are used for checking any sort of statement is true or false.
- To join any two statements, you can use the AND (&&) or OR (||) operators. These are mostly used for checking conditions simultaneously
- The postfix and prefix increment operators are used to increase or decrease the value assigned to the variable by one.
- The (.) operator is a very special operator present in JAVA. It is used to access all the methods of the class.
- The first step to start a JAVA program is by creating a class. The word class is a keyword used to create a class.
- If you want to declare an abstract class, you can use the abstract keyword before the class name.
- The try keyword is used to create a block of code in your program that can handle exceptions.
- Followed by the try keyword, the keyword catch is used to get hold of all the exceptions generated or thrown by the try.
- If you want to define a set of constants, you can use the enum keyword.
- Inheritance is one of the primary and key features of JAVA programming. The keyword extends used to signify inheritance.
- If you want to fix a value so that it cannot be changed, then the final keyword is the one that should be used.
- After the try-catch structure, the finally keyword is used to execute the entire program.
- If you want to implement an interface, then the implements keyword is used for that task.
- The new keyword in JAVA is used to create new objects within the program.
- The super keyword in a program is used to refer to the parent class from which other classes are inherited.
- If you want to refer to a particular object in a function or a constructor, then this keyword is the one you should use.
- Just like the name suggests, the throw keyword is simply used to throw away an exception.
- If you want to declare an exception, then the throws keyword is used for doing this function.
- A parameter list of a function is a sequence of variables and their data types that are to be used in that function in JAVA.
- A return statement is for returning the value to the calling method if a return type is mentioned before the function or class.
- If there are two conditions to be checked from then in that scenario, the if-else statement is the perfect choice for coding.
- But if there are more than two conditions, then the switch statement is the ideal one. In the switch statement, the compiler only executes if a condition is true and the rest are left.
- If you want to terminate from a loop or any condition, then the break keyword is to be used; it acts as a termination statement. You can also use the exit() function to serve the same.
- If you want to create an entry control loop, then for that, you can use for loop and while loop structures. And if you want an exit control loop, the do-while loop is the ideal structure for the task.
- If you want to convert an entire string into the lower case, then toLowerCase() is used
- For converting an entire string into the upper case, you can use the toUpperCase() function.
- If you want to replace any given character with another character, you can use the replace() function.
Syntax: replace(‘a’, ‘b’) if you want to replace a by b.
- The trim() function can be used to remove all the white spaces from the beginning and end of a given string.
- equals() is a Boolean function to check if two given strings are the same or not. If you want to check the strings irrespective of the case, then you can use equalsIgnoreCase().
- If you want to check the length of the string given, you can use the length() function instead of extracting all the characters one by one.
- Suppose you want to find a character present in a particular position in a string. For that, you can use the CharAt() function.
Syntax: CharAt(n) to find the character present in the nth position.
- If you want to compare two strings, then for that situation, the compareTo() function is present.
It provides a positive result if the 1st string is greater than the 2nd one.
It provides a negative result if 2nd string is greater than the first one
It provides zero as a result if both the strings are the same.
- The concat() function is present to make the joining of two strings easier for the developer.
- If you want to create a new string from an old string, you can use the substring() function.
Syntax: substring(n) is the syntax if you want to create a new string starting from the nth term of the string.
Substring(n,m) is used if you want to create a new string starting from the nth to the mth term.
- To create the string representation of an object, the toString() function is used.
- If you intend to find the position of a given character in a string, you can use the indexOf() function.
Syntax: indexOf(‘a’) will give the position of the first occurrence of the character a in the string.
Syntax: indexOf(‘a’, n) is to find the position of occurrence of ‘a’ after the nth index.
- The ValueOf(variable) function is used to convert the parameter values to their string representations.