This is a site for software engineers. I'll go posting a little tricks or how to do something in the different languages of programming that I know, and the main is Java. /* Este es un sitio para ingenieros de software. Iré creando entradas con pequeños trucos o cómo se hace algo en los diferentes lenguajes de programación que conozco, siendo el principal Java.*/
Wednesday, October 12, 2011
Introduction Java GUIs (New video)
I've created a new video to the introduction more short than the last and I've included audio. Although, the audio is in Spanish at this moment. I'll try to upload a new video with subtitles in English..
You can select the HD mode
Regular Expressions
Today, we are going to see a common concept that is used in more situations, these are regular expressions. Regular Expressions are some patterns that describe an string. These are very useful for validations.
E.g. to validate that an email is correct: email@domain.com (this is valid) / www.ccc.com (this is not valid).
We have a table with all features of regular expressions here:
Logical:
Character ranges:
Predefined character ranges:
Characters:
Limits:
Quantifiers:
Source: http://luauf.com/2008/05/03/expresiones-regulares-en-java/
E.g. to validate that an email is correct: email@domain.com (this is valid) / www.ccc.com (this is not valid).
We have a table with all features of regular expressions here:
Logical:
- x|y: x or y.
- xy: x followed by y
Character ranges:
- [abc]: Any of characters in brackets. Ranges can be spefified, for example, [ad] is equivalent to [abcd])
- [âbc]: Any character which is not in brackets.
Predefined character ranges:
- .: Any single character, except the newline.
- \d: Any digit character, equivalent to [0-9].
- \D: Any character that is not digit, equivalent to [^0-9].
- \s: Any single character in blank space (items, tabulations, break pages or newlines).
- \S: Any single character that is not a blank space.
- \w: Any alphanumeric character, including underscored, equivalent to [A-Za-z0-9_].
- \W: Any character that is not alphanumeric, equivalent to [^A-Za-z0-9_].
Characters:
- \f: Break pages.
- \n: Newlines.
- \r: Carriage return.
- \t: Tabulation.
Limits:
- ^: Beginning of input or line.
- $: End of input or line.
- \b: Limit of word (like an item or carriage return)
- \B: End of word.
Quantifiers:
- {n}: Exactly n appearances of the previous character.
- {n,m}: At least n and at most m appearances of the previous character.
- *:The previous character 0 or more times.
- +: The previous character 1 or more times.
- ?: The previous character at most 1. (that is, it indicate that the previous character is optional).
Source: http://luauf.com/2008/05/03/expresiones-regulares-en-java/
Sunday, October 2, 2011
Introduction to create Java GUI's with WindowBuilder PRO
Today, I've made the first video tutorial of a sequence about this topic.
I'll show you how to create java graphic user interfaces with the tool of Google: WindowBuilder PRO: http://code.google.com/intl/es/javadevtools/download-wbpro.html
I work with a Eclipse IDE: http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigosr1 You have to choose your compatibility version with your computer. It's x32 for me.
I'll show you how to create java graphic user interfaces with the tool of Google: WindowBuilder PRO: http://code.google.com/intl/es/javadevtools/download-wbpro.html
I work with a Eclipse IDE: http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigosr1 You have to choose your compatibility version with your computer. It's x32 for me.
Wednesday, September 28, 2011
My things of English
This is my new software that I'm developing now. That works with Hibernate so that controlling the data access to database of application. It's developed with Java. I've just powered by Google translator^^
Check it out!
Check it out!
Friday, September 23, 2011
Introduction to Hibernate - Part 1
Hibernate is a framework that helps to work with data access in databases and it improves the use of java objects persistence. The official page is http://www.hibernate.org/. Check out!
We have to look for our drive to the database that we're working. For example, I work with MySQL5 then I have to choose a Hibernate SQL dialect for that: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-optional-dialects
We need mapping our classes so that accessing to entities or tables of our working data base.
They exist two options to work in Hibernate for mapping:
I work with Eclipse IDE and I'll show the image captures there. (http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigor)
Let's go to start!
I always create a folder in my java projects to keep use libraries and I add them to build path.
Next, we create 4 packages: dao, model, utils and test.
Then we need to create a configuration file to Hibernate:
Now, we need to copy this in the hibernate.cfg.xml (it's the configuration file to Hibernate):
I'm going to explain some parts of this xml file: The first one, they're the connection parameters that you have to know:
We're mapping our class so that adding java objects persistence here. Client and product classes are in model package:
Have a nice week!
We have to look for our drive to the database that we're working. For example, I work with MySQL5 then I have to choose a Hibernate SQL dialect for that: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-optional-dialects
We need mapping our classes so that accessing to entities or tables of our working data base.
They exist two options to work in Hibernate for mapping:
- Using annotations (It's my favorite)
- Using XML file (I won't show it there. I don't like this)
So that Starting to work, we have to go to the page of downloads (http://www.hibernate.org/downloads) and to download the last release pack. Inside of this we find a lot of libraries, but at this moment we need these:
- hibernate-core-[version number].jar (It's the heart of Hibernate)
- hibernate-jpa-[version number]-api[version number].jar (this is for to use annotations)
- slf4j-api-[version number].jar (it's a log for java framework: http://www.slf4j.org/ and hibernate uses a log)
- slf4j-simple-[version number].jar
- mysql-connector-java-[version number].jar (it's mysql driver for java: http://www.mysql.com/downloads/mirror.php?id=403046#mirrors)
I work with Eclipse IDE and I'll show the image captures there. (http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigor)
Let's go to start!
I always create a folder in my java projects to keep use libraries and I add them to build path.
Next, we create 4 packages: dao, model, utils and test.
Then we need to create a configuration file to Hibernate:
Now, we need to copy this in the hibernate.cfg.xml (it's the configuration file to Hibernate):
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">com.mysql.jdbc.Driver jdbc:mysql://localhost/yourdatabase youruser yourpassword 1 org.hibernate.dialect.MySQL5Dialect true <mapping class="model.Client"/> <mapping class="model.Product"/>
I'm going to explain some parts of this xml file: The first one, they're the connection parameters that you have to know:
com.mysql.jdbc.Driver jdbc:mysql://localhost/yourdatabase youruser yourpassword
- yourdatabase: it's the name of your database
- youruser: it's the name of your user that you use to connect to the database
- yourpassword: it's the password of your user
We're mapping our class so that adding java objects persistence here. Client and product classes are in model package:
<mapping class="model.Client"/> <mapping class="model.Product"/>Eventually, we have done Hibernate initial configuration. In the next part, I'll continue to explain how to access to the database very easy, because Hibernate help us!!!!
Have a nice week!
Welcome - How to copy files in Java
Welcome to my site. This is the first post and I want to write how to copy files in Java.
We need a source file and a destination file:
We need a source file and a destination file:
File source = new File("source.mp3");
File destination = new File("destination.mp3");
Next, we have to create an input stream and an output stream, reading the input file and writing in the output file.
This is the code:
try {
InputStream in = new FileInputStream(source);
OutputStream out = new FileOutputStream(destination);
// to read while data exist in the input stream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// to close opened files
in.close();
out.close();
}
catch (FileNotFoundException e1) {
e1.printStackTrace();
}
catch (IOException e2) {
e2.printStackTrace();
}
}
I hope you like this and I've helped,
Regards!
Subscribe to:
Posts (Atom)




