Πέμπτη 18 Δεκεμβρίου 2008

Java Generics

Java Generics
http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html

pdf tutorial
http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

Τρίτη 9 Δεκεμβρίου 2008

Subclipse

http://subclipse.tigris.org/

Subclipse is an Eclipse Team Provider plug-in providing support for Subversion within the Eclipse IDE. The software is released under the Eclipse Public License (EPL) 1.0 open source license.

Παρασκευή 21 Νοεμβρίου 2008

Τετάρτη 19 Νοεμβρίου 2008

Βγήκε η έκδοση 6.5 του Netbeans!

Βγήκε η έκδοση 6.5 του Netbeans!

Κατεβάστε την απο εδώ: http://www.netbeans.org/downloads/

Μερικά features:
* The award-winning NetBeans IDE for Java keeps getting better. New to 6.5: support for Groovy and Grails, built-in support for Hibernate, Eclipse project import, Compile/Deploy on Save, and much more.
* Value Proposition: We continue to build on our award-winning IDE for Java by adding popular new features and improvements. Find out why NetBeans IDE for Java is the right IDE for you- with rich support for ME/SE/EE development and new feature highlights including Groovy and Grails support, built-in support for Hibernate, Eclipse project import/synchronization, Compile/Deploy on Save, and Ajax-enabled JSF CRUD generator.
* Simplify your Python development with the NetBeans IDE for Python- Early Access. This community driven project combines the practical development expertise of Python developers with the experience of IDE development by the NetBeans community.
* Developers can enjoy great editor features such as code completion, semantic highlighting, instant rename, smart indentation, pair matching, and more. The EA release also includes a community developed Python debugger as well as the ability to choose between the Python and Jython runtimes.

Packaging a Java application on Debian

Before packaging your Java program on Debian, be sure you have read the Debian policy for Java, located here:

http://www.debian.org/doc/packaging-manuals/java-policy/index.html

Πέμπτη 16 Οκτωβρίου 2008

Using Streams in Java

If you got confused by the number of streams in Java, check this out:

Using Java Streams: http://docs.rinet.ru/WebJPP/ch13.htm

Input and Output Streams: http://www.iam.ubc.ca/guides/javatut/java/io/index.html

Basic I/O: http://java.sun.com/docs/books/tutorial/essential/io/

Very very fast:

* Byte Streams handle I/O of raw binary data.
* Character Streams handle I/O of character data, automatically handling translation to and from the local character set.
* Buffered Streams optimize input and output by reducing the number of calls to the native API.
* Scanning and Formatting allows a program to read and write formatted text.
* I/O from the Command Line describes the Standard Streams and the Console object.
* Data Streams handle binary I/O of primitive data type and String values.
* Object Streams handle binary I/O of objects.

Ventrix's Code Folds

Ventrix's Code FoldsExplicit code

Δευτέρα 6 Οκτωβρίου 2008

Calculate the execution time

//variables
private long start;
private long end;

//Put this before the main code
start = System.currentTimeMillis();

//Main code here

//Put this at the end of the code
end = System.currentTimeMillis();

System.out.println("Completed in +"+(end-start)+"ms");

Running a threadless application on a Intel Core2 CPU

My processor:


cat /proc/cpuinfo

ventrix@bytemobile:~$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 CPU 6300 @ 1.86GHz
stepping : 6
cpu MHz : 1875.766
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2



I created an application to test if a number is prime or not. It isn't very special, except the fact that you can check REALLY big numbers...

The result is this:


As you can see with htop, only one of the cores is executing the application.
Also, if you take a careful look at the xfce's cpu meter, the total use of the CPU counts a 50% percent.

After 25 minutes I guess 170141183460469231731687303715884105727 IS a big number to test:)
[BTW 170141183460469231731687303715884105727 is a prime, according to http://en.wikipedia.org/wiki/List_of_prime_numbers)

Τετάρτη 17 Σεπτεμβρίου 2008

Java comments for javadoc how to

Java comments for javadoc how to

In Netbeans, write /** before a constructor for example and press enter. It will automatically generate the javadoc comments for that constructor!


/**
* Returns an Image object that can then be painted on the screen.
* The url argument must specify an absolute {@link URL}. The name
* argument is a specifier that is relative to the url argument.
*


* This method always returns immediately, whether or not the
* image exists. When this applet attempts to draw the image on
* the screen, the data will be loaded. The graphics primitives
* that draw the image will incrementally paint on the screen.
*
* @param url an absolute URL giving the base location of the image
* @param name the location of the image, relative to the url argument
* @return the image at the specified URL
* @see Image
*/
public Image getImage(URL url, String name) {
try {
return getImage(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}



http://java.sun.com/j2se/javadoc/writingdoccomments/

Πέμπτη 4 Σεπτεμβρίου 2008

J2me sockets and streams...

http://www.russellbeattie.com/notebook/1002646.html

a call to Connector.open("sockets://...") in the main thread will STOP your application from running without an error.

if the inputStream is blocked waiting for a read(), then the outputStream is blocked also.

a call to InputStream.available() always returns 0, regardless of how many bytes are actually available.

Τρίτη 2 Σεπτεμβρίου 2008

Java Naming Conventions

Java Naming Conventions

http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html

http://geosoft.no/development/javastyle.html

Τετάρτη 27 Αυγούστου 2008

Parsing XML String using DOM

http://www.albeesonline.com/blog/2007/10/09/parsing-xml-string-using-dom/

Java Persistence API Getting Started

JPA - Java Persistence API

Ένα πολύ καλό Getting Started εδώ: http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40ff8a3d-065a-2910-2f84-a222e03d1f43

τόσο καλό που το έκανα mirror εδώ: http://ventrix.nsdc.gr/stuff/Getting_Started_Java_Persistence_Api.pdf

Και μετά ελέγξτε και αυτό: https://glassfish.dev.java.net/javaee5/persistence/persistence-example.html

Τρίτη 12 Αυγούστου 2008

Threads in J2ME

A really good article to get started at:

http://developers.sun.com/mobility/midp/articles/threading2/

And always remember:

When creating a thread, we implement the run() BUT call the start() method.

Τετάρτη 2 Ιουλίου 2008

Java to exe, JSmooth a Java Executable Wrapper

JSmooth is a Java Executable Wrapper. It creates native Windows launchers (standard .exe) for your java applications. It makes java deployment much smoother and user-friendly, as it is able to find any installed Java VM by itself.

When no VM is available, the wrapper can automatically download and install a suitable JVM, or simply display a message or redirect the user to a web site.

JSmooth provides a variety of wrappers for your java application, each of them having their own behaviour: Choose your flavour!

http://jsmooth.sourceforge.net/

Τετάρτη 11 Ιουνίου 2008

Creating jar applications

Αφού κάνουμε compile τα αρχεία .java ώστε να παραχθούν τα .class εκτελούμε μέσα στον φάκελο την εξής εντολή:
jar cvfm test.jar manifestfile *.class

ώστε να δημιουργηθεί το jar αρχείο test.jar το οποίο θα περιέχει το manifest αρχείο manifestfile και όλα τα .class. Αν έχετε και άλλα αρχεία που θέλετε να περιλαμβάνει μπορείτε να τα προσθέσετε και αυτά δίπλα στο *.class χωρίζοντας τα με κενό.

Το αρχείο mainfestfile πρέπει να περιέχει τα εξής:

Manifest-Version: 1.2
Main-Class: mainclass
Created-By: 1.4 (Sun Microsystems Inc.)

Όπου mainclass το όνομα (χωρίς την κατάληξη) της main κλάσης του προγράμματος.

Για να το τρέξετε πατήστε:
java -jar example.jar (σε linux)
ή
C:\Java\jdk1.4.0\bin\javaw.exe -jar example.jar (σε windows)

Sun's java on linux

Ένα απο τα πιο συχνά προβλήματα στο Debian είναι η σωστή υποστήριξη της java, και για την ακρίβεια, η υποστήριξη της ΣΩΣΤΗΣ java. Το Debian διαθέτει το JRE, το JDK και λοιπά της SUN σαν non-free πακέτα του στυλ sun-java5-*, ενώ προσφέρει διάφορες εναλλακτικές όπως το GCJ (GNU compiler for java) τα οποία όμως δεν παίζουν αρκετά καλά προς το παρόν με αποτέλεσμα πολλά λάθη σαν και αυτά:

Exception in thread "main" java.lang.NoClassDefFoundError: [***]
at java.lang.Class.initializeClass(libgcj.so.90)
Caused by: java.lang.ClassNotFoundException: javax.swing.GroupLayout not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}

Για να εγκαταστήσετε την σωστή έκδοση της Java, βεβαιωθείτε οτι έχετε στα repositories του apt την επιλογή non-free, εγκαταστήστε όποια πακέτα απο το sun-java5- θέλετε και αφού η εγκατάσταση ολοκληρωθεί πατήστε:

sudo update-alternatives --config java


Διαλέξτε την επιλογή: /usr/lib/jvm/java-6-sun/jre/bin/java.

Στο τέλος θα πρέπει να δείτε: Using '/usr/lib/jvm/java-6-sun/jre/bin/java' to provide 'java'.

Αυτό ήταν!

απο το http://ventrix24.blogspot.com/

Τρίτη 10 Ιουνίου 2008

A Visual Guide to Layout Managers

http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

Java Applet VS Java Application

Application is a Java class that has a main() method. An applet is a Java class which extends java.applet.Applet. Generally, application is a stand-alone program, normally launched from the command line, and which has unrestricted access to the host system. An applet is a program which is run in the context of an applet viewer or web browser, and which has strictly limited access to the host system. For instance, an applet can normally not read or write files on the host system whereas an application normally can. The actions of both applets and applications can be controlled by SecurityManager objects.

Applets may communicate with other applets running on the same virtual machine. If the applets are of the same class, they can communicate via shared static variables. If the applets are of different classes, then each will need a reference to the same class with static variables.

from http://www.doc.ic.ac.uk/~nd/surprise_97/journal/vol1/tay/app.html

Controlling Access to Members of a Class

The following table shows the access to members permitted by each modifier.

Access Levels







































ModifierClassPackageSubclassWorld
publicYYYY
protectedYYYN
no modifierYYNN
privateYNNN


απο το http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html

Παρασκευή 6 Ιουνίου 2008

Εγκατάσταση Java JDK JRE

Για να εγκαταστήσετε την Java και το JDK απο την Sun ώστε να μπορείτε να μεταγλωττίζετε και να τρέχετε προγράμματα java, εγκαταστήστε το πακέτο: sun-java5-jdk και τα dependencies του.

Πέμπτη 5 Ιουνίου 2008

IMB J9 JVM

IBM J9 Java Virtual Machine and WebSphere Application Server V5.1.1 & V6.0 Support

http://www-1.ibm.com/support/docview.wss?uid=swg21221478

Δευτέρα 26 Μαΐου 2008

Java Screenshot How to

http://schmidt.devlib.org/java/save-screenshot.html

[code]
/*
* Screenshot.java (requires Java 1.4+)
*/

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class Screenshot {
public static void main(String[] args) throws Exception {
// make sure we have exactly two arguments,
// a waiting period and a file name
if (args.length != 2) {
System.err.println("Usage: java Screenshot " +
"WAITSECONDS OUTFILE.png");
System.exit(1);
}
// check if file name is valid
String outFileName = args[1];
if (!outFileName.toLowerCase().endsWith(".png")) {
System.err.println("Error: output file name must " +
"end with \".png\".");
System.exit(1);
}
// wait for a user-specified time
try {
long time = Long.parseLong(args[0]) * 1000L;
System.out.println("Waiting " + (time / 1000L) +
" second(s)...");
Thread.sleep(time);
} catch(NumberFormatException nfe) {
System.err.println(args[0] + " does not seem to be a " +
"valid number of seconds.");
System.exit(1);
}
// determine current screen size
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize);
// create screen shot
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRect);
// save captured image to PNG file
ImageIO.write(image, "png", new File(outFileName));
// give feedback
System.out.println("Saved screen shot (" + image.getWidth() +
" x " + image.getHeight() + " pixels) to file \"" +
outFileName + "\".");
// use System.exit if the program hangs after writing the file;
// that's an old bug which got fixed only recently
// System.exit(0);
}
}
[/code]

Τετάρτη 7 Μαΐου 2008

Netbeans Mobility pack

Πρώτη μέρα στην δουλειά χθες, στήσαμε το Netbeans με το mobility pack για την ανάπτυξη εφαρμογών σε j2me. Είμαι τόσο ενθουσιασμένος που θα γράψω ένα μικρό tutorial στα γρήγορα...

Για να φτιάξετε λοιπόν ένα jar θα χρειαστεί να κατεβάσετε το μία έκδοση του Netbeans που να υποστηρίζει το mobility pack, δηλαδή το Netbeans mobility pack ή το Netbeans All.
Θεωρώ σαν δεδομένο οτι έχετε εγκαταστήσει την java
Εγκαταστήστε το Java JDK απο εδώ: http://javadl.sun.com/webapps/download/AutoDL?BundleId=18705 και κρατήστε το path που το εγκαταστήσατε.
Κατόπιν τρέξτε το αρχείο netbeans-6.1-VERSION-linux.sh με την παράμετρο "--javahome /path/to/java"

./netbeans-6.1-mobility-linux.sh --javahome ~/bin/java"

στην περίπτωση μου.

Τώρα το που μένει είναι να αλλάξετε δυο αρχεία ακόμα.
Βρείτε το αρχείο: mobility8/WTK2.5.2/bin/emulator που βρίσκεται εκεί που εγκαταστήσατε το netbeans και αλλάξτε την γραμμή javapathtowtk= /path/to/java/bin/

javapathtowtk=/usr/lib/jvm/java-6-sun-1.6.0.06/bin/

για το δικό μου σύστημα.

Ομοίως αλλάξτε το αρχείο mobility8/WTK2.5.2/bin/ktoolbar

Είσαστε έτοιμοι!



QuickPost

Snapshot "Hello j2me world, from Ventrix"

Java on wm5

Φτιάχνοντας κάποιες jar εφαρμογές με το NetBeans που έπεζαν στο κινητό, ήθελα να δοκιμάσω πως θα τρέχουν και στο pda με κάποιο jvm. Βρήκα αυτά τα δυο: Mysaifu JVM - http://www2s.biglobe.ne.jp/~dat/java/project/jvm/index_en.html
και
Ewe Launcher - http://www.ewesoft.com/

και τα δυο freeware εννοείται.

Δοκίμασα το πρώτο και φαίνεται να δουλεύει μια χαρά με κάποια tests με class αρχεία που έκανα, όμως δεν τα καταφέρνει πολύ καλά με τα jars βγάζοντας: java.lang.Exception: No Main-Class attribute in "path" at java.lang.VMMainThread$1.Run(VMMainThread.java)


Τελικά έπαιξε άψογα το JVM της IBM ονόματι J9.

Τρίτη 1 Απριλίου 2008

jpcap -- a network packet capture library

http://jpcap.sourceforge.net/

The jpcap distribution includes both

* A tool for real-time network traffic capture and analysis
* An API for developing packet capture applications in Java

The jpcap network capture tool performs real-time decomposition and visualization of network traffic.

Java and Android Blog

Μετά την επιτυχία(?!) του http://ventrix24.blogspot.com blog σχετικό με Debian και linux related θέματα, αποφάσισα να φτιάξω και ένα blog για java περισσότερο για προσωπική βοήθεια.

Λόγω πτυχιακής θα ασχοληθώ αρκετά και με το android συνεπώς τις περισσότερες φορές θα γράφω συνδυαστικά και για τα δύο.