Core java
06 OctoberConvert char to lowercase java
You can use Character class’s toLowerCase method to convert char to lowercase in java. Method signature public static char toLowerCase(char ch) Parameters ch is primitive character type. Return type return type is char. If char is already lowercase then it will return same. package org.arpit.java2blog; public class JavaToLowercaseMain { public static void main(String[] args) { […]
06 OctoberConvert char to uppercase java
You can use Charater class’s touppercase method to convert char to uppercase in java. Method signature public static char touppercase(char ch) Parameters ch is primitive character type. Return type return type is char. If char is already uppercase then it will return same. package org.arpit.java2blog; public class JavaToUpperCaseMain { public static void main(String[] args) { […]
06 OctoberJava isLetter method
Character class’s isletter method can be used to check if character is letter or not. Method signature public static boolean isLetter(char ch): Parameters ch is primitive character type. Return type boolean is primitive character type. package org.arpit.java2blog; public class JavaIsLetterMain { public static void main(String[] args) { System.out.println(Character.isLetter('a')); System.out.println(Character.isLetter('Y')); System.out.println(Character.isLetter('5')); System.out.println(Character.isLetter('&')); } } When you […]
06 OctoberFix cannot make static reference to non-static method
In this post, we will see how to solve cannot make static reference to non-static method. [toc] Let’s understand this error with the help of example. package org.arpit.java2blog; public class JavaHelloWorld { public static void main(String args[]) { sayHello(); } public void sayHello() { System.out.println("Hello world from java2blog"); } } Above program won’t compile and […]
06 OctoberImplement distance formula in java
In this post, we will see how to implement distance formula between two points in java. Formula to find distance between two points ( x1, y1) and (x2 , y2) is d= sqrt( (x2-x1)^2+ (y2 – y1)^2) Here is simple program to calculate distance between two points in java. package org.arpit.java2blog; public class calculateDistanceMain { […]
06 OctoberConvert decimal to binary in java
In this post, we will see how to convert decimal to binary in java. There are lot of ways to convert decimal to binary in java.Let’s explore them one by one. [toc] Using Integer.toBinaryString() method You can simply use inbuilt Integer.toBinaryString() method to convert a decimal package org.arpit.java2blog; public class DecimalToBinaryInBuiltMain { public static void […]
05 OctoberCalculate total surface area of Cylinder in java
In this post, we will see how to calculate total surface area of Cylinder in java. Formula of calculating total surface area of Cylinder is: Surface area of Cylinder = 2 *Π * r * r + 2 *Π * r * h Where r is radius of cylinder and h is height of cylinder […]
05 OctoberCalculate total surface area of Hemisphere in java
In this post, we will see how to calculate total surface area of Hemisphere in java. Hemisphere is exactly half of sphere. There can be many practical examples of Hemisphere. You can divide earth into two hemisphere i.e. Northen Hemisphere and Southern Hemisphere. Formula of calculating total surface area of Hemisphere is: surface area of […]
05 OctoberGet Random Number between 0 and 1 in Java
In this post, we will see how to get random number between 0 to 1 in java. We have already seen random number generator in java. Get Random Number between 0 and 1 in Java We can simply use Math.random() method to get random number between 0 to 1. Math.random method returns double value between […]