What are the JDBC statements?
In JDBC, Statements are used to send SQL commands to the database and receive data from the database. There are various methods provided by JDBC statements such as execute(), executeUpdate(), executeQuery, etc. which helps you to interact with the database.
In JDBC, Statements are used to send SQL commands to the database and receive data from the database. There are various methods provided by JDBC statements such as execute(), executeUpdate(), executeQuery, etc. which helps you to interact with the database.
π1
What is the return type of Class.forName() method?
The Class.forName() method returns the object of java.lang.Class object
The Class.forName() method returns the object of java.lang.Class object
π1
For more information visit
https://cjavapoint.blogspot.com/2023/09/Java%20Inheritance%20Update.html
https://cjavapoint.blogspot.com/2023/09/Java%20Inheritance%20Update.html
How can we set null value in JDBC PreparedStatement?
By using setNull() method of PreparedStatement interface, we can set the null value to an index. The syntax of the method is given below.
void setNull(int parameterIndex, int sqlType) throws SQLException
By using setNull() method of PreparedStatement interface, we can set the null value to an index. The syntax of the method is given below.
void setNull(int parameterIndex, int sqlType) throws SQLException
What is the role of the JDBC DriverManager class?
The DriverManager class acts as an interface between user and drivers. It keeps track of the drivers that are available and handles establishing a connection between a database and the appropriate driver. The DriverManager class maintains a list of Driver classes that have registered themselves by calling the method DriverManager.registerDriver().
The DriverManager class acts as an interface between user and drivers. It keeps track of the drivers that are available and handles establishing a connection between a database and the appropriate driver. The DriverManager class maintains a list of Driver classes that have registered themselves by calling the method DriverManager.registerDriver().
What are the functions of the JDBC Connection interface?
The Connection interface maintains a session with the database. It can be used for transaction management. It provides factory methods that return the instance of Statement, PreparedStatement, CallableStatement, and DatabaseMetaData.
The Connection interface maintains a session with the database. It can be used for transaction management. It provides factory methods that return the instance of Statement, PreparedStatement, CallableStatement, and DatabaseMetaData.
What is the difference between HashSet and TreeSet?
The HashSet and TreeSet, both classes, implement Set interface. The differences between the both are listed below.
HashSet maintains no order whereas TreeSet maintains ascending order.
HashSet impended by hash table whereas TreeSet implemented by a Tree structure.
HashSet performs faster than TreeSet.
HashSet is backed by HashMap whereas TreeSet is backed by TreeMap.
The HashSet and TreeSet, both classes, implement Set interface. The differences between the both are listed below.
HashSet maintains no order whereas TreeSet maintains ascending order.
HashSet impended by hash table whereas TreeSet implemented by a Tree structure.
HashSet performs faster than TreeSet.
HashSet is backed by HashMap whereas TreeSet is backed by TreeMap.
π3
What is the difference between Set and Map?
The differences between the Set and Map are given below.
Set contains values only whereas Map contains key and values both.
Set contains unique values whereas Map can contain unique Keys with duplicate values.
Set holds a single number of null value whereas Map can include a single null key with n number of null values.
The differences between the Set and Map are given below.
Set contains values only whereas Map contains key and values both.
Set contains unique values whereas Map can contain unique Keys with duplicate values.
Set holds a single number of null value whereas Map can include a single null key with n number of null values.
What is the difference between HashSet and HashMap?
The differences between the HashSet and HashMap are listed below.
HashSet contains only values whereas HashMap includes the entry (key, value). HashSet can be iterated, but HashMap needs to convert into Set to be iterated.
HashSet implements Set interface whereas HashMap implements the Map interface
HashSet cannot have any duplicate value whereas HashMap can contain duplicate values with unique keys.
HashSet contains the only single number of null value whereas HashMap can hold a single null key with n number of null values.
The differences between the HashSet and HashMap are listed below.
HashSet contains only values whereas HashMap includes the entry (key, value). HashSet can be iterated, but HashMap needs to convert into Set to be iterated.
HashSet implements Set interface whereas HashMap implements the Map interface
HashSet cannot have any duplicate value whereas HashMap can contain duplicate values with unique keys.
HashSet contains the only single number of null value whereas HashMap can hold a single null key with n number of null values.
π2
What is the difference between HashMap and TreeMap?
The differences between the HashMap and TreeMap are given below.
HashMap maintains no order, but TreeMap maintains ascending order.
HashMap is implemented by hash table whereas TreeMap is implemented by a Tree structure.
HashMap can be sorted by Key or value whereas TreeMap can be sorted by Key.
HashMap may contain a null key with multiple null values whereas TreeMap cannot hold a null key but can have multiple null values.
The differences between the HashMap and TreeMap are given below.
HashMap maintains no order, but TreeMap maintains ascending order.
HashMap is implemented by hash table whereas TreeMap is implemented by a Tree structure.
HashMap can be sorted by Key or value whereas TreeMap can be sorted by Key.
HashMap may contain a null key with multiple null values whereas TreeMap cannot hold a null key but can have multiple null values.
What is the difference between Collection and Collections?
The differences between the Collection and Collections are given below.
The Collection is an interface whereas Collections is a class.
The Collection interface provides the standard functionality of data structure to List, Set, and Queue. However, Collections class is to sort and synchronize the collection elements.
The Collection interface provides the methods that can be used for data structure whereas Collections class provides the static methods which can be used for various operation on a collection.
The differences between the Collection and Collections are given below.
The Collection is an interface whereas Collections is a class.
The Collection interface provides the standard functionality of data structure to List, Set, and Queue. However, Collections class is to sort and synchronize the collection elements.
The Collection interface provides the methods that can be used for data structure whereas Collections class provides the static methods which can be used for various operation on a collection.
π2
For more information visit
https://cjavapoint.blogspot.com/2023/09/Java%20Inheritance%20Update.html
https://cjavapoint.blogspot.com/2023/09/Java%20Inheritance%20Update.html
Forwarded from java interview Questions (Raj patel)
HAS-A Relationship
1.HAS-A Relationship is also knows as composition(or) aggregation.
2.There is no specific keyword to implement HAS-A relationship but mostly
we can use new operator.
3.The main advantage of reusability.
Example:-
class Engine
{
// engine functionality
}
class Car
{
Engine e=new Engine();
//------------------------------;
//------------------------------;
//------------------------------;
}
NOTE:-
class car has-a engine reference.
The main dis-advantage of has-a relationship increases dependency between the
components and creates maintains problems. ππππππ More java interview Questions Visit: -https://cjavapoint.blogspot.com/πππππ
1.HAS-A Relationship is also knows as composition(or) aggregation.
2.There is no specific keyword to implement HAS-A relationship but mostly
we can use new operator.
3.The main advantage of reusability.
Example:-
class Engine
{
// engine functionality
}
class Car
{
Engine e=new Engine();
//------------------------------;
//------------------------------;
//------------------------------;
}
NOTE:-
class car has-a engine reference.
The main dis-advantage of has-a relationship increases dependency between the
components and creates maintains problems. ππππππ More java interview Questions Visit: -https://cjavapoint.blogspot.com/πππππ
π2β€1
Forwarded from java interview Questions (Raj patel)
Core Java Inetrview Questions java Opps Concept What is method overloading in OOP or Java? (answer)
It's one of the oldest OOPS concept questions, I have seen it 10 years ago and still sees it now. When we have multiple methods with the same name but different functionality then it's called method overloading. For example. System.out.println() is overloaded as we have 6 or 7 println() method each accepting a different type of parameter.
What is method overriding in OOP or Java? (answer)
It's one of the magic of object oriented programming where the method is chose based upon an object at runtime. In order for method overriding, we need Inheritance and Polymorphism, as we need a method with the same signature in both superclass and subclass. A call to such method is resolved at runtime depending upon the actual object and not the type o variable. See the answer for more detailed discussion. more Questions Visit https://cjavapoint.blogspot.com/πππππππ
It's one of the oldest OOPS concept questions, I have seen it 10 years ago and still sees it now. When we have multiple methods with the same name but different functionality then it's called method overloading. For example. System.out.println() is overloaded as we have 6 or 7 println() method each accepting a different type of parameter.
What is method overriding in OOP or Java? (answer)
It's one of the magic of object oriented programming where the method is chose based upon an object at runtime. In order for method overriding, we need Inheritance and Polymorphism, as we need a method with the same signature in both superclass and subclass. A call to such method is resolved at runtime depending upon the actual object and not the type o variable. See the answer for more detailed discussion. more Questions Visit https://cjavapoint.blogspot.com/πππππππ
π1
Forwarded from java interview Questions (Raj patel)
What is method overloading?
Method overloading is a programming technique that allows developers to use the same method name multiple times in the same class, but with different parameters. In this case, we say that the method is overloaded. Listing 1 shows a single method whose parameters differ in number, type, and order.
Listing 1. Three types of method overloading
Number of parameters:
public class Calculator {
void calculate(int number1, int number2) { }
void calculate(int number1, int number2, int number3) { }
}
Type of parameters:
public class Calculator {
void calculate(int number1, int number2) { }
void calculate(double number1, double number2) { }
}
Order of parameters:
public class Calculator {
void calculate(double number1, int number2) { }
void calculate(int number1, double number2) { }
} more java interview Questions visit https://cjavapoint.blogspot.com/ join my me on https://t.me/javaQuestions4u ππππππππ
Method overloading is a programming technique that allows developers to use the same method name multiple times in the same class, but with different parameters. In this case, we say that the method is overloaded. Listing 1 shows a single method whose parameters differ in number, type, and order.
Listing 1. Three types of method overloading
Number of parameters:
public class Calculator {
void calculate(int number1, int number2) { }
void calculate(int number1, int number2, int number3) { }
}
Type of parameters:
public class Calculator {
void calculate(int number1, int number2) { }
void calculate(double number1, double number2) { }
}
Order of parameters:
public class Calculator {
void calculate(double number1, int number2) { }
void calculate(int number1, double number2) { }
} more java interview Questions visit https://cjavapoint.blogspot.com/ join my me on https://t.me/javaQuestions4u ππππππππ
π5β€1
Forwarded from java interview Questions (Raj patel)
Strings in Java
Strings in Java are Objects that are backed internally by a char array. Since arrays are immutable(cannot grow), Strings are immutable as well. Whenever a change to a String is made, an entirely new String is created.
Below is the basic syntax for declaring a string in Java programming language.
Syntax: String str = "learnJava";
More java Interview Questions Visit:- https://cjavapoint.blogspot.com/ ππππππ
Strings in Java are Objects that are backed internally by a char array. Since arrays are immutable(cannot grow), Strings are immutable as well. Whenever a change to a String is made, an entirely new String is created.
Below is the basic syntax for declaring a string in Java programming language.
Syntax: String str = "learnJava";
More java Interview Questions Visit:- https://cjavapoint.blogspot.com/ ππππππ
π3β€1
8.1 What is the difference between a Choice and a List ?
A Choice is displayed in a compact form that must be pulled down, in order for a user to be able to see the list of all available
choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible.
A List supports the selection of one or more List items.
8.2
What is a layout manager ?
A layout manager is the used to organize the components in a container.
8.3
What is the difference between a Scrollbar and a JScrollPane ?
A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs
its own scrolling.
8.4
Which Swing methods are thread-safe ?
There are only three thread-safe methods: repaint, revalidate, and invalidate.
8.5
Name three Component subclasses that support painting.
The Canvas, Frame, Panel, and Applet classes support painting.
8.6
What is clipping ?
Clipping is defined as the process of confining paint operations to a limited area or shape.
8.7
What is the difference between a MenuItem and a CheckboxMenuItem ?
The CheckboxMenuItem class extends the MenuItem class and supports a menu item that may be either checked or unchecked
A Choice is displayed in a compact form that must be pulled down, in order for a user to be able to see the list of all available
choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible.
A List supports the selection of one or more List items.
8.2
What is a layout manager ?
A layout manager is the used to organize the components in a container.
8.3
What is the difference between a Scrollbar and a JScrollPane ?
A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs
its own scrolling.
8.4
Which Swing methods are thread-safe ?
There are only three thread-safe methods: repaint, revalidate, and invalidate.
8.5
Name three Component subclasses that support painting.
The Canvas, Frame, Panel, and Applet classes support painting.
8.6
What is clipping ?
Clipping is defined as the process of confining paint operations to a limited area or shape.
8.7
What is the difference between a MenuItem and a CheckboxMenuItem ?
The CheckboxMenuItem class extends the MenuItem class and supports a menu item that may be either checked or unchecked
π17β€4
public class RemoveNonASCIIString{
public static void main(String [] args){
String str = "InstanceΒ‘ofΒ₯java";
System.out.println(str);
str = str.replaceAll("[^\\p{ASCII}]", "");
System.out.println("After removing non ASCII chars:");
System.out.println(str);
}
}
public static void main(String [] args){
String str = "InstanceΒ‘ofΒ₯java";
System.out.println(str);
str = str.replaceAll("[^\\p{ASCII}]", "");
System.out.println("After removing non ASCII chars:");
System.out.println(str);
}
}
π4β€1
import java.util.Arrays;
import java.util.LinkedHashSet;
public class ArrayExample
{
public static void main(String[] args) throws CloneNotSupportedException
{
//Array with duplicate elements
Integer[] numbers = new Integer[] {1,2,3,4,5,1,3,5};
//This array has duplicate elements
System.out.println( Arrays.toString(numbers) );
//Create set from array elements
LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>( Arrays.asList(numbers) );
//Get back the array without duplicates
Integer[] numbersWithoutDuplicates = linkedHashSet.toArray(new Integer[] {});
//Verify the array content
System.out.println( Arrays.toString(numbersWithoutDuplicates) );
}
}
import java.util.LinkedHashSet;
public class ArrayExample
{
public static void main(String[] args) throws CloneNotSupportedException
{
//Array with duplicate elements
Integer[] numbers = new Integer[] {1,2,3,4,5,1,3,5};
//This array has duplicate elements
System.out.println( Arrays.toString(numbers) );
//Create set from array elements
LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>( Arrays.asList(numbers) );
//Get back the array without duplicates
Integer[] numbersWithoutDuplicates = linkedHashSet.toArray(new Integer[] {});
//Verify the array content
System.out.println( Arrays.toString(numbersWithoutDuplicates) );
}
}
β€2π1
240-core-java-interview-questions-and-answers.pdf
502.6 KB
π4β€1π1