Review of basic Java Standard Edition (আস্তে আস্তে জাভা শিখি)

Here is a list of basics about Java what we must know.

  • Code Structure
    [public static void main(String a[]) , class name]
  • Difference between C, C++ and JAVA
  • Why Java is better than other programming languages?
  • What do you mean by OOP?
  • Does Java supports OOP?
  • Define these terms
    • inheritence
    • encapsulation
    • polymorphism
  • Access Specifiers
  • Friend function
  • Friend Class
  • Super class, Sub class
  • Difference between abstract class and interface
  • implement or extend
  • Virtual class, virtual function
  • Differences between Function Overloading & Operator overloading
  • String Manipulation

As per my knowledge, If we learn these things with practicing some code related to these topics, we can start for any kind of development or to take in part in java related exams.

I am sorry to say that I can’t share these things right now. But in near future, a brief of these topics will be here.

[polldaddy poll=7717806]

API vs Library vs SDK [Self Note]

A Library is a collection of code that we can call from our own code, to help us do things more quickly/easily. For example, Let there is a class for pagination, and we just call the method of that class which does the pagination work.

An API (application programming interface) is a term meaning the functions/methods in a library that we can call to ask it to do things for us – the interface to the library.

An SDK ( (software development kit) is a library (often with extra tool applications, data files and sample code) that aid us in developing code that uses a particular system (e.g. extension code for using features of an operating system (Windows SDK), drawing 3D graphics via a particular system (DirectX SDK), writing add-ins to extend other applications (Office SDK), or writing code to make a device like an Arduino or a mobile phone do what we want)

[Collected]

HAPPY NEW YEAR, 2014 🙂

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

 

 

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

Programming,Mathematics and Newbies

I am not sure if I am the right person or not to write this. Now I am going to share something with you that I know. Yes, These all are about the “Importance of programming” for the newbies. Here I will inspire you to be a good programmer, not the “Boss” of one of the C/C++/JAVA/PHP or web developments and many others. Being a programmer means being well-developped logically i.e mathematically who can use any language whatever it is,to solve a real life problem efficiently. As I know, and I think everyone will agree with me that mathematics is the one and only way to solve any real-life problems (which are not defined impossible by the experts). As a Bangladeshi , It is a matter of shame that we are far from other countries in the race of mathematics which is an obstacle in the race of technological development. If you say,“God didn’t give me a good brain,what can I do?”, I will not agree with you. As my opinion, It’s all about practice.We,the lazy people,passes our time doing nothing. A Proverb is said to be “Practice makes a man perfect”.
So, What are you thinking now? Wanna start practicing mathematics and programming now? An Eiffel Tower can not be built in one night.So,you have to spend some of your precious times to gain the power to control your PC,the coming world of technology.now what to do? Let’s go through some steps.

Step 1:
Find some books on basic mathematics/Number theory.
* Elementary Number Theory with Applications
-Thomas Koshy
*Concrete mathematics
-Donald Knuth

Step 2:
Select an programming language to implement those mathematics you have learnt. Now-a-days, C,C++,JAVA are the most popular and widely used languages. If you are newbie ,I will suggest you to learn C because it is the most efficient and easiest language. Most of important softwares and Some of operating systems are developed in C.
If you are not a student of CSE background,don’t be afraid,because you can learn it easily. You can learn this from this book. Ya, all the newbies who are related to CSE,this book is also for you too.
*Art Of Programming contest
* Programming with C
-Bayron Gottfried
Step 3:
Now you have learnt a little bit of mathematics, at least one of the programming languages, it’s time go now. What to do? You have to solve problems.There are many Online judges,In which there are thousands of problem descriptions with the facility to judge your solution ,is it ok or not,I will mention “Is the solution efficient or not”.
As you are newbie I will suggest you to use UVA at first . For this you have to open an account on this site.you can browse problems of their site. The first job of you to read the problem carefully,find the solution ,then code it.
What is coding? If you have learnt any of the programming languages, don’t ask it again.You have to write a code which will take input and provide with outputs as the problem description. After login you have to submit your solution to the onlinejudge.That machine will judge your solution in RE (runtime error),TE (time limit exceede),WA (wrong answer),PA (presentation error) and AC (accepted).
When submitting,you have take some measures which will be described below.
You can track your progress from here .
After solving some of problems,you should not be limited only in a single judges.

Here are some others OJs.
*SPOJ
*Light OJ
*Topcoder
*Codeforces

Here are some of websites/blogs which can be useful for you too.
*Smilitude
* UVA FORUM

Problems solving with C:
A sample code for submitting a problem is given below.
[code]
#include<stdio.h>
int main()
{
int testcase,input,I,j,k;
while(scanf(“%d”,&input)==1)
{
//your solution exists here
If(input ==2)
printf(“two”);
else
printf(“Not two”);
}
return 0;
}
[/code]

Now practice problem solving. You must attend free online contests to judge yourself.

For any kind of help or suggestions
I am here

JAVA [creating Jar files]

To create a jar file execute this command given below

[code]
jar cf jar-file input-file(s)
[/code]
//input files are .class files and extra files you have used like music,jars etc.

For more you can see this Creating JAR files
After creation you must specify the main class using manifest.

Ways to update a jar file with manifest……
I have created a text file as manifest like aaa.txt which contains

[Code]Main-class: Mainclassname
[/Code]
//a new line or enter must be pressed after Mainclassname before saving

Updating a jar file with main class, you have to move the jar file to the BIN folder of JDK. Then using the command propmt executed the commands given below:

[code]
jar umf aaa.txt calender.jar
jar xvf calender.jar
type META-INFMANIFEST.MF
[/code]
Now double-click on your JAR file….

Thanking you,
Ujjal

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]