Jul 17

How to use conditional breakpoint in eclipse (step by step)

We can say no developers in the world who developing without debugging his/her code. We have lot of debugging options to make use the debugging option more effectively.

Here we are going to see how we can debug with conditional breakpoints.
Step 1:
Below is the very simple program to explain the conditional breakpoint,

package in.javadomain;
public class ConditionalBreakpoint {
	public static void main(String[] args) {
		boolean value = false;
		value=true;
		System.out.println("Debug, if condition given in the breakpoint condition satisfies ");
	}

}

Step 2:
Put the breakpoint in the sysout line of the above program.

Step 3:
Right click on the breakpoint and click breakpoint properties (or) control+double click on the breakpoint, then click the Breakpoint properties -> Enable the Conditional checkbox -> click suspend when true radio button.
Then add the condition,
setting breakpoint

Now Run as debug and see the output for both the conditions (value==false and value==true) below,

when value==true
conditional breakpoint

when value==false
conditional_breakpoint_false

Note:
After changing the breakpoint conditions, ensure you have saved it.

Recommended Java Books:

Jul 17

Main Method auto generation in java Eclipse example

As we know main method is first method java begins its execution. That main method we can generate using two ways in eclipse
Way 1:

While creating the class, we can enable the “public static main method(String[] args) checkbox”,

AutoGenCreate

Way 2:

If we have created the class without enabling the checkbox, then no need to delete and create it again. We can simply create simply typing main with ctrl+shift.

AutoGenCtrlShift

Recommended Books:

Jul 14

Java With MySQL Insert Example

Download the users_test table:
Users_test table – Mysql download

Loading the Mysql connection:

	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

Fetching the records: [Select]

	public void insertUsers(Connection conn, String email,String full_name,String mobile,String pass,String access){
		System.out.println("Insert started!");
		String query = " insert into users_test (mobile,email,pass,full_name, access) values (?, ?, ?, ?,?)";
		PreparedStatement preparedStmt;
		try {
			preparedStmt = conn.prepareStatement(query);
			preparedStmt.setString(1, mobile);
			preparedStmt.setString(2, email);
			preparedStmt.setString(3, pass);
			preparedStmt.setString(4, full_name);
			preparedStmt.setString(5, access);
			preparedStmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		System.out.println("Insertion Done!");
	}

Java with Mysql Insert Full Program:

package in.javadomain;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author Naveen class to connect java with mysql and fetching mysql records
 *         using java
 */
public class JavaMySQL {
	/**
	 * Main method first get the mysql connection then it will fetch the records
	 */
	public static void main(String[] args) {
		String email = "me@javadomain.in";
		String full_name = "naveenkumar";
		String mobile = "9597470873";
		String pass = "testpass";
		String access = "1";
		JavaMySQL javaMySQL = new JavaMySQL();
		// Getting the mysql Connection
		Connection conn = javaMySQL.LoadDriver();
		// Fetching the mysql table records
		javaMySQL.insertUsers(conn, email, full_name, mobile, pass, access);
	}

	/**
	 * Loads the mysql connection with the given username, password, database
	 * and mysql jar driver
	 * 
	 * @return Connection
	 */
	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

	/**
	 * @param conn
	 * @param email
	 * @param full_name
	 * @param mobile
	 * @param pass
	 * @param access
	 *            all the above params are inserted using the prepared statement
	 */
	public void insertUsers(Connection conn, String email, String full_name,
			String mobile, String pass, String access) {
		System.out.println("Insert started!");
		String query = " insert into users_test (mobile,email,pass,full_name, access) values (?, ?, ?, ?,?)";
		PreparedStatement preparedStmt;
		try {
			preparedStmt = conn.prepareStatement(query);
			preparedStmt.setString(1, mobile);
			preparedStmt.setString(2, email);
			preparedStmt.setString(3, pass);
			preparedStmt.setString(4, full_name);
			preparedStmt.setString(5, access);
			preparedStmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		System.out.println("Insertion Done!");
	}

}

Output:

Insert started!
Insertion Done!

Download the Source code:
Java With Mysql Insert

Note:
1. Do not forget to add the mysql java connection jar.
2. Mention the username, password and database name correctly.
3. Mention the column names, column name types and table names correctly.

Java Recommended Books:

Jul 14

Java With MySQL Select Example

Download the users_test table:
Users_test table – Mysql download

Loading the Mysql connection:

	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

Fetching the records: [Select]

public void getRecords(Connection connection) {
		String query = "SELECT * FROM users_test";
		Statement createStatement;
		try {
			createStatement = connection.createStatement();
			ResultSet resultSet = createStatement.executeQuery(query);
			while (resultSet.next()) {
				String mobile = resultSet.getString("mobile");
				String full_name = resultSet.getString("full_name");
				String email = resultSet.getString("email");
				System.out.format("%s, %s, %s\n", full_name, email, mobile);
			}
			createStatement.close();
		} catch (SQLException sqlException) {
			sqlException.printStackTrace();
		}

	}

Mysql With Select Full Program:

package in.javadomain;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Naveen 
 * class to connect java with mysql and fetching mysql records
 *         using java
 */
public class JavaMySQL {
	/**
	 * Main method first get the mysql connection then it will fetch the records
	 */
	public static void main(String[] args) {
		JavaMySQL javaMySQL = new JavaMySQL();
		// Getting the mysql Connection
		Connection conn = javaMySQL.LoadDriver();
		// Fetching the mysql table records
		javaMySQL.getRecords(conn);
	}

	/**
	 * Loads the mysql connection with the given username, password, database
	 * and mysql jar driver
	 * 
	 * @return Connection
	 */
	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

	/**
	 * @param connection
	 *            to create the mysql connection Records fetched using create
	 *            statement
	 */
	public void getRecords(Connection connection) {
		String query = "SELECT * FROM users_test";
		Statement createStatement;
		try {
			createStatement = connection.createStatement();
			ResultSet resultSet = createStatement.executeQuery(query);
			while (resultSet.next()) {
				String mobile = resultSet.getString("mobile");
				String full_name = resultSet.getString("full_name");
				String email = resultSet.getString("email");
				System.out.format("%s, %s, %s\n", full_name, email, mobile);
			}
			createStatement.close();
		} catch (SQLException sqlException) {
			sqlException.printStackTrace();
		}

	}
}

Output:

Hems, Hems@Hems.com, 7777777777
Aravind, aravind@aravind.com, 7777788888
Chudar, chudar@chudar.com, 8888888888
Naveen, naveen@naveen.com, 9999999999

Download the Source code:
Java with Mysql Select

Note:
1. Do not forget to add the mysql java connection jar.
2. Mention the username, password and database name correctly.
3. Mention the column names, column name types and table names correctly.

Java Recommended Books:

May 12

How to increase the JVM heap size in web sphere?

How to increase the JVM heap size in web sphere?

1. By Server Console

Servers -> Server Types -> WebSphere application servers -> Java and Process Management -> Process definition -> Java Virtual Machine -> Configuration

Enter the values in,

 Initial heap size and Maximum heap size text boxes.

(256m and 1024m) are recommended.

2. By Server.xml file:

C:\Program Files\IBM\SDP\runtimes\base_v7\profiles\AppSrv01\config\cells\Node03Cell\nodes\Node03\servers\server1

Open the server.xml file and search with heap,

<jvmEntries initialHeapSize="256m" maximumHeapSize="1024m">

Change the above values accordingly.

May 12

[Solved] Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at

Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at
session_start() should be used first line in the php code and php code should exist even above the html tag.

session1.php:

<html>
<?php
session_start();
$check = 0;
if(isset($_SESSION['var1'])){
$check =1;
}
?>
<head>
</head>
<body>
<?php
if($check==1){
?>
With Session
<?php
}else{
?>
Without Session.
<a href="session2.php">Click here to initate the session</a>
<?php
}
?>
</body>
</html>

session2.php:

<?php
session_start();
$_SESSION['var1']='Javadomain.in';
header ("Location: session1.php");
?>

Output:
without session issue

As discussed already, if you move the php part to before the html tag, then we will not be getting the issue.

session1.php:

<?php
session_start();
$check = 0;
if(isset($_SESSION['var1'])){
$check =1;
}
?>
<html>
<head>
</head>
<body>
<?php
if($check==1){
?>
With Session
<?php
}else{
?>
Without Session.
<a href="session2.php">Click here to initate the session</a>
<?php
}
?>
</body>
</html>

session2.php:

<?php
session_start();
$_SESSION['var1']='Javadomain.in';
header ("Location: session1.php");
?>

Now output is,
without session

PHP Recommended Books:

May 02

Header, Body and Footer Html CSS Example

Header, Body and Footer Html CSS Example:

Html Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Learn</title>
</head>
<body>
<div id="container">
<div class="header">Header</div>
    <div class="mainbody">
    Body
    </div>
    <div class="footer">Footer</div>
</div>
</body>
</html>

CSS Code:

<style type="text/css">
.container {
    width: 500px;
    max-height: 500px;
    margin: 10px;
    border: 1px solid #fff;
    background-color: #ffffff;
    box-shadow: 0px 2px 7px #292929;
    -moz-box-shadow: 0px 2px 7px #292929;
    -webkit-box-shadow: 0px 2px 7px #292929;
    border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
}
.mainbody,
.header,
.footer {
    padding: 5px;
}
.mainbody {
    margin-top: 0;
    min-height: 150px;
    max-height: 540px;
    overflow: auto;
	height:499px;
	text-align:center;
}
.header {
    height: 40px;
    border-bottom: 1px solid #EEE;
    background-color: #ffffff;
    height: 40px;
    -webkit-border-top-left-radius: 5px;
    -webkit-border-top-right-radius: 5px;
    -moz-border-radius-topleft: 5px;
    -moz-border-radius-topright: 5px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
		width:100%;
}
.footer {
    height: 40px;
    background-color: whiteSmoke;
    border-top: 1px solid #DDD;
    -webkit-border-bottom-left-radius: 5px;
    -webkit-border-bottom-right-radius: 5px;
    -moz-border-radius-bottomleft: 5px;
    -moz-border-radius-bottomright: 5px;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
	width:100%;
}
 

</style>

Output:

header, body and footer

Recommended Html/Css/jQuery Books:

May 02

Header, Body Left, Body Right and Footer Html CSS Example

Header, Body Left, Body Right and Footer Html CSS Example:

Html Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Learn</title>
</head>
<body>
<div id="container">
<div class="header">Header</div>
    <div class="mainbody">
       <div class="left_div"> Body Left</div>
       <div class="right_div"> Body Right</div>
    </div>
    <div class="footer">Footer</div>
</div>
</body>
</html>

CSS Code:

<style type="text/css">
.container {
    width: 500px;
    max-height: 500px;
    margin: 10px;
    border: 1px solid #fff;
    background-color: #ffffff;
    box-shadow: 0px 2px 7px #292929;
    -moz-box-shadow: 0px 2px 7px #292929;
    -webkit-box-shadow: 0px 2px 7px #292929;
    border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
}
.mainbody,
.header,
.footer {
    padding: 5px;
}
.mainbody {
    margin-top: 0;
    min-height: 150px;
    max-height: 540px;
    overflow: auto;
	height:499px;
	text-align:center;
}
.header {
    height: 40px;
    border-bottom: 1px solid #EEE;
    background-color: #ffffff;
    height: 40px;
    -webkit-border-top-left-radius: 5px;
    -webkit-border-top-right-radius: 5px;
    -moz-border-radius-topleft: 5px;
    -moz-border-radius-topright: 5px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
		width:100%;
}
.footer {
    height: 40px;
    background-color: whiteSmoke;
    border-top: 1px solid #DDD;
    -webkit-border-bottom-left-radius: 5px;
    -webkit-border-bottom-right-radius: 5px;
    -moz-border-radius-bottomleft: 5px;
    -moz-border-radius-bottomright: 5px;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
	width:100%;
}
.left_div{
	border:1px solid #000; 
	display:inline-block;
	float: left;
    height: 99%;
    width: 49.5%;
}
.right_div{
border:1px solid #000; 
	display:inline-block;
	float: right;
    height: 99%;
    width: 49.5%;
}

</style>

Output:
header, body left, body right and footer

Download Zip:
Learn

Recommended Html/Css/jQuery Books:

May 02

jQuery select onchange Example

jQuery select onchange Example:

Select dropdown onchange can be done using both javascript and jQuery.

We have done here using jQuery. Please find the program below,

Select Onchange jQuery Sample:

<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$( '.left_select').change(function() {
alert($('.left_select').val());
});
});
</script>
</head>
<body>
<div class="dropdown">
<select class="left_select">
<option value="java" selected>Java</option>
<option value="php">PHP</option>
<option value="javascript">JavaScript</option>
</select>
</div>
</body>
</html>

Output:
jquery select onchange

Recommended jQuery Books:

May 02

Javascript Alert Message Color Example

Javascript Alert Message Color Example:

In Javascript we can not customize the alert contents/messages like font color, font type, bold, italic etc…

If you want to achieve the same, you can go for jquery scripts.

We have tried the alert message with color using the jQuery. You can find the jsfiddle below,

jsFiddle Sample:

Thanks for reading this post..!!