Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/default-filters.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/default-filters.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/class-wp-theme.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/class-wp-theme.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/class-wp-styles.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/class-wp-styles.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/rest-api/class-wp-rest-request.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/rest-api/class-wp-rest-request.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/block-supports/duotone.php on line 1

Warning: Uninitialized string offset 0 in /home/ujjal/public_html/blog/wp-includes/block-supports/duotone.php on line 1

Warning: Cannot modify header information - headers already sent by (output started at /home/ujjal/public_html/blog/wp-includes/default-filters.php:1) in /home/ujjal/public_html/blog/wp-includes/feed-rss2.php on line 8
Programming with JAVA – Diary of Ujjal https://blog.ujjal.net Software Development Lead, Very good listener, Tech enthusiastic, Movie & Series freak Sat, 14 Feb 2015 10:38:34 +0000 en-US hourly 1 https://wordpress.org/?v=6.2.6 Converting a .JAR Into .EXE for WIndows user https://blog.ujjal.net/?p=186&utm_source=rss&utm_medium=rss&utm_campaign=converting-a-jar-into-exe-for-windows-user https://blog.ujjal.net/?p=186#respond Wed, 01 Aug 2012 16:52:56 +0000 http://ujjalruet.wordpress.com/?p=186 Continue reading "Converting a .JAR Into .EXE for WIndows user"

]]>
We, the Java developers, develop softwares using Java because of it’s platform independency . Though now-a-days JDK is available to users,we usually provide JAR file of the software to the user.So, users can start it with only a double click. But  still some windows users prefere .exe version of that software. So, now I am going to tell you about a software by which we can convert a .jar file to .exe for windows user.

Before starting this we must read these two posts carefully.

Click here

We will use Jar to exe convert wizard 1.8 to convert  our jar files to exe.

 

Step 1 : Install the software and run the wizard.

Step 2:  Browse project.jar and press next.

Step 3: Select Console application or Windows gui application

Step 4: Select the Main class from where the software will start and keep “select a picture for splash window” blank.

Step 5: enable Support System tray and disable all others disable. [or, you can change as your requirements.]

Step 6: Add others Jars you have used like mysql-connector.jar . Usually these are on project/dist/lib/ if you are using Netbeans IDE. 

Step 6:  press Next and Finish.

Step 7 : We got the converted exe file of our jar file.

 

Thanks for reading this post.

Ujjal

 

 

]]>
https://blog.ujjal.net/?feed=rss2&p=186 0
Creating AutoBack Up of MySQL Database using JAVA OR PHP ( পিএচপি অথবা জাভা তে কিভাবে মাইএসকিউএল ডাটাবেজ এর অটোমেটিক ব্যাকআপ করতে হয় ) https://blog.ujjal.net/?p=170&utm_source=rss&utm_medium=rss&utm_campaign=creating-autoback-up-of-database-using-java https://blog.ujjal.net/?p=170#comments Wed, 02 May 2012 15:35:55 +0000 http://ujjalruet.wordpress.com/?p=170 Continue reading "Creating AutoBack Up of MySQL Database using JAVA OR PHP ( পিএচপি অথবা জাভা তে কিভাবে মাইএসকিউএল ডাটাবেজ এর অটোমেটিক ব্যাকআপ করতে হয় )"

]]>
It is usual that we need to backup the database in software development (specially in Enterprise Software,web applications ) Database is very important which contains all the information about the organization. Last night I have coded a auto backup script in both JAVA and PHP. Here I am gonna post them below with comment.

Code Written in JAVA

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Ujjal Suttra Dhar
 */

class create_backup{

    String database = "your_database_name",  user = "root", password = "pass";
    Connection m_Connection = null;
    Statement m_Statement = null;
    ResultSet m_ResultSet;
    String m_Driver = "com.mysql.jdbc.Driver";
    String m_Url = "jdbc:mysql://localhost:3306/" + database;

    public create_backup(){

        /*Eshtablishment of Connection of java code with MySQL using JDBC
         You must read my previous post to know further about this. 
         */
        try {
            Class.forName(m_Driver);
            m_Connection = DriverManager.getConnection(m_Url, user, password);
            //Create Statement object
            m_Statement = m_Connection.createStatement();

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        try {
            //Database will be stored in filename.sql which can be import on MySQl as backup
            BufferedWriter  out = new BufferedWriter(new FileWriter("kernel_school.sql"));


            //Now here is the informations about the database of which backup will be created
            String dump = "C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump " //Path to mysql
                    + "--host=localhost" //Mysql hostname
                    + "--port=3306" //Mysql portnumber
                    + "--user=root" //Mysql username
                    + "--password=pass" //Mysql password
                    + "--add-drop-table" //Add a DROP TABLE statement before each CREATE TABLE statement
                    + "--add-drop-database" //Add a DROP DATABASE statement before each CREATE DATABASE statement
                    + "--complete-insert" //Use complete INSERT statements that include column names.
                    + "--extended-insert" //Use multiple-row INSERT syntax that include several VALUES lists
                    + "kernel_school";                  //Mysql databasename


            //executing the command through process.
            Process run = Runtime.getRuntime().exec(dump);


            /*resultant SQL informations are here on the br which can be read line by line .
            And at the same time it will be written on another sql file.*/
            InputStream in = run.getInputStream();
            InputStreamReader isr = new InputStreamReader(in);
            BufferedReader br = new BufferedReader(isr);
            String line = null;

            while ((line = br.readLine())!=null) {
                 out.write(line);
                 out.newLine();
            }

       out.flush(); // must flush or close the file after completing the task.
        // int exitVal = run.waitFor();//when exitVal is ,then the process is completed

        } catch (Throwable t) {
            t.printStackTrace();
      }

    }//constructor
 } // class



public class autobackup {
    public static void main(String a[]){
            new create_backup();
    }
}

Code Written in PHP

]]>
https://blog.ujjal.net/?feed=rss2&p=170 2
Minimum Spanning Tree in JAVA https://blog.ujjal.net/?p=134&utm_source=rss&utm_medium=rss&utm_campaign=minimum-spanning-tree-in-java https://blog.ujjal.net/?p=134#comments Wed, 09 Nov 2011 09:40:32 +0000 http://ujjalruet.wordpress.com/?p=134 Continue reading "Minimum Spanning Tree in JAVA"

]]>
বন্ধুরা অনেক আগে থেকে ফ্রিলান্সিং করলেও আমি করি নাই। আমার ইচ্ছা ছিল আগে প্রোফাইল ভাল করব যাতে বিড করলেই কাজ পাই। গত কাল রাতে হটাত ব্রাওজার এর বুকমার্ক দেখতে দেখতে হটাত চোখ পড়লো Ezdia নামক একটি সাইট এ। ঢুকলাম । প্রথমেই যার ওপর চোখ পড়ল তা হল minimum spanning tree এর implementation JAVA দিয়ে করতে হবে। ভাবলাম কোড তো C++ এ করাই আসে।JAVA তে convert করতে র কত সময় লাগবে। Bid করলাম । কাজ টা পেয়েও গেলাম। JAVA অনেকদিন দেখি নাই।তাই ভুলে গেসিলাম কিছু জিনিস। তাই করতে কিছুটা সময় বেসি লাগল। সব মিলিয়ে ২.৫০ ঘণ্টায় কাজ টা delivery দিলাম।

যাই হোক,কাজটা client এর পছন্দও হল। কিন্তু এখন পর্যন্ত উনি আমাকে pay করেন নাই। প্রথম কাজেই ধরা খাইলাম। ব্যাপার না। আরও হবে। আপাতত সেই কাজ তাই আপনাকে দেখাচ্ছি।

updater after 2 days
দেরীতে হলেও ফিডব্যাক পাওয়া গেল।টাকাও।

Here is the input/output format

Input

Input starts with an integer T, denoting the number of test cases.

Each case begins with an integer n denoting the number of nodes. Then there will be n lines, each having n space separated integers, denoting the lengths of two connected nodes. Each length will be between 0 and 100.

Output:
If generating a tree is impossible ,then output is -1 else the minimal cost.

Example:

Input:
3

2
27 26
1 52

4
0 10 10 0
0 0 1 1
0 0 0 2
0 0 0 0

4
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0

Output:
Case 1: 105
Case 2: 12
Case 3: -1

[code]

import java.util.*;

class edge {

public int dist;
int st, end;

edge(int i, int j, int k) {
this.st = i;
this.end = j;
this.dist = k;
}
};

class exe {

public edge road[] = new edge[3000];
edge ce;
int arr[][] = new int[52][52];
int rank[] = new int[52];
int par[] = new int[52];
double ans = 0;
int min1 = 0, max1 = 0;
int cost;
int C, R, cnt, E;

int find(int i) {
if (i != par[i]) {
par[i] = find(par[par[i]]);
}
return par[i];
}

void link(int x, int y) {
if (rank[x] > rank[y]) {
par[y] = x;
} else {
par[x] = y;
if (rank[x] == rank[y]) {
rank[y]++;
}
}

}

void kruskal() {
int i = 0, j = 0, u, v, flag = 0;
System.out.println("Tree diagram is ");
for (i = 0; j < C – 1 && i < E; i++) {
u = find(road[i].st);
v = find(road[i].end);
if (u == v) {
continue;
}
link(u, v);
flag = 1;
j++;
min1 += road[i].dist;

System.out.println(road[i].st + "->" + road[i].end + " cost is " + road[i].dist);

}
if (j < C – 1) {
System.out.println(-1);
} else {
//System.out.println(max1-min1);
System.out.println("Minimal Cost is " + min1);
}

} //krus

public exe() {

int i, j, k, T, cs = 0;

Scanner s = new Scanner(System.in);

T = s.nextInt();

while (true) {
if (T == 0) {
break;
}

C = s.nextInt();

for (i = 1; i <= C; i++) {
par[i] = i;
rank[i] = 0;
}

k = 0;
max1 = 0;
for (i = 1; i <= C; i++) {
for (j = 1; j <= C; j++) {
arr[i][j] = s.nextInt();

if (arr[i][j] != 0 && i != j) {
road[k] = new edge(i, j, arr[i][j]);
k++;
}
max1 += arr[i][j];
}
}

E = k;
for (i = 0; i < E – 1; i++) {
for (j = i + 1; j < E; j++) {
if (road[i].dist > road[j].dist) {
ce = road[i];
road[i] = road[j];
road[j] = ce;
}

}
}

min1 = 0;

System.out.print("Case " + (++cs) + ": ");
kruskal();

T–;
} // while

}
}//class exe

public class Ezdia1 {

public static void main(String ars[]) {
try {
exe object = new exe();
} catch (Exception p) {
}

}
//main
}//class

[/code]

ধন্যবাদ সবাইকে।

]]>
https://blog.ujjal.net/?feed=rss2&p=134 1
Connecting with MySQL in JAVA https://blog.ujjal.net/?p=35&utm_source=rss&utm_medium=rss&utm_campaign=connecting-with-mysql-in-java https://blog.ujjal.net/?p=35#respond Sun, 03 Apr 2011 14:23:48 +0000 http://ujjalruet.wordpress.com/?p=35 Continue reading "Connecting with MySQL in JAVA"

]]>
Sometimes we need to use database(MySQL).So,we must connect our interpreter to the existing MySQl.For this we need JDBC driver to install it.In netbeans IDE jdbc driver is built in.But to make this working, we must have a mysql connector,which is a jar file in our system.

We must download a mysql-connector-java-5.0.8-bin.jar and keep it to
C:Program FilesJavajdk1.6.0_01jrelibext

In java programming, before coding we must established a connection between interpreter and MySQL.

at first we must import some built in packages.they are:
[code]
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;

//now finally in our main job i.e establishing the connection

Connection m_Connection = null;
Statement m_Statement = null;
ResultSet m_ResultSet = null;

String m_Driver ="com.mysql.jdbc.Driver";
String m_Url = "jdbc:mysql://localhost:3306/databasename";

//Loading driver
try {
Class.forName(m_Driver);
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
}

String query = "";
try {

//Create connection object
m_Connection = DriverManager.getConnection(m_Url, user, password);

//Create Statement object
m_Statement = m_Connection.createStatement();
query = "SELECT * FROM ";
query+=tablename;

//Execute the query
m_ResultSet = m_Statement.executeQuery(query);
String s,t="";

//Loop through the results
while (m_ResultSet.next()) {

s=m_ResultSet.getString(1); //here 1 means value of first coloumn

}//end for while loop

}
catch (SQLException ex) {
ex.printStackTrace();
System.out.println(query);

}
catch (Exception e) {
System.err.println("Error: " + e.getMessage());

}

finally {

try {
if (m_ResultSet != null)
m_ResultSet.close();
if (m_Statement != null)
m_Statement.close();
if (m_Connection != null)
m_Connection.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
[/code]

]]>
https://blog.ujjal.net/?feed=rss2&p=35 0
Links https://blog.ujjal.net/?p=27&utm_source=rss&utm_medium=rss&utm_campaign=links https://blog.ujjal.net/?p=27#respond Sat, 02 Apr 2011 06:22:45 +0000 http://ujjalruet.wordpress.com/?p=27 JAVA
Java-forums
Scanning an Image from Scanner[JAVA]
JAR File Specificaton
Download Java books
java-networking(1)
java-networking(2)
Java Database Connectivity

Programming
Track your progress
Find .EXE of Accepted Solutions of Uva problems
Uva
SPOJ
Codeforce
For more OJ and resources

]]>
https://blog.ujjal.net/?feed=rss2&p=27 0
JAVA in online programming [Uva] https://blog.ujjal.net/?p=17&utm_source=rss&utm_medium=rss&utm_campaign=java-in-online-programming-uva https://blog.ujjal.net/?p=17#respond Fri, 01 Apr 2011 07:24:18 +0000 http://ujjalruet.wordpress.com/?p=17 Continue reading "JAVA in online programming [Uva]"

]]>
Sometimes we try to use Java in online programming like Uva.Though it is bad in Uva,some programmers think that it is helpful to use Java in contests.

We know that Java support in the judge is bad. But if you want to try it, take this considerations into account.

The Java programs submitted must be in a single source code (not .class) file. Really, they are compiled and run as native applications using the gcj compiler. They must read and write the standard input/output, as the other languajes. Note that java::io use is restricted; this implies that some features (for example, to create a DataInputStream variable with System.in as argument, in order to use readLine to read strings from the standard input) are not available. Also, network and other functions are not allowed. Threads are also not ready. However, methods from math, util and some other common packages are authorized. If you find any useful function for a scientific program not available, please contact Uva about it.

I am posting here my code of Uva 10055 so that you can get an idea about submitting solutions using java…


// import ::io is restricted

import java.util.*;

class Main //class name must be Main and non-public
{
public static void main(String[] a){
long hn,mn;

Scanner s=new Scanner(System.in);

while(s.hasNext()){
hn=s.nextLong();
mn=s.nextLong();

if( hn<mn )
System.out.println(""+(mn-hn));
else
System.out.println(""+(hn-mn));
}
}
}

]]>
https://blog.ujjal.net/?feed=rss2&p=17 0
Big Number problem in JAVA in programming contest https://blog.ujjal.net/?p=7&utm_source=rss&utm_medium=rss&utm_campaign=big-number-problem-in-java-in-programming-contest https://blog.ujjal.net/?p=7#comments Thu, 31 Mar 2011 12:09:38 +0000 http://ujjalruet.wordpress.com/?p=6 Continue reading "Big Number problem in JAVA in programming contest"

]]>
Bignumber problem can be solved easily using BigInteger class in java.Here is a sample for doing this….
[code]
import java.math.BigInteger;

public class BIG
{
public static void main(String[] args)
{
//initialization
BigInteger N1 = new BigInteger ("1000000000000000000");
BigInteger N2 = new BigInteger ("123456789123");
BigInteger N3 = new BigInteger ("50000000000");
//Math operations
BigInteger mult = N1.multiply(N2); //This is how to send arguments in bigint functions
BigInteger add = N1.add(N2);
BigInteger div= N1.divide(N2);
BigInteger substract1 = N1.subtract(N2); //N1-N2
BigInteger substract2 = N2.subtract(N1); //N2-N1
BigInteger gcd = N1.gcd(N3);
//Printing output
System.out.println("Mult " + mult);
System.out.println("add " + add);
System.out.println("div " + div);
System.out.println("substract1 " + substract1);
System.out.println("substract2 " + substract2);
System.out.println("gcd N1 N3 " + gcd);
}
}
[/code]
There are some more built in functions:

BigInteger.ONE; (==1)
BigInteger.ZERO;(==0)
A.abs();
A.add(N);
A.divide(N);
A.divideAndRemainder(N); (returns an array)
A.max(N);
A.min(N);
A.mod(N);
A.multiply(N);
A.remainder(N);
A.signum(N);

A.doubleValue();
A.floatValue();
A.intValue();
A.longValue();
A.toString();
A.compareTo(N)

converting an integer to bigint
BigInteger A = BigInteger.valueOf(20000);
You can take input using scanner just as you input int,long etc.

]]>
https://blog.ujjal.net/?feed=rss2&p=7 2