|
|
||
Alexander Schunk's BlogCommunity: JDK ArchivesMy View on Closures: Part 2Posted by alexanderschunk on January 20, 2008 at 05:09 AM | Permalink | Comments (4)No more symbols please>In my last Blog i did make some suggestions to get rid of the redundand => syntax of closures. I suggested to use := and to invent a keyword i.g. block or function to highlight the fact that closures are functional objects - basicall Neil Gafter regards them as equivalent to anonymous methods however i think there is no strict distinction in Gafters proposal wheather a closure is a pure function or an object According to Neil Gafter, a closure object needs to be invoked by calling the invoke() method for a particular closure. The invoke method can have parameters i.g.:
{ int x => x + 1 } //closure definition
{ int x = > x + 1 }invoke(10); //call closure with 10 as parameter
So if a closure is a function in this case - besides the fact that its also an object - a closure object - then i think it would make sense to declare this whole block of statemens as a function:
function { int x => x+ 1}(int);
In my last Blog i said that the => symbol is redundant and suggested to use := as a variation of =. With this variation the closure would be written as:
function{
int x := x+ 1;
}(int);
//call closure with 10 as argument
function{ int x:=x+1 }(10);
This syntax could also be used to simply define getters that return values:
function {int x:=10;}(); //always returns 10
int s = function sum{int x, int y := x+y }(3, 5); //call sum with 3 and 5 as parameters
Local variablesAlso its possible to declare local variables in closures:
function{
int j = 0;
int i=3;
switch(i){
//some switch statements
case 1: j++;
case 2: j--;
}
}();
Thus using a function keyword makes clear that a closure is both a function and an object that can be invoked. The invocation is executed by adding the () parantheses to the statement. Yet Another Closures ProposalPosted by alexanderschunk on January 17, 2008 at 09:47 AM | Permalink | Comments (19)First: Getting rid of =>Basically, when i read all the proposals, comments and pros and cons on closures in Java the first thing i would get rid of is the obviously redundant => declaration. So in case of block statements the following would be allowed:
{
int x = 0;
int y = 3;
int sum:= x+ y;
}
As i understood it right, => has at least two meanings. It means return for functions and := or = in the other case. Replace => by := for assignmentsI would use := for assignments rather than => simply because := is more naturial to mathematicians and logicians and is usually used to describe an assignment in math and logics. This could be used as outlined above:
{
int x = 4;
int y = 3;
int z = 3;
int sum:=x+y+z; //assignment
}
Use a function keyword instead of {int, int => int} syntaxFor the function declaration, i would suggest to use a keyword rather than a symbol. Why not invent a function keyword that has a similar meaning like => i.g.:
public int function add(int x, int y){
return x + y;
}
In the other case, i would use := instad of => because the arrow direction implies to read it left to right rather than right to left and there is no <= to represant the invert direction. Use a block keyword to declare block statementsRather than just simply type closures i would invent a block keyword that defines a block of anonymous statements:
//only valid for anonymous block statements, not be used in loops
//itereations
block{
int x = 3;
int y = 4;
}
So with these language features you could write a simple to read Java code that is clear and understandable by everyone:
class MyClass{
//declare a function type
public int function add(int x, int y){
return x + y;
}
public int function sub(int x, int y){
return x - y;
}
public void function(List
LinAlg API CVS trunk is openPosted by alexanderschunk on January 12, 2008 at 02:57 AM | Permalink | Comments (0)LinAlg API CVS trunk is openThere is a first source files upload avaiable for LinAlg API in CVS trunk. To check out the sources simply use your favorite CVS access programm and type the following commands: cvs -d :pserver:username@cvs.dev.java.net:/cvs login :pserver:username@cvs.dev.java.net:/cvs checkout linalg If you are using NetBeans you just need to configure the CVSRoot path and the set the checkout options. There seems to be a problem with NetBeans CVS under Windows but if you have a Linux CVS client that should work well. We will provide further CVS sources for different OS and Java platforms in the future. So far you need to become a member of LinAlg API project and download the sources and .jar files from the document/files section. LinAlg API: 20 fellows make up a CommunityPosted by alexanderschunk on January 09, 2008 at 07:12 AM | Permalink | Comments (0)20 Fellows make up a CommunityThe twentieth member has joined the LinAlg API community. Members background ranges from computer sciences and software engineers with up to 5 years of experience in Java programming and with industry background. In particular in the last two month many people joined LinAlg API and asked for help in developing or porting LinAlg API to other platforms. Thats a great news and i hope and will look forward to get more fellows that want to contribute and help improving LinAlg API. We are on a good way. LinAlg API: Christmas PresentPosted by alexanderschunk on December 22, 2007 at 02:20 AM | Permalink | Comments (0)Christmas ReleasesIn my last Blog i said that LinAlg API is finished. This is still true yet i did add some more features to it and revealed two new ports for mobile and 64 bit platforms as a special christmas release :). FeaturesWith this release LinAlg API now offers core features for the following mathematical types and a bit more:
To download release 2.0 of LinAlg API go to the LinAlg API project page at linalg.dev.java.net. Thanks to the contributorsThis 2.0 release of LinAlg API would not have been possible without the help of the many contributors that joined LinAlg API and helped testing it or porting it to other systems. Special thanks goes to Morton Gulbrandtsen - working on a Solaris and Debian port -, David Clavel and Steven Martin who first joind LinAlg API and gave a good feedback. Merry Christmas and a Happy new Year...... to the Java community and the rest of the world from the LinAlg API team. LinAlg API: FinishedPosted by alexanderschunk on December 17, 2007 at 11:14 AM | Permalink | Comments (0)LinAlg API: its finishedYes. Finally, i got it done. LinAlg API now offers all the things i wanted to see it have. Sure, there are some things to do here and there but basically all features from my todo list are now implemented and exist at an almost complete level. The Quaternion class needs to be finished yet this is something i will do in the next couple of weeks however the Quaternion class already provides some basic operations for Quaternions you can work with with. LinAlg API: Scope and FeaturesFrom the very beginning i wanted to write an almost complete linear algebra API that offers basic features to do linear algebra with Java. Now, lets have a short look at what features LinAlg API provides with this stable release:
Sure, there are some things you wont find in LinAlg API that some people may find useful yet the Todo list has not been closed :). Another important thing - that has nothing todo with its implementation - is the growing number of interesting people and developers that join the project. Some of them give feedback others not but its a good feeling to see that there are people that like the project and want to help make it better. Sure, i am still looking for volunteers, testers and developers to test and help improve LinAlg API so if you are interested feel free to joint the project. Demos, Docs, TutorialsThere are a few demos available that demonstrate the core features of LinAlg API, a tutorial for beginners and a whitepaper for those interested in background information. I will start writing a JCP for those interested in using LinAlg API for their own implementations. Basically using LinAlg API is rather simple - no matter if you use it for developing apps or to develop your own linear algebra API. I will provide more tutorials and information on implementation issues in the near future. Mercurial at homePosted by alexanderschunk on December 13, 2007 at 10:55 AM | Permalink | Comments (0)Mercurial at homeSince the beginning of OpenJDK i followed the discussion about the mercurial move. Since the main job of porting over the sources from subversion CVS to Mercurial - that is the Mercurial transition - is done i wanted to test Mercurial myself at home. As a Windows user i was looking for a Windows download and found one at the Mercurial download page. Having installed Mercurial on my machine i did run the hg test command and got a list of help commands for the other mercurial commands. After experimenting with other commands i found that for each command it is required to add the hg command which i find a bit of "repeat yourself." and thought i got myself writing a few batch files to do the job. Having a few batch files to create and update repositories i found that having a GUI application for Mercurial that displays the repositories and their files would be even better. I am not aware about how good Java would do the job here but i think it should be possible to have an application that goes over all files in the directories of the repositories and shows the files connected to them. LinAlg API: Graphics ToolsPosted by alexanderschunk on December 10, 2007 at 11:10 AM | Permalink | Comments (2)Graphics Tools for LinAlg APII have started adding some graphics tools to LinAlg API using Java2D. As a result i have a simple 2D coordinate system that is scalable and can be customized to your personal needs. I would love to show a picture of it if i knew how to load images to this Blog - may be someone can help me here. The graphics tools basically consists of a few methods that enable you display coordinate systems and Vectors in 2D graphics and to scale these coordinate systems by any unit you like. This feature is not yet implemented but its easy to do it. Just need to provide further methods with corresponding parameters. A new statisitcs APIAnother thing i am currently planning to work on is a new statistics API with some demo apps providing common statistic algorithms like mean, standard deviation,binomial and faculty algorithms, statistic distributions etc. To distinguish myself from other libraries i will also provide graphics tools for this API to display statistic data or to animate certain distributions like the poisson distribution. LinAlg API: on international developmentPosted by alexanderschunk on November 15, 2007 at 08:17 AM | Permalink | Comments (3)An Experiment at the beginningWhen i started developing LinAlg API it was just personal interest and a sort of experiment. Is it possible to write a simple-to-use API for Vector and Matrix operations? Well, the answer seems to be: Yes. Then, i decided to add Complex number functionality and to keep scope of LinAlg API features to a minimum. There are of course other such APIs for vector and matrix calculus yet i had my very own idea how to implement such an API. I wanted to make it easy-to-use and comfortable. Thats why it is implemented as it is. The way to java.netAs development moved on i decided to host it on java.net in order to find fellow developers to join this project. It took a bit of Blogging to gain some interest and now i have fellow developers all over the world from the USA over China to India. One thing thats a bit hard is to get information about project members once they joined the project and to keep track of development of these developrs. Until you have setup some sort of mailing list or a developer forum it seems to be impossible to keep uptodate with the development of other people. So here is a proposal for java.net to add a feature for this to share information on users contact information and background - because sometimes its interesting to have an idea of the people you are working with. Moving onNow, since Linalg has made its way over the world its time to move on. I have added a few ports to 64 Bit systems and other Java platforms like the wireless API. I am still looking for interested developers that could porting LinAlg API to other 64 Bit systems and to the mobile platform. The End. The beautiful World of Java SwingPosted by alexanderschunk on November 10, 2007 at 12:32 PM | Permalink | Comments (3)Somewhere deep down in the API forrest...In the beginning there was Swing as a subset of AWT with a huge array of features for GUI programming. Ok. Now we have JavaFX, Swing-X, Fuse and the Swing Application Framework. Now, from the developers point of view its nice to have this kind of choice of many APIs available for GUI programming yet whats missing is a kind of overview what API to choose for what kind of project. For example the Swing-X API offers some features one would like to see in the Java Swing API. JavaFX has even more features not available in Swing and other such APIs. If JavaFX is the next generation GUI API for Web and Mobile apps whats going on with Java Swing on the desktop?. LinAlg API: 64 Bit Version availablePosted by alexanderschunk on November 06, 2007 at 09:04 AM | Permalink | Comments (1)64 Bit rocksA first 64 Bit version of LinAlg API for Windows Vista 64 Bit is available. If you want to compile it yourself you need a 64 Bit JRE and Compiler with Java 6 installed. I will also provide some demos for this 64 Bit Version. LinAlg API: Weekly BuildsPosted by alexanderschunk on November 06, 2007 at 04:53 AM | Permalink | Comments (0)Weekly BuildsWeekly Builds of LinAlg API will be available soon. These weekly builds are developer builds that you can use for development. Stable versions are build in a month turn or if there are enough features that require a new milestone. If other ports are available these will also be available for download on the project homepage. I will also provide some 64 Bit demos for this version of LinAlg API. ADI: Application Driven InternetPosted by alexanderschunk on November 05, 2007 at 03:47 AM | Permalink | Comments (3)Application Driven InternetThis Blog is the sequel of my last Blog where i was thinking further on Davids entry. In fact my last Blog results in what i call ADI which is short for Application Driven Internet - a new view on the Interne as a means of using the Internet for sharing Web and Desktop applications as were they one application. Your Browser: the Gateway to the InternetThis view on the Internet turns the Browser into the Gateway to the Internet leaving settings and configurations to the applications - i.g. thinks like security, RSS, etc. - and spanning the bridge between your desktop and the world wide web. In this Internet the Browser only is a means for displaying a minimum sort of XML based content with an engine to run applications - if we want full Desktop equivalent applications in the internet we also need some mechanism to run these applications in the browser which means we need some form of internet application engine that is not bound to the desktop application or may be a part of it. So in this view on the internet there is no big difference between desktop applications and web applications. For example consider the following scenario: you have an application for managing email, contacts, etc. with one backend on the desktop and one backend on the internet with the same GUI interface. Now, if you want to write your friend an email just go to the internet menu and select "connect to" and send over the message while the application opens an connection to the internet and displaying the GUI of the Web interface. Also consider the other case where you have a webapplication with a webinterface that also has a Desktop backend with the same GUI interface but limited features. You can select a menu in your web appliction that opens a connection to this Desktop backend and allows you to work with this Desktop backend almost the same as with the internet appliction. So within the Application Driven Internet there woul be no frontier between the Web and the Desktop and it would be the users freedom what application to use and allowing him to configure security and personal settings in both worlds. Desktop/Web convergence: Ist it becoming real?Posted by alexanderschunk on November 05, 2007 at 02:53 AM | Permalink | Comments (0)Wesktop: Desktop and Web applicationsIn his latest Blog David Herron is thinking aloud on the convergence of Web and Desktop applications and citing some existing example of these and resuming the main disadvantages of the current state-of-the-art Web access. Hiding the Browser from ApplicationsIn fact David is suggesting to reduce the Browser as a means of accessing content to a means of accessing only the web itself. This would result in that the web applications would be independent from the Browser and its capabilities. This would mean in turn that we need programming languages that are indepenendent from Browser features and only used for writing Web applications. Giving Power to the apps, not to the BrowserThis shift from the Browser as a tool for access and not viewing content would also mean a shift from giving power back from the Browser to applications and reduce Browser featurs to a limit. Since the Browser must have some knowledge or concept how to present Web date this might make it necessary to invent some cross-language format that describes Webcontent no matter if its HTML, CSS or a scripting language. This could be done with XML the same way you use XML to define a Webservice. The power of ConvergenceConverging Web applications with Desktop applications or features will make it possible to write applications that can both access far networks over the internet and access local resources on your local machine given some restrictions on critical data. Yet even this problem might be solved by allowing some personal configurations. For examle one could allow an application to acces his private data on his local machine if he secures it with a password. I think this is the sort of next Generation Web applications we are seeing in the 5 or 10 years. However this will also require some more security and awareness of dangers coming from the interent. Java on Mac: RevisedPosted by alexanderschunk on November 01, 2007 at 12:44 PM | Permalink | Comments (0)Compile once dont run anywhere?Ok. My Last Blog did stirr up attention but did not bring the very answers i was looking for. Having read some other Blogs i am still confused about what this controversy still is about but i think i am getting right by assuming that Apple is currently not supporting Java 6 on the current Mac OS yet they are planning to support some time later. However this brings me to some other questions that arise. If Microsoft Windows is only supported because of its market share and Linux because of its popularity - what happens if one these operating systems will not have that market share or popularity? Is there a minimum of operating systems Java is going to run anytime or is the OS portfolio a volatile thing that is shifting and changing depending on acceptance and availability? What is with those developers that use Java because it supports that variety of operating systems and want to support a variety of plattforms? Is Java not going to get hurt if one big OS vendor says: "well we are supporting Java but not the very latest version of it"? So software developers will have to downgrade to that vendors Java version - if possible - and or have to wait until that vendor is upgrading to the latest Java version. So the question about Java on Mac or not has a much more deeper truth behind and is not so easy to answer. Java on Mac: what the hec?Posted by alexanderschunk on October 31, 2007 at 12:22 PM | Permalink | Comments (12)Compile once, dont run anywhere?So whats this controversy or non-contreversy thing with Java all about? And what about compile once run anwyher? And isnt its SUNs Job to get things work on the OS plattform they support and not Apple? Ok. To make me understand: at the beginning of this year i joined the OpenJDK discussion lists and i was told the Vista is not one of SUns favorite OSes for Java 7. Now everyone seems to acknowledge that Windows Vista is - despite the problems with Vista Microsoft has - the very one plattform and MAC is not. So whats up with Java 7? Is it going to run on MAC, Linux, Vista or only Vista and Linux?. OpenJDK: Repositories overviewPosted by alexanderschunk on October 30, 2007 at 02:31 PM | Permalink | Comments (0)Master and SlaveReading Kellys Blog it seems like the main target group of developers for OpenJDK is moving from pure Desktop applications to Webservice related applications. The Mercurial repositories of OpenJDK include jws, jdk, java2d, ti, and some other interesting APIs. However some APIs - mainly extended APIs - are not listed in the Master and Slave repository chart. I assume these APIs will be included into OpenJDK to a later time or may be added using Modules. Anyway if this is the core of OpenJDK or Java 7 it looks like Java will shrink in its core features and is open for new extension API development. However this is just my personal interpretation. In this case external APIs from third party developers will have to comply and meet the software development guideliness as imposed by the OpenJDK community charter and legal documents. Search and Sort with JavaPosted by alexanderschunk on October 11, 2007 at 11:49 AM | Permalink | Comments (14)Search and Sort API for JavaWhile working on some simple applications i realized that there is no standard seaerch and sort API for Java but a lot of books covering Algorithms in Java i.g. "Sedgewicks Algorithm in Java". However it would be easy to implement common algorithms for basic purposes in Java for instance things like linear search binary search or sorting algorithms like bubble sort, quick sort etc. While most applications require a special implementation of certain standard algorithms a standard API for algorithms in Java might help in certain common tasks. Another field of algorithms is hashing and algorithms for Graphs. Most common algorithms on Graphs are documented well and lots of implementations are around there. Again a standard API for Graphs algorithms might help for certain common tasks. Possible implementationA possible way to implement search and sort functionlity would be to use an interface like Comparable and Comparator for searching:
public interface Sortable{
public int sort(Object[] items);
}
Another way is to use concrete classes:
public class BasicSearch{
public Object linearSearch(Object[] item, Object key){
}
}
There are various ways to implement such an API but i think having concrete classes or interfaces is a good way to do it. So its a question to the community if there is a need for a standard API for searching, sorting and may be Graphs. Java 6: Update N Nice butPosted by alexanderschunk on October 09, 2007 at 11:05 AM | Permalink | Comments (23)Java: Update NThe Consumer JRE or Update N for Java 6 is a good one solving some bottlenecks of previous Java versions. Except Quickstart and Nimbus all items of the new Update worked pretty well on my Win XP Notebook. I was trying some Java apps i have written but i did not see a remarkable launch improvement instead they were running as usual. The Deployment Toolkit is a nice Add-On for the Browser telling me that i am using Java 1.7.0 on my Windows. I have no hard figures for Quickstart on Win XP but i feel my Swing apps already run smooth and have appropriate start up times. Concerning Nimbus i would love to see it working on Win XP so i hope it will be stable in the near future. Great work. LinAlg API: Stable release available for DownloadPosted by alexanderschunk on October 02, 2007 at 11:52 AM | Permalink | Comments (0)LinAlg Stable releaseA first stable release of LinAlg API is available. You can download it from the LinAlg API project homepage at linalg.dev.java.net. DemosWith this first stable release i have provided some demo apps. These demo apps are:
The angle converter simply converters angles from degree to radians. One drawback is then when converting back from radians to degree you have to specify the angle with all digits otherwise the result is wrong. Complex Calculator supports the basic complex operations like +, -, *, /, abs(), tan() for Complex Numbers. PASCAL supports basic Vector 3D operations like +, - ,* , /, abs() etc. You can download the demo apps from the project homepage in the LinAlgDemos folder. For screenshots see the Demos folder. Bug ReportsI would be happy to receive any user feedback or bug reports of LinAlg API so feel free to post them. LinAlg API: Stable releasePosted by alexanderschunk on September 29, 2007 at 12:29 PM | PermalinkLinAlg API: Stable releaseA first stable release of LinAlg API is available. This release offers a few new features, some changes and also some demo apps. New FeaturesI have added a tiny utility class called UtilsDegrees to Radians: With these two methods its possible to convert angles from degree to radian. The following image shows a demo application i have written that does just that: For a screenshot i refer you to the LinAlg API project homepage linalg.dev.java.net. Complex classThe Complex class has undergone the most significant changes. Now the Complex class offers almost all features you need to work with Complex numbers. Below is a list of new features:
I have written a simple demo app called Complex Calculator that is a simple calculator for Complex numbers. Vector and Matrix classThere is not much new for the Vector classes. The Matrix class has some new features some of which need to be tested. LicenseThe stable release will be available with two licenses like the other Milestones of LinAlg APi. The GPL and CDDL license. DemosI will try to upload the demo apps on the project hompage with screenshots. db4j: Simple Database API for JavaPosted by alexanderschunk on September 28, 2007 at 12:04 PM | Permalink | Comments (6)db4j: A simple Database APIIf you are working a lot with Java DB then you repeatedly perform a few tasks every time and some only once. For instance establishing a connection with a database and open a table of database usually happens at least once until you are working with more than one database. With JDBC you need to do the following for establishing the connection:
try{
conn = DriverManager.getConnection(dbname, username, password);
return SQL_DB_OPEN_ERROR;
}catch(SQLException e){
System.out.println("Error! Unable to connect to " + dbname);
System.out.println("Cause: " + e.getSQLState());
}
Given a Connection object called conn the code above is used for setting up a connection with a database with your username and password. With db4j you can connect to a database as follows:
DBConnection db = new DBConnection();
String dbname = "BeispielDB.txt";
String usrname = "admin";
String password = "adminadmin";
String constring = "sun.jdbc.odbc.JdbcOdbcDriver";
Connection conn;
try{
db.connect(conn,constring, "admin", "adminadmin");
db.open(conn, constring, usrname, password);
}catch(Exception e){
}
This simplifies the connection process to creating an object of class DBConnection and calling its open() method with a few parameters. The DBConnection class offers basic methods for connecting to a database, open a database and close the connection. To reduce programming with JDBC or derby db4j offers a set of classes that consists of the following classes:
The name of these classes are almost self describing. The DBActions class provides database transactions such as Auto-Commit, Rollback etc. Note that your DBMS might not support all these featurs so have to consult your DBMS documentation. DBLogger is a simple Logger class that uses JDBC Logger methods. The DBDriverInfo provides information about the database driver. In a future release i will add a statement class and some utility methods for retrieving and setting database values. VisGraph: Visualization of Math functionsPosted by alexanderschunk on September 24, 2007 at 01:09 PM | Permalink | Comments (1)VisGraph: Simple, Tiny, VisualVisGraph API is a simple and tiny API for plotting standard math functions like sin(), cos(), abs() etc. that are provided by the java.lang.math package. VisGraph implemens all methods as static methods so you can use them like the ones provided in java.lang.Math.
//plot a sin curve in green given the points below
double[] points = {2, 3, 4, 5, 6, 9, 12};
plotSin(points, BasicMath.TWO_PI, Color.green);
This plots a sin curve with the points given in a range of TWO_PI which is a constant of the class BasicMath in which plotSin() is defined. With VisGraph you can plot i.g. a line that is defined as a Vector or as Points. //plot a line defined as two points in blue Point2D one = new Point2D(2, 4); //define a Point Point2D two = new Point2D(3, 1); //another point plotPoint2D(one, two, Color.red); There are similar methods for Vector types: //plot a line defined as two vectors Vector2D x = new Vector2D(3, 1); Vector2D y = new Vector2D(2, 1); plotVector2D(x, y, Color.blue); Since all methods are static you can call them in your app without any object. VisGraph uses the Java 2D API methods for drawing the plots so its a bit limited to Java 2D capabilities. Compatiblity vs. Diversity: Will OpenJDK help Java survive?Posted by alexanderschunk on September 05, 2007 at 01:30 AM | Permalink | Comments (1)Compatibility or DiversityOne thing thats right in Davids comment is that as soon as there are many different distributions of one Software product this will hurt compatiblity to the original product. One reason why people develop different implementations of an existing product is that they think the original product (i)does not offer the thing they need and/or (ii)the feature works bad or not as expected. This goes for all kinds of software thats around there today. No matter if you write Tools, APIs, Frameworks, etc. you can bet that sooner or late there will be improvement, extension, enhancement or whatsoever. OpenSource: The root of the WarOne thing David omits in his comment was that the OpenSource movement - driven by the emergence of Linux - has helped Linux encountering the Desktop and thats why so many poeple use it today. So diversity and open systems also have a good point. If Linux would not exist, Microsoft would be the Monopolist you fear. And with Linux many useful Unix tools discovered the Desktop and gain a much broader popularity. So with open systems you have the freedom of choice to pick the one you like and leave alone the ones you dont. Just imagine there would only be one OS to make things worse, consider this would be Windows. All people on this planet -including the SUN engineers - would have to use this mor or less stable operating system. Unless you throw it away and write your own. And... see grow up another incompatible system in the world. OpenSource and CompatiblityI dont say that software diversity is bad or compatiblity stops diversity but keeping compatiblity and allowing diversity is a thing all major software developers and vendors have to face. Its also true that its software vendors own failure that different and incompatible versions of a software exist. Its true that for the Windows plattform there are today - at least - three different kinds of frameworks and APIs available that are more or less incompatible: .NET, MFC, and Windows API. Yes you are reading right... the MFC is still alive :). On the other hand, if low-level APIs such as Windows API would not be available it would be hard to write certain applications that you cannot develop using .NET only. Since Java is a cross-plattform programming Platfrom - not just an API or language its another story. Sure the existance of other opensource implementations like the Classpath project or other Java VMs does not make lifer easier for developer however, i believe that most Java developers are using the SUN Java Platform. So in the end i think that Java wont suffer the same silly war than Unix because its already in widespread use on different platforms and it was initially developed with the scope of cross-platform usability while Unix was not. And another thing thats important is that SUN has opened the Java TCK Compatibility tests for OpenJDK so this might be a resort to help ensuring compability to the original Java platform. So, finally, if SUN opensources Java it has to solve the problem of OpenSource freedom and commercial interests. SIMD for LinAlg API: Part IPosted by alexanderschunk on September 02, 2007 at 02:23 AM | Permalink | Comments (5)SIMD: IntroductionFor those that are not familiar with SIMD, which is short for Single Instruction Multiple Data i will give a short introduction. If you never worked with low-level assembly or C code, SIMD is a bit hard to understand but i will try to explain it. Basically, using SIMD requires an understanding of how a CPU works and how a CPU processes data between memory and its various registers. But this is just the beginning of the story. Since SIMD is implemented by various CPU vendors like Intel and AMD, there are, unfortunately, different types of SIMD instruction sets for different CPU architectures. Why SIMDSIMD was introduced to improve speed of data processing on PCs in particular for those applications that need to perform a lot of complex opereations and process a lot of data fast. Those applications are for instance Games, Animations and other Mulitmedia applications. If you run those applications on a normal CPU without SIMD the CPU usually only processes one instruction at time, that is, per CPU tick. Sometimes the applications mentioned above require to process more than one data - or, multiple data - per tick. Thus, the idea of SIMD was born. If you are using SIMD in your application, this basically means that you are processing multiple data in parallel by one single CPU / FPU instruction. Sounds nice right? So why do not all applications benefit from this great technology? Well, to be honest, its not the problem of technology rather than a problem of implementation. If you want to support SIMD, you will have provide an assembly language implementation of the functions that require fast CPU processing. Today, there are various libraries available i.g. from Intel that provide common math functions that support SIMD, yet, if your API only uses a few functions that require SIMD support, well using another lib just would bloat up your own code. MMX, SSE and 3DNOWAs i said above, there are different SIMD implementations availabe today. The two most popular implementations used, in particular in 3D Games or real-time applications are Intels Streaming SIMD Extensions called SSE and AMDs 3DNOW. MMX which is short for Multi Media Extension is not that much used today. Intel and AMD are the two global players on the CPU market today so if you write a cross-plattform API you will have to support these CPU architectures. Both, SSE and 3DNOW make use of special FPU - Floating Point Unit - registers that can perform complex math operations, such as Vector computation. For example, if you want to to compute the square root, that is the length of a Vector using SIMD, you can move the values of the Vector components into the corresponding register and look up the square root in a Look up table of the CPU. This is faster than computing it by using i.g. the Java Math.sqrt() method.. 64 Bit FPU data typesThe most important fact why SIMD is so much faster than SISD - which means Single Instruction Single Data - is that it makes use of special 64 Bit registers that can store and process two 32 Bit values, also known as DWORD or double word. These registers are all implemented on the FPU, so the CPU does not need to deal with them. This also has the advantage that the CPU can process normal application data and can delegate complex math operations to the FPU. So, basically, a fast FPU and huge RAM memory will speed up any 3D application. 32 and 64 Bit ArchticturesWith the emergence of x64 Bit architectures, things become more complicated. If you want to support any imaginable PC architecture you have to provide at least implementations for Intel x32 and 64 Bit and AMD x32 and x64 bit architectures. So you will end up at least with 4 small projects that almost provide the same functionality. Java, C, AssemblyNow that you know your various "stakeholders" at the system side, the other "stakeholders" at the software side show up. If you want to support any SIMD technology from above, you will have to write a JNI wrapper in C that implements the assembly code. Java - currently - lacks the ability to load native assembly files, so you have to use C. ConclusionWhat do we learn from that? Well there are many aspects to consider and many pitfalls to fall in, but, actually, as you will see in another Blog, things are not that much complicated, at least, if you have already had a look at SIMD before. Basically, you will need a few C structs and some functions that provide the assembly code and write a Java class that loads the library including error handling etc. The most important thing when working with SIMD is the processor type detection and the processor feature detection using the CPUID instruction. CPUID instruction is available on all common processor types. The Java JNI Tutorial provides a good introduction to the Java invocation API and on Intel Developer Site and AMD homepage you will find valuable information on how to deal with various processors and their features. LinAlg API: Milestone 1 releasePosted by alexanderschunk on August 27, 2007 at 02:12 PM | Permalink | Comments (4)LinAlg API: Scope, Features, WhichlistIn my previous Blogs on LinAlg API i already received some nice compliments and also some thoughtful advises. Both were helpful in development and help me understand the need and requirements of the community. Therefore i would like to thank you anyone who gave advise and or suggestions. Baering all this in mind i have fixed some Bugs and added the missing features of this API. As i have written in my headline, this is Milestone 1 of LinAlg which means that development of this API will continue, no matter if and where it will be used in the final end. Since LinAlg is released under GPL 2 you are free to redistribute, copy and use it as you which. So any help from the community to improve this API and its features is welcome. You do not need to be a Math professional to implement such an API. What you need is programming skills and a good reference book for Math on linear Algebra. FeaturesLast time i have already outlined the features of the missing Matrix class and the Vector implementation. Today and over the week end i have extended the Matrix class so it can work with 3D Vectors. Besides the basic Matrix operations i have outlined before the Matrix class now offers the following features: For example its possible now to mulitply a Matrix by a 3D Vector and to create a Matrix from a 3D Vector. This also required a redesign of the Vector3D class so the Matrix class can work with it. Also i have added further Constructors so it is possible to create different kind of Matrices. The following examples show what you can do with LinAlg Milestone 1:
Vector3D x = new Vector3D(1,3 ,4);
Vector3D y = new Vector3D(2, 4, 1);
Vector3D t = new Vector3D(1, 1, 1);
Vector3D u = x.add(y);
Vector3D z = x.add(y).add(t).scalarMul(2);
Matrix m = new Matrix(z);
Matrix k = new Matrix(3, 2, 3, 1);
double det = k.det();
double det2 = m.det();
Matrix l = m.vectorMul(x);
One thing thats nice is - because all methods return references of the specific type - that you can concatenate methods as in this example where you can add three Vectors in a single line: Vector3D z = x.add(y).add(t).scalarMul(2); In this line you add Vectors x, y, t and multiply the result by 2 given the Vectors specified above. The result is [8.0 16.0 12.0]. Another thing you can do is to calculate the Determinant of a Matrix:
Matrix m = new Matrix(z);
Matrix k = new Matrix(3, 2, 3, 1);
double det = k.det();
double det2 = m.det();
Matrix l = m.vectorMul(x);
In this example you have two Matrices. The first is created by the Vector z from the example above. The second is a simple 2x2 Matrix. The next two lines determine the Determinant using the following formula: det(A) = m11*m22-m21*m12. In the last line Matrix l is multiplied by Vector x. Of course the examples above only show only a fraction of LinAlg fetures. You can also rotate a Matrix around the three Axes by a specified angle. For example you can rotate a Matrix first around X-Axis, then around Z-Axis and finally around Y-Axis: Matrix p = m.RotX(30).rotZ(10).RotY(20); This is, again, possible because the methods return references of type Matrix. LinAlg API: Code organizationTo give LinAlg a more professional look and feel and organization of the code i have reorganized the package structure. With LinAlg API Milestone 1 the classes mentioned before are now hold into a seperate package with a corresponding name. So the Matrix class is hold in a package named matrix and the Vector classes are hold in a package namedVector. LicenseLinAlg API Milestone 1 is published under GPL version 2. TodoSince the scope of LinAlg API is - compared to other APIs mentioned before - rather narrow and more general the Todo list of LinAlg is not so long as of other APIs offering similar features. However one or another feature will sure show up in the Todo list so stay tune for updates. LinAlg API Milestone 1 will be available at linalg.dev.java.net. Java Consumer JRE: really a winnerPosted by alexanderschunk on August 22, 2007 at 12:06 PM | Permalink | Comments (9)Consumer JRE: a real winnerNo, i dont want to get too optimisitc nor enthusiastic but the changes of Java 6 described in Chets Blog really look great. According to Chet, one of the next coming Java 6 updates will include the following features:
Personally, i think Quickstarter and Java kernel are the two main improvements. Nimbus look and feel looks great. Just have a look at the screenshots in the Blog. The other improvements on the installer and the like just seem to be of cosmetic nature but i want to test Quickstarter and Java Kernel as soon as possible. Great Work guys. | ||
|
|