0% found this document useful (0 votes)
4 views30 pages

Java Journal

The document outlines a series of experiments for setting up a Java environment and using various programming concepts including installation of Java and Eclipse IDE, coding and debugging programs, and database connectivity through JDBC. It provides step-by-step instructions for each experiment, including code snippets and expected outputs. The experiments cover topics such as constructors, control statements, exception handling, and database operations.

Uploaded by

saadmaladar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views30 pages

Java Journal

The document outlines a series of experiments for setting up a Java environment and using various programming concepts including installation of Java and Eclipse IDE, coding and debugging programs, and database connectivity through JDBC. It provides step-by-step instructions for each experiment, including code snippets and expected outputs. The experiments cover topics such as constructors, control statements, exception handling, and database operations.

Uploaded by

saadmaladar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment 1: Install and setup java environment.

Step 1: Verify that it is already installed or not

1. Open Command Prompt and type javac

Google → Search → Java JDK


Select → Windows Download (x64 installer) i.e 153.38 MB
Download → Yes → Next → Next → Next steps → Close
1. This PC → C DRIVE → Program file → Java → JDK – [Link] → bin → Copy path address (C:\Program
Files\Java\jdk-[Link])
2. Start pc Search → System →Advanced System Settings → Environmental Variables

Above window will open. Click on "Environment Variables" to continue.


Enter "path" in variable name and enter the path to the bin folder inside your JDK in the variable value. Click
OK.

Now Java Path has been set up. Open the Command prompt and type "javac" In case you have already open up
the command prompt, I suggest you to close the existing window and reopen it again.

We will get javac executed as shown in the image below.

The Java has been installed on our system. Now, we need to configure IDEs like NetBeans or Eclipse in order
to execute JavaFX applications.
Experiment 01:
Steps to install Eclipse IDE.
 Visit the Eclipse official website at [Link]
 Go to the "Downloads" section.
 Click on the "Download Packages" button.
 Download the Eclipse installer file ("[Link]").
 Locate the downloaded installer file and double-click it.
 If prompted, click "Yes" to allow the installer to make changes to your system.
 In the Eclipse installer window, select "Eclipse IDE for Java Developers."
 Choose an installation location or use the default location.
 Click "Install" to start the installation process.
 Review the license terms and click "Accept Now."
 The installer will download and install the necessary components.
 Once the installation is complete, click "Launch" to start Eclipse.
 Choose a workspace location for your projects.
 Click "Launch" to open the Eclipse IDE.
 Optionally, customize the layout and preferences in the "Window" and "Preferences" menus.
 Test the installation by creating a new Java project, writing a simple Java program, and running it.
Experiment 2:
1. Code and debug programs that use different types of variables and
data types.
CODE:-

OUTPUT:-
Experiment 3: Code, execute and debug program. Identify and resolve issues in the given
code snippet.

A: That uses different types of contractor.

 Default Constructor
CODE:-

OUTPUT:-

 Parameterized Constructor
CODE:-
OUTPUT:-

B. Code, execute and debug program for expression evaluation

CODE:-

OUTPUT:-
C. Programs to perform Autoboxing and Unbloxing.

 Autoboxing
CODE:-

OUTPUT:-

 Unboxing
CODE:-

OUTPUT:-
Experiment 4: Memory allocation explanation through the programs.
A. By nulling the reference.
CODE:-

OUTPUT:-

B. By assigning a reference to another.


CODE:-
OUTPUT:-

B. By anonymous object.
CODE:-

OUTPUT:-
Experiment 5: Code, execute and debug programs that uses different control
statements. Identify and resolve issues in the given code snippet.

A: Using if else statement.

CODE:-

OUTPUT:-

B: Using do while statement.

CODE:-

OUTPUT:-
C: Using switch and break statement.

CODE:-

OUTPUT:-
D: Using continue statement.

CODE:-

OUTPUT:-
Experiment 6: A. Encapsulation Concept.
CODE:-
OUTPUT:-

B. Define class and implement like simple calculator or text processing and check compliance
with SRP.

CODE:-
OUTPUT:-
Experiment 7:
A. Code, execute and debug program that use array concept.

CODE:-

OUTPUT:-
B. Code, execute and debug program to perform string manipulation.

CODE:-

OUTPUT:-
Experiment 8:
A. Code, execute and debug programs that uses inheritance concept.

CODE:-

OUTPUT:-
B. Design a class and implement like File Parser and check Compliance with OCP.

CODE:-

OUTPUT:-
Experiment 9:
A. Code, execute and debug programs that uses static binding.

CODE:-

OUTPUT:-

B. Code, execute and debug programs that uses dynamic binding.

CODE:-

OUTPUT:-
Experiment 10:
A. Code, execute and debug programs that use abstract class to achieve abstractions.

CODE:

OUTPUT:-

B. Code, execute and debug programs that use interface to achieve abstractions.

CODE:-

OUTPUT:-
Experiment 11:
A. Code, execute and debug programs in java to handle checked and unchecked
exception.
i. Unchecked Exception

CODE:

OUTPUT:-

ii. Checked Exception

CODE:-

OUTPUT:-
B. Code, execute and debug programs in java read the content of the file and write the
content to another file.

CODE:-

OUTPUT:-
C. Code, execute and debug programs to illustrate throwing our own exceptions or user
defined exceptions.
CODE:-

OUTPUT:-
Experiment 12: Design an interface and implement and check
compliance with ISP.
CODE:-

OUTPUT:-
Experiment 13: Code, execute and debug programs to connect to
database through JDBC and perform basic DB operations.
Step1: In addition to JDK and Eclipse Environment, Install Xampp software for Apache server and MySql
service.

Stpe 2: Now open Xampp control panel to start Apcahe and MySql services as shown below. Then click on
MySql-admin button to open MySql[Link]

Step 3 : To connect MySql database in Java using Eclipse, follow below steps.

 Open Eclipse IDE and create in java project named JavaJDBC and click finish.
 Create new Java class with DB Test and click on the finish button.
 In order to connect Java program([Link]) with MySQL DataBase, we need to download and
include MySQL JDBC driver which is a JAR file, namely [Link].
 Now right click on Java JDBC project to include connector and go to properties.
 Click On java build path option-> libraries and then click on Add External JARS.
 Now select downloaded jar file [Link]. and click open.
 Click on OK and close.
Step 4: Now in browser go to myphpadmin page and create student table in test database with following fields as
shown below an click Save.

Connecting Java Program with MySQL Database


 After adding JAR file, connect the java program with MySQL Data
I. Establish connection using driver manger. get connection (String URL) and it returns a connection reference.
II. In String URL parameter write like this:

jdbc:mysql://localhost:3306/”test”,”root”,”password”
Where,

 Jdbc is the API.


 Mysql is the database.
 Localhost is the name of the server in which MySQL is running.
 3306 is the port number.
 Test is the Database name. If the database name is different , then replace this name with the correct
database
 Root is the user name of the MySQL database. It is the default user name for the MySQL database.
 Password is the password that is given while installing the MySQL database.
 SQL Exception might occur while connecting to the database, try-catch block must be used
Step 5: Write below code in DB Test class eclipse environment.

package sheetal;

import [Link].*;

public class expt13 {

public static void main(String[]args) {


String url = "jdbc:mysql://localhost:3306/soul";
String uName = "root";
String uPsw="";
try {
[Link]("[Link]");
Connection con = [Link](url,uName,uPsw);
[Link]("Java connection established!");
Statement st= [Link]();
String inst1 = "INSERT INTO `details`(`Regno`, `Name`, `Sem`) VALUES
('312','Sheetal','4')";
[Link](inst1);
String inst2 = "INSERT INTO `details`(`Regno`, `Name`, `Sem`) VALUES
('313','Sohan','4')";
[Link](inst2);

String qry = "SELECT*FROM details";


ResultSet rs = [Link](qry);
while([Link]()) {
int Regno = [Link]("Regno");
String Name = [Link]("Name");
int Sem = [Link]("Sem");
[Link](Regno+ " ; "+Name+ " ;" +Sem);

}
[Link]();
[Link]("Connection closed!");
}catch(Exception e) {
[Link]("Error while executing program: "+e);
}
}
}
OutPut:-

You might also like