Study I
The world of programming is full of questions that can be answered with a simple answer. But sometimes, the answer isn't so clear-cut. In this article, I present to you some basic questions and answers that will help you get started with programming.
1. What is the difference between JDK and JVM?
The JDK (Java Development Kit) is a
collection of tools and utilities that are used in Java development. JVM is a
virtual machine that runs the Java code.
JDK stands for Java Development
Kit, while JVM stands for Java Virtual Machine.
2. What is the difference between JVM and JRE?
The Java Virtual Machine (JVM) is a
program that performs the instructions of your program. It's basically like an
operating system for Java programs, and it runs them in a virtual machine
environment. The JRE is just like the operating system for all applications on
your computer, including Word or Excel or Firefox.
The JVM can run most commonly used
languages such as C++, Ruby and Python through interpreters written in these
languages (known as compilers).
3. What is the base class of all classes?
The base class of all classes is
java.lang.Object. All classes are subclasses of this class, and all objects in
Java are instances of this class.
4. Give differences between these two classes java.util.Date and java.sql.Date ?
Two classes java.util.Date and
java.sql.Date are used for date and time manipulation in JDBC.
java.util.Date is used for date and
time manipulation, whereas java.sql.Date is used for date and time manipulation
in the JDBC interface itself (i).
5. What are wrapper classes?
Wrapper classes are used to convert
primitive data types to object types, and vice versa. For example, if you have
an int value in C++ code that you want to store as a string in Python code (or
vice versa), wrap your int with a class called IntWrapper. In Python:
```python
IntWrapper = object()
IntWrapper(int) = “int”
6. What are the types of statements in JDBC?
The following are the types of
statements in JDBC:
execute - executes SQL statement,
returning a result set.
update - updates a row in the
result set with one or more columns.
delete - deletes rows from the
result set based on criteria specified by you. You
can also delete multiple rows at once by specifying an INSERT command followed
by ROLLBACK and then any other commands that you want to use to remove those
rows (i.e., DELETE). If you don't specify any WHERE clause
parameters, all rows will be deleted unless they match your WHERE clause
criteria as follows: IF NOT EXISTS THEN SELECT * FROM Table; ELSE UPDATE Table
SET MyField = Value WHERE MyCondition
someOtherValue ; END IF ; . . . . . .
For example: TO VARCHAR(100) FROM
DUAL; WHEN 'SOME_COLUMN' THEN SET COLUMN = SUBSTRING(SOME_COLUMN); ELSE SET
COLUMN = 'OTHER_COLUMN'; END IF ;
7. What is a stored procedure?
A stored procedure is a collection
of SQL statements that has been saved in the database. It's a way of
encapsulating a series of SQL statements and making them available to all
applications that have access to it via DDL, DML and DDL commands. A stored
procedure can be called from any application that has access to the database.
8. What are the common SQL Function used in JDBC?
The most popular functions are:
SUM (Addition)
AVG (Average)
MIN(Minimum Value)
9. Difference between PreparedStatement and CallableStatement ?
PreparedStatement and
CallableStatement are both used to execute SQL statements. But they differ in
the following ways:
PreparedStatements are not executed
dynamically like callableStatements, but only once at the beginning of their
execution. After that, you can reuse them without having to go through a new
parse and bind operations again. This means that you can use preparedStatements
for static queries (e.g., SELECT * FROM Table), where no dynamic processing is
involved and there is no need for any complex logic within the statement
itself.
CallableStatements allow you to
create custom subqueries using parameterized SQL functions and variables from
your database as parameters/values; this allows you to build more complex
queries by combining smaller pieces into larger ones or simply by changing
individual parts of a query's text while keeping all other parts intact (for
example: "SELECT * FROM table WHERE col1 = ${col1} AND col2 >
20").
10. Why we use both Prepared Statement and Callable statement together ? what's the specific reason ?
Prepared Statement is used for insert,
update and delete statements. Callable statement is used for callable
statements.
When you write a prepared
statement, it returns a result set if the action was successful. If it fails
then an exception will be thrown and that exception can be caught by your code
if you want to handle it appropriately (you can do this using try..catch).
However when you use callableStatement , it doesn't return anything because
there's not any operation happening on this statement hence no exception will
be thrown even if something goes wrong during execution of your code (in which
case you would have access to all parameters passed into this function).
11. What is ResultSetMetaData in jdbc ? When it is used ? How to use it ? how to get it ?
ResultSetMetaData is a class that
represents information about a result set. It can be used to get information
about the columns in the result set, such as their names, types and display
sizes.
You have use this class when you
want to retrieve or change some properties of your query's resultset object.
Conclusion
In conclusion, the list of
questions here is definitely not exhaustive. But I hope you will find it
helpful in your journey to become a professional programmer. If you have any
other questions on this topic please let me know in the comments below.