Write a program to input a sentence and convert it into uppercase and count and display the total number of words starting with a letter ‘A’. Ans.
Category: Java
Write a Java program for Buble sort.
Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique. Ans.
Java program for String, to uppercase, to equal, length of string
Define a class to accept two strings, convert them into uppercase, check and display whether two strings are equal or not, if the two strings are not equal, print the string with the highest length or print the message both the strings are of equal length. Ans.
Define a class to declare an array of size 20 of the double datatype, accept the elements into the array and perform the following: Calculate and print the sum of all the elements.
Define a class to declare an array of size 20 of the double datatype, accept the elements into the array and perform the following: Calculate and print the sum of all the elements. Calculate and print the highest value of the array. Ans.
Define a class to declare an integer array of size n and accept the elements into the array.
import java.util.Scanner;class LinearSearch{public static void main(String args[]){int c, n, search, array[];Scanner in = new Scanner(System.in);System.out.println(“Enter number of elements”);n = in.nextlnt();array= new int[n];System.out.println(“Enter those” +n+ “elements”);for (c = 0; c < n; c++)array[c] = in.nextlnt();System.out.println(“Enter value to find”);search = in.nextlnt();for (c = 0; c < n; c++){if (array[c] = search) /Searching element is present/{System.out.println(array[c]);break;}}if (c = […]
File handling
FILE HANDLING: File handling in java comes under input output (IO) operations. Classes used in file handling in Java are present Java IO package (java.io). Some of the file handling operations are: Create file Delete file Read file Write file Changes file permissions, etc. Program for create operation in file handling: package com.journaldev.files; import java.io.File; […]
CLOSE THE DATABASE CONNECTION
CLOSE THE DATABASE CONNECTION: It is not necessary to close the connection, but open database can cause problems, so its better to close the database connection. For this close( ) method is used. Syntax: stmt.close( ); Here, stmt is statement object to be closed. cn.close( ); Here, cn is the connection object to be closed.
Process the result
The result of the SQL statement (SQL queries) are stored in a ResultSet object. To retrieve the data from the ResultSet we need to use the getXXX methods. These methods retrieve the data and convert it to a Java data type. There is a separate getXXX methods for each datatype. For example, getString( ) is […]
Execute an SQL Statement
EXECUTE AN SQL STATEMENT: There are three methods to execute the statement, which are execute( ), executeQuery( ) and executeUpdate( ). Syntax: stmt.execute( ); stmt.execute( String str); Syntax: stmt.executeQuery( ); stmt.executeQuery( String str); Syntax: stmt.executeUpdate( ); stmt.executeUpdate( String str );
Establish Database Connection
To connect to the database getConnection() method is used.Syntax:DriverManager.getConnection(String url, String user, String password);