Wednesday 23 October 2024

What is the JDBC Programming Model?

Advanced Java: 02

Q.1 What is JDBC?

  • JDBC is a java-based data access technology from sun microsystem.
  • JDBC is not a software, not a programming language it's a technology.
  • JDBC is a trademark name given to a technology.
  • No framework in the world without JDBC they can communicate with database.
  • There is no expansion of JDBC.
Q.2 What is the architecture of JDBC?
  • Please remember if you know JDBC then only you understand database.
  • Java database communication is to perform CRUD (create, read, update, delete) operation is acts like a client server architecture. JDBC follows client server architecture.
  • A software or a program that request for resources is a client.
  • A Software that provides requested resources to client is a server.
Q.3 What is a JDBC Client?
  • Any java program that uses JDBC Technology to communicate with the database is known as a JDBC client.
  • Why it is a client because java program is requesting for connection, requesting for CRUD operation.
Q.4 What is the JDBC Programming Model?
  • There are certain steps that you have to follow to understand JDBC Programming model.


Note: First you should be conceptually strong and then you should be programmatically strong.

Q.5 What are the JDBC client-side requirements to communicate with the database?

  • The movement we install JDK following things automatically get install along with it.
  1. JDBC API
  2. JDBC DRIVER
  • Without JDBC API (library Methods) and JDBC Driver you cannot communicate with the database.
Q.6 What is JDBC API?
  • Please note in interview if they ask what API is? then tell API is Application Programming Interface they are not asking long form of it please note. you have to tell them the correct answer is "A Collection of library methods" as you know in java methods belongs to Classes and Interfaces. Classes and Interfaces belongs to Packages. 
  • likewise, to communicate with the database java has java. SQL package which having library classes and library interfaces.
  • Now the answer for what is JDBC API? is "A Collection of library methods (that belongs to the library classes and library interfaces) of java SQL package."
  • Note: You installed JDK means you install JDBC API, but you need to import the package (java. SQL) in application. we required this to perform CRUD operation with the database.
  • JDBC API, is nothing but the tool.
Q.7 What is a JDBC Driver?
  • JDBC Driver is a translation software written in java according to JDBC specification.
  • JDBC Driver performs the following operation or duties to enable java-database communication.
  1. when java program (JDBC Client) makes a method call, JDBC Driver will receive that method call. JDBC Driver translates this method call into Pure SQL statement and send it to DBMS Software. DBMS handover this statement to MySQL for execution.
  2. Once the MySQL execute these statements (Query) it generates SQL Type response from the DBMS to JDBC Driver. now once again JDBC Driver translate this SQL Response into java format and handing over to java program (JDBC Client).



Imp Note: Once you understand JDBC, you will enjoy 6 to 7 ways of database connection.

 

Tuesday 22 October 2024

Why do we require Advanced Java?

Advanced Java: 1

We are going to learn advanced java in question answer form.

Q1. What is CORE JAVA?
  • Core java is used to developed standalone applications.
  • Core java means only language learning.
  • Core java is required to learn language but not sufficient.
  • Core java 25years outdated because now a days no one use standalone application for businesses.
Q2. What is Advanced Java?
  • To make the project online that is web application learn advanced java.
  • if you want to develop internet-based application learn advanced java.
  • if you want to become java professional you must learn advanced java.
  • Collection of various tools and technologies through which we can develop dynamic application.
  • To communicate with the database located at remote location we need Advanced Java.
  • We can develop network centric, web based, enterprise applications using advanced java.
Q3. What is the basis for company to provide services to customer?
  • For Ex. Bank --- Provides --- services to customers. Now using what they provide services to customer, so the answer is DATA. Online banking, online shopping any application to provide the services data is more important. (Joke in IT industry: More than wife data is important)
Q4. Which feature should data possess?
  • Now question comes to your mind why data requires features? data must require features because if data is not having any feature, then there is no use of such data.
  • Data of web application must possess following features:
  1. Persistence (Permanence): for ex. bank having data customers account no if after few days bank forgot customer account number, can we think that application or project or software work?
  2. Security: your data must be secure.
  3. Easy accessibility: This feature is also required for easy access of data.
For example, consider a scenario if i stored data in hard disk, data is permanent, but it is not secure and not easily accessible. so can you think you will get all those things in one place. Yes, if we store data in a database data will possess all features permanence, secure, easy accessibility, instead of writing 500 lines of code to access data from file system we easily get data from database through SQL statements.

Q5. Now if database is there then why java is required?
  • To answer this question let's assume, SBI bank all customers details stored in database. SBI is having 1000 branches all over India. suppose customer from Pune wants to know the balance enquiry so to know the balance can customer open SQL prompt and write SQL Statement for the same or can bank person open the SQL prompt and write SQL statement for the same as SELECT balance FROM Account WHERE Accountno=123.
  • What do you think can bank person knows the SQL Statement definitely not. secondly how SQL appears in Pune branch because database server is located somewhere in Mumbai branch.
  • From this we come's to know that database is weak in data processing and only database is not sufficient.
Q6. What is the Role of Java in Web application?
  • Role of java is Backend processing.
  • Communicating with the database and perform CRUD operations.
  • For example, consider the use case of balance enquiry.
  • When user enters his or her Account no: 1234 and click on getBalance button, java program will send select statement to database. similarly for CRUD operation java program will send insert, update and delete statement to the database.
  • Data processing is done by java. 
  • Making processed data to the frontend.
  • java role is backend processing. (How to communicate with database is the first part of advanced java JDBC and Servlet)
Q7. What is the Obstacle for java -database communication?
  • Java Program     --------------------------------------      Database
  • As we know in core java when we want to do any operation using java it will do it with java method calls. now using java program, we want to retrieve balance from the database for that purpose from java side it will call method for the same. 
  • now who will receive that method call answer is database will receive that method call but database does not understand method call. database understand only SQL Statement.
  • Now we have to make request in the form of SQL Statement using java, but java compiler does not accept SQL directly.
  • So, what we can say that java and database are heterogeneous to each other. 
  • This is the main obstacle for java database communication.
but still java wants to communicate with database, so we can simulate this problem with real world entities like PM of India wants to communicate with PM of Russia. both doesn't understand language of each other. So, to overcome this obstacle they use mediator or translator for the same so that they can understand each other's opinion.

Similarly, we use JDBC as a mediator or translator between 
Java (method calls) --------------------    JDBC     -------------------------   DBMS (SQL Statement only)

Q8. How java database communication?
  • By using JDBC java database connection is possible.

Next session will discuss.:

1. What is JDBC?
2. What is architecture of JDBC?
3. What is a JDBC client?
4. What is the JDBC Programming Model?
5. What are the JDBC Client side requirements to communicate with the database?
6. What is JDBC API?
7. What is a JDBC Driver?

Saturday 19 October 2024

Python program to check whether number is palindrome or not also count number of occurrences of each digit.


First of all, we have to write an algorithm for the same so that we come to know how to solve this problem statement step by step.

Algorithm:

1. Start
2. Accept any number n from the user.
3. Using function reverse the accepted number n.
4. Check whether the original and reverse number are same if yes then given number is palindrome.
5. If original and reverse number both are not same, then number is not palindrome.
6. Using function compute each digit occurrence inside the accepted number n.
7. Stop

Now, start the implementation of above algorithm step by step using python.

n = int (input ("Enter the Number n: "))

rev = reverse_num(n) # Function calling to reverse the given number.

if (rev = = n):
    print ("The number is palindrome")
else:
    print ("The number is not palindrome")

ocuurance_of_each_digit(n): # Function calling to find occurrence of each digit.

----------------------------------------------------------------------------------------------------------------------
# Function definition: To reverse the number.

def reverse_num(num):
    reverse = []
    while num >= 1:
        rem = int (num % 10)
        reverse.append(rem)
        num = num / 10
    print(reverse) # get number in reverse order but in list, so we want convert list to str
    temp=""
    for no in reverse:
            temp = temp + str(no)
    rev1 = int (temp) # now converting string to integer
    return rev1
-----------------------------------------------------------------------------------------------------------------------
 

----------------------------------------------------------------------------------------------------------------------
# Function definition: To find the occurrence of each digit in given number.

def ocuurance_of_each_digit(num):
    count = [0,0,0,0,0,0,0,0,0,0]
    while n >= 1:
        digit = int (n % 10)
        count[digit] = count[digit] + 1
        n = n / 10
length = len(count)
i = 0
while i < length:
    if count[i]! = 0:
        print(f"{i} occurance is:", count[i])
    i = i+1
-----------------------------------------------------------------------------------------------------------------------
        
       
    
    

Thursday 10 October 2024

NoSQL Databases