Java Connection getMetaData Method with Example

Arushi
Updated on 02-Aug-2024 18:19:16

2K+ Views

Generally, Data about data is known as metadata. The DatabaseMetaData interface provides methods to get information about the database you have connected with like, database name, database driver version, maximum column length, etc... The getMetaData() method of the Connection interface retrieves and returns the DatabaseMetaData object. This contains information about the database you have connected to. You can get information about the database such as the name of the database, version, driver name, user name, URL, etc… by invoking the methods of the DatabaseMetaData interface using the obtained object. This method returns the DatabaseMetaData object which holds information about the underlying ... Read More

Check the End of a String in Java

karthikeya Boyini
Updated on 02-Aug-2024 18:17:40

3K+ Views

In general, the endswith() method in Java is used to check whether the given string ends with a specific suffix string or not. If the substring ends with the specific string then it will return a Boolean value true, otherwise it will return false if the value is not found. Syntax public boolean endsWith(String suffix) Problem Statement Write a program to check if a string ends with a specific substring in Java − Input str = demo Output The string ends with the word mo Step to check the end of a string Following are the steps to check with ... Read More

Rename a File or Directory in Java

karthikeya Boyini
Updated on 02-Aug-2024 18:16:28

2K+ Views

The method File.renameTo() method of the java.io package is used to rename a file or directory. This method requires a single parameter i.e. the name that the file or directory is renamed to and it returns true on the success of the renaming or false otherwise. Syntax public boolean renameTo(File dest) Steps to rename a file or directory using File renameTo() method Below are the steps to rename a file or directory using the File renameTo() method − Import File class from java.io package Define the demo class with the main method. ... Read More

Calculate the Power of a Number in Java

Lakshmi Srinivas
Updated on 02-Aug-2024 18:16:16

3K+ Views

Read the base and exponent values from the user. Multiply the base number by itself and multiply the resultant with base (again) repeat this n times where n is the exponent value. 2 ^ 5 = 2 X 2 X 2 X 2 X 2 (5 times) Problem Statement Given a number, write a program in Java to calculate the power of the number − Input Enter the base number :: 12 Enter the exponent number :: 2 Output Result of 12 power 2 is 144 Steps to calculate the power of a number Import ... Read More

Check If an Array Contains a Given Value in Java

Alshifa Hasnain
Updated on 02-Aug-2024 18:16:00

1K+ Views

In this article, we will understand how to check if an array contains a given value using two methods: Linear search and the HashSet class. For Linear Search, we will iterate through the array elements, comparing each element with the given input. For the HashSet class, we will utilize the contains() method to achieve this efficiently. Problem Statement Write a Java program to check if an array contains the given value − Input 1 Enter the number to be searched: 25 The elements in the integer array: 15 20 25 30 35 Output 1 The array contains the given value ... Read More

Sum Up Elements of a C++ Vector

Vishesh Raina
Updated on 01-Aug-2024 12:27:52

27K+ Views

In this article, we will understand how to sum the elements present inside a vector in C++. A vector is a dynamically allocated array with variable size. The sum of elements of a vector can be calculated in a number of ways, and we will discuss two such ways. Problem Statement Given a non-empty vector of integers, calculate the sum of all elements of the vector using multiple approaches in C++. Examples The following examples give the input and output of some test cases : Input vector vec={1, 3, 4, 5, 2, 3} Output ... Read More

Convert String to Byte in Java

Shriansh Kumar
Updated on 01-Aug-2024 12:10:46

1K+ Views

Suppose you are given a String named "str". Now, your task is to write a Java program to convert the given string to Byte. String is a class in Java which stores sequence of characters within double quotes and Byte is a wrapper class of java.lang package which wraps value of byte datatype. Example Scenario: Input: String str = "65"; Output: res = 65 Using Byte.valueOf() Method The valueOf() method of Java Byte class is used to convert given string into its corresponding Byte object. It accepts a single numeric string as a parameter value and returns it as ... Read More

Check if a Given Number is a Fibonacci Number in Java

Shriansh Kumar
Updated on 01-Aug-2024 11:57:13

3K+ Views

For a given input number, write a Java program to check if it is a Fibonacci number. Any number that belongs to Fibonacci series is called as Fibonacci number. The Fibonacci series is a sequence of numbers formed by the sum of its two previous integers. The first two terms of this series are 0 and 1 and further terms go like 1, 2, 3, 5, 8 and so on. This series was named after a famous Italian mathematician, Leonardo Fibonacci. Example Scenario 1 Input: num1 = 8; Output: 8 is a Fibonacci number 8 comes into ... Read More

Check Whether a Number is Prime in Java

Shriansh Kumar
Updated on 01-Aug-2024 11:55:27

27K+ Views

Given a number, let's say N, write a Java program to check whether the given number is prime or not. Prime numbers are special numbers with only two factors 1 and that number itself, they cannot be divided by any other number. Example Scenario 1 Input: num = 1; Output: 1 is not a prime number Example Scenario 2 Input: num2 = 5; Output: 5 is a prime number 5 is divisible by 1 and 5 only Checking Prime Numbers using Factorization The naive approach to check a given number is prime or not is factorization. ... Read More

Check Whether a Number is a Neon Number in Java

Shriansh Kumar
Updated on 01-Aug-2024 11:54:45

1K+ Views

In this article, we will understand how to check whether the given input number is a neon number. A neon number is such a number whose sum of digits of square of the number is equal to the number itself. Example Scenario: Input: num = 9; Output: The given input is a neon number How to Check Neon Number in Java? To check a given input is a neon number in Java, use the below approaches − Using for loop Using while loop Using recursion Using ... Read More

Advertisements