Convert Float Decimal to Octal Number in Java

Ankith Reddy
Updated on 25-Jun-2020 14:25:17

365 Views

We can convert any decimal number to its equivalent octal by following program.In this we reserve the reminder we get after divide the given number by 8 as it is the base of Octal and then reverse the order of reminders we have stored by multiplying each reminder by 10.Let understand by following example.Example Live Demopublic class DecimalToOctal {    public static void main(String[] args) {       int decimal = 84;       int octalNumber = 0, i = 1;       while (decimal != 0) {          octalNumber += (decimal % 8) * i;          decimal /= 8;          i *= 10;       }       System.out.println("Octal of given decimal is " + octalNumber);    } }OutputOctal of given decimal is 124

Print Duplicates from a List of Integers in Java

George John
Updated on 25-Jun-2020 14:23:39

4K+ Views

In order to find duplicates we can utilize the property of Set in Java that in Java duplicates are not allowed when going to be added in a Set.Add method of set returns true for the adding value which is not added previously to it while it would return false in case the adding value is already present in the Set.For our agenda we would iterate out list or collection of integer and try to add each integer in a set of type integer.Now if integer gets added than this means that it is occurring for first time and not ... Read More

JavaBean Class in Java

Ankith Reddy
Updated on 25-Jun-2020 14:22:20

4K+ Views

A JavaBean is a specially constructed Java class written in the Java and coded according to the JavaBeans API specifications.Following are the unique characteristics that distinguish a JavaBean from other Java classes −It provides a default, no-argument constructor.It should be serializable and that which can implement the Serializable interface.It may have a number of properties which can be read or written.It may have a number of "getter" and "setter" methods for the properties.JavaBeans PropertiesA JavaBean property is a named attribute that can be accessed by the user of the object. The attribute can be of any Java data type, including ... Read More

Generate Temporary Files and Directories Using Python

Arjun Thakur
Updated on 25-Jun-2020 14:21:25

15K+ Views

The tempfile module in standard library defines functions for creating temporary files and directories. They are created in special temp directories that are defined by operating system file systems. For example, under Windows the temp folder resides in profile/AppData/Local/Temp while in linux the temporary files are held in /tmp directory.Following functions are defined in tempfile moduleTemporaryFile()This function creates a temporary file in the temp directory and returns a file object, similar to built-in open() function. The file is opened in wb+ mode by default, which means it can be simultaneously used to read/write binary data in it. What is important, ... Read More

Lambda Expression in Java 8

Arjun Thakur
Updated on 25-Jun-2020 14:17:55

675 Views

Lambda expressions are introduced in Java 8 and are touted to be the biggest feature of Java 8. Lambda expression facilitates functional programming, and simplifies the development a lot.SyntaxA lambda expression is characterized by the following syntax.parameter -> expression bodyFollowing are the important characteristics of a lambda expression.Optional type declaration − No need to declare the type of a parameter. The compiler can inference the same from the value of the parameter.Optional parenthesis around parameter − No need to declare a single parameter in parenthesis. For multiple parameters, parentheses are required.Optional curly braces − No need to use curly braces ... Read More

Check Occurrence of Each Vowel in String using Java

Chandu yadav
Updated on 25-Jun-2020 14:16:42

754 Views

To count occurence of vowels in a string again use Map utility of java as used in calculating occurence of each character in string.Put each vowel as key in Map and put initial value as 1 for each key.Now compare each character with key of map if a character matches with a key then increase its corresponding value by 1.Examplepublic class OccurenceVowel {    public static void main(String[] args) {       String str = "AEAIOG";       LinkedHashMap hMap = new LinkedHashMap();       hMap.put('A', 0);       hMap.put('E', 0);       hMap.put('I', 0);       hMap.put('O', 0);       hMap.put('U', 0);       for (int i = 0; i

Reverse Words in a Given String in Java

karthikeya Boyini
Updated on 25-Jun-2020 14:16:25

5K+ Views

The order of the words in a string can be reversed and the string displayed with the words in reverse order. An example of this is given as follows.String = I love mangoes Reversed string = mangoes love IA program that demonstrates this is given as follows.Example Live Demoimport java.util.regex.Pattern; public class Example {    public static void main(String[] args) {       String str = "the sky is blue";       Pattern p = Pattern.compile("\s");       System.out.println("The original string is: " + str);       String[] temp = p.split(str);       String rev = ... Read More

Random vs Secure Random Numbers in Java

Arjun Thakur
Updated on 25-Jun-2020 14:15:38

4K+ Views

Java provides two classes for having random numbers generation - SecureRandom.java and Random.java.The random numbers can be used generally for encryption key or session key or simply password on web server.SecureRandom is under java.security package while Random.java comes under java.util package.The basic and important difference between both is SecureRandom generate more non predictable random numbers as it implements Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) as compare to Random class which uses Linear Congruential Generator (LCG).A important point to mention here is SecureRandom is subclass of Random class and inherits its all method such as nextBoolean(), nextDouble(), nextFloat(), nextGaussian(), nextInt() and ... Read More

Referencing Subclass Objects with Subclass vs Superclass Reference

Ankith Reddy
Updated on 25-Jun-2020 14:15:01

3K+ Views

In java inheritance some of the basic rules includes −Object relation of Superclass (parent) to Subclass (child) exists while child to parent object relation never exists.This means that reference of parent class could hold the child object while child reference could not hold the parent object.In case of overriding of non static method the runtime object would evaluate that which method would be executed of subclass or of superclass.While execution of static method depends on the type of reference that object holds.Other basic rule of inheritance is related to static and non static method overriding that static method in java ... Read More

Reading and Writing CSV File Using Python

Ankith Reddy
Updated on 25-Jun-2020 14:14:39

2K+ Views

CSV (stands for comma separated values) format is a commonly used data format used by spreadsheets. The csv module in Python’s standard library presents classes and methods to perform read/write operations on CSV files.writer()This function in csv module returns a writer object that converts data into a delimited string and stores in a file object. The function needs a file object with write permission as a parameter. Every row written in the file issues a newline character. To prevent additional space between lines, newline parameter is set to ‘’.The writer class has following methodswriterow()This function writes items in an iterable ... Read More

Advertisements