Is php very limited? - java

I've tried asp.net and jsp...and the programming language was powerful enough to create both desktop and Windows apps.
Butwhat can I possibly do with php other than creating web applications? Does it have some kind of runtime or framework?
Thanks

Powerful is an unfortunate word. It's about focus, not power. PHP is not very well suited for desktop applications. In part because of weak library support (Though some exists), and in part because of its memory management model. It can be used for jobs outside the web world though; It's often used as a general scripting language, as well as various background tasks.

PHP is not "limited" per se. PHP is primarily only used to develop Web applications. However, there are products like WinBinder that promise to allow you to use PHP to build a desktop application; I wouldn't exactly recommend that though. Also, you probably have not built Windows applications with ASP.NET and JSP but rather more likely .NET WinForms and Java (perhaps Swing). PHP is used by thousands of developers building many different Web applications. It is possible to build other kinds of applications with it but again I wouldn't recommend going down that path.

PHP was intended as a web development language, but you can write console scripts with it, and if you're feeling brave, use something like PHP-GTK to write GUI apps.

PHP makes a surprisingly good shell scripting tool. It has a wealth of simple functions built in.
File IO
String manipulation
Array manipulation
While you can do the same thing in JSP and C# you will spend a lot more time vs. any scripting langauge.
The biggest advantage PHP has over other scripting languages is PHP.net Documentation. Out of any language I have ever used this single resource defines what good documentation and organization of a langauge reference should be.

PHP can be run via an interpreter on the command line, so any computation task can be done in PHP. I don't know about desktop apps and GUI.

PHP has a runtime but it's not fully interpreted like some languages. For example, you can't redefine a method. As far as desktop apps, PHP has bindings for creating desktop apps but it's not very good. It's great for command line tools. Zend and CakePHP are two frameworks for web apps. PHP is like a very-easy to use version of C with a very good community of extensions (look at the extensions on php.net docs). PHP is well supported on windows (even by Msft).

Quite often it is the "limitation" or for want of a better word "focus" of a language that makes it powerful rather than weak.

I'd say PHP is best suited for web application development.
It does the job, and does it well.
But that's not to say that it is not useful for anything else. It can be used as a generic scripting language.
With Qt, you can even develop desktop apps using PHP. Check out http://php-qt.org/
But the focus must be with web apps: PHP was intended for the web.

Depends on what you consider powerful?
It is designed for server-side web-development, and it does that perfectly.
I can't see myself saying one language is more powerful than the other, as it is always a matter of preference, the task at hand and whether the language was designed for what you are trying to accomplish.

Related

Am I able to use JavaScript with the Java SDK?

I want to create a mod for Minecraft, and I am aware it uses Java. I am currently learning JavaScript, and was wondering if I am able to use JavaScript for the SDK.
Yes and no.
Java is not Javascript...but a Java project can interpret Javascript
Java and Javascript are two completely different languages. However, there is a javascript interpreter created in Java, that you can plug in to java, called Rhino. However, although Rhino makes it easier to embed Javascript into your Java code, its not a simple drop in solution that would allow you to simply script what ever you want with out going through the effort of makin the proper connections. Definitely achievable, but you wont likely be able to start scripting without making that time investment to connect Java and Javascript.
Background story
The relationship between Javascript and Java is a rather shallow one. The similar name comes from a marketing plan back when it was being released by Netscape (which most developers ended up moving to the non-profit Mozilla). They made a deal with Sun (bought by Oracle) to share that similar name, but purely for marketing purposes.
Yes, it is possible to run JavaScript within a Java program, using the Rhino Javascript engine (for example).
However, this would not be a good way develop a Minecraft plugin / mod. None of your knowledge of the Javascript APIs would be relevant. Everything you did to interact with Minecraft would entail using Java classes and methods in the Java or Minecraft libraries.
My advice:
If your aim is to avoid learning Java ... don't be lazy. (You'll end up having to learn the Java APIs anyway. And learning another language will be good for you ... assuming you aspire to be a professional programmer.)
If your aim is to integrate some pre-existing Javascript code-base, it might work. But you might be better off porting the Javascript code to Java.
Sorry, Java and JavaScript are totally different languages. The "Java" in both of them was a marketing decision from ancient times.
They do share some of the same syntax that many languages share, however, so if you have learned JavaScript it might be a little easier to get started with Java. They are definitely NOT interchangeable, though.
Have a look at JDK1.6's ScriptEngine, the interface whose methods provide basic scripting functionality. Using these methods you can execute javascript. Numerous examples can be found on usage of this.
script support is avail from jdk 6 onwards:
reference link
However, this is not a full implementation of Rhino.

What is Rhino in JDK useful for?

Rhino is a JavaScript interpreter running on top of JVM. I guess it was useful for server-side programming in JavaScript. Now we have Node.js. So I wonder if Rhino is still relevant and what it is useful for.
It simply provides a means to run Javascript in the JVM. As such it gives you another implementation choice on top of the JVM in preference to the Java language (in a similar fashion to JRuby, Scala, Groovy etc.). You can write complete solutions in Javascript, or mix/match with Java (or any other JVM language)
Note that this isn't specific to 'server-side' or any such deployment choice.
Speaking from personal experience, I've used it to provide trivial scripting in Ant deployments, and to provide an out-of-the-box simple scripting language for customers using Java applications/toolsets I've written.
Rhino is also used by the the HttpUnit library, which can be used in unit tests to emulate a web browser, for testing web sites. It gives the library JavaScript support.
I use Javascript with Rhino as a scripting language for my MMORPG server written in Java. It allows me to implement NPC scripts, item use scripts, event triggers and other server-sided interactive functionality in Javascript without having to touch the Java part of my server.
Implementing these features in Javascript makes the syntax for them much easier to write and read. Especially because I let the Java part of the server automatically add any trivial boilerplate code to the script sourcecode before sending them to the script engine. This further simplifies the javascript syntax.
It also allows a much clearer separation of the engine and the content.
I also added a Javascript admin shell, which allows me to run any Javascript code on the running server. This has proven to be a very useful testing and debugging tool and I expect it to be a very powerful administration tool later.
I could, of course, also have used any other scripting language, like for example Lua which is frequently used as a scripting language in game development. But Rhino is supported out-of-the-box so I don't need any additional 3rd party dependencies. Also, my client is a HTML5/Javascript application, so I don't have yet another programming language in the project. Note that although both the client and the server content use JS, there is no code shared between them - they are literally on the opposite ends of the system architecture and interact with each other through several layers of indirection, so there is no reason to share code.

Converting a Java Web Application to .Net

What is the process involved with converting a Java web application to something like ASP.NET with Silverlight or alike?
I know many Java frameworks have been proted to .Net (either C# or VB.NET), but haven't really seen many web applications done. (I might be very wrong here)
I also know very little about Java programming but know C#, VB.NET and ASP.NET. I haven;t looked at silverlight yet but know what it can do to some extent. I do know though that Java syntax is very similar to that of C, C# and C++ as they all the the "{}" brackets and layed out similarly.
For arguments sake (just to get a handle and example) what would it take to convert something like Alfresco to a .NET type web app? Also, just want to add that I am not planning on doing it but want to know that if its even worth investing time in looking into Java applications to port to .NET.
Microsoft used to distribute a 'Java Language Conversion Wizard' to convert Java code into C# code, including substituting some of the common framework classes. It needs a lot of cleanup after the fact, but may be useful depending on what sort of code you're trying to convert. If you have access to the VS 2005 tools you should be able to install it.
Other than that, it's heavily dependent on how the code's structured. Finding a web framework that's similar to the Java framework used would probably be helpful. In many cases, I suspect it would be easier just to port the database and master page templates/stylesheets across and build the rest from scratch.
This page on MSDN might be useful: http://msdn.microsoft.com/en-us/gg715299.aspx.
It does a conceptual mapping of concepts in Java to concepts in .NET.
Regarding Giacomo's mention of the Java Language Conversion Assistant (JLCA), it is in fact retired and I wouldn't recommend relying too heavily on it. As he says there's quite a bit of cleanup to do but much of that depends on how you architected your app.

Advantages of using Rhino (mozilla's rhino)

I've been reading about Rhino as a useful way to implement JavaScript inside my Java code.
After reading for a while, searching in google and here, I couldn't find a real reason for which I would use JavaScript inside Java.
Could you point some real world advantages you find on using Rhino for a regular Java application?
Note that since Java 6, the scripting API is in the standard Java library - see the documentation of the package javax.script. The API in javax.script is an adapted version of Rhino. The scripting API supports not only JavaScript, but many other scripting languages.
See Java Scripting Programmer's Guide
The front page there mentions some reasons you might want to use scripting:
Application extension/customization: You can "externalize" parts of your application - like configuration scripts, business logic/rules and math expressions for financial applications.
"Command line" shells for applications -for debugging, runtime/deploy time configuration etc. Most applications have a web-based GUI configuaration tool these days. But sysadmins/deployers frequently prefer command line tools. Instead of inventing ad-hoc scripting language for that purpose, a "standard" scripting language can be used.
An example: You can script Oracle Weblogic using Python scripts, for example to configure your application server domain, to start or stop the server and to do other administration tasks.
Processing XML with Rhino and E4X is a joy compared to most of the Java XML APIs
You have existing JavaScript that "just works" and you don't want to re-write it. This can happen if you have some calculation or processing happening on the client side and move it to the server.
All kinds of neat caching and code loading tricks.
Your problem is better solved by a more dynamic language then Java.
List comprehensions ;)
The benefit of embedding a script language like javascript into your software is that you can offer others a way to write plugins for your software without giving the source code away.
A reason to write the whole app in another language is that you are able to write an app for a company which deploys it in their Java EE environment without having to learn Java.
We use JS (via Rhino) for a DSL in one of our products. It isn't a great DSL, but that is a fault of how we use JS, rather than Rhino.
If you considering to .Net also, I suggests to get along with Rhino.
Besides Java enviroments, rhino is one of the best performance interpreter on .NET environment (using IKVM). On the other hands, nashorn is very slow on .net.
Porting your own Rhino project to .NET is not so difficult.

Webservices - Java or .NET?

I need to implement webservices in an upcoming project and wanted to know what are the main points to base the decision on whether to implement using java or .NET
I'm a C++er...
If you're a Java shop use Java. If you're a .NET shop use .NET.
There really is no difference that makes one of the two languages superior to the other in regards to web services.
Possible consideration - .NET pre 3.5 only provided support for SOAP based services, but I believe the 3.5 WCF offers REST and SOAP now.
There's no real difference from programmer's point of view (implementation).
For me, a reason to pick Java is that all tools and infrastructure are free/open source. OS, deployment web server, databases, IDEs and developer tools.
I have plenty of experience with both, and both will certainly do the job.
However I tend to prefer Java over .Net for things like web services for the following reasons:
It's cross-platform, which gives you much better options on the hosting side (e.g. running a big Linux cluster on Amazon EC2)
The library ecosystem is larger and more mature, especially on the server side.
I prefer the more flexible open source philosophy to "the only way is Microsoft". Vendor lock-in is always a bad idea for your enterprise architecture in the long run.
You can optionally use awesome languages like Clojure or Scala on the JVM
Ultimately though, I'd go with the one your team has the most skills with. This will determine what you are most productive with, which is usually most important if your main objective is to deliver value quickly.
It's a personal decision, usually determined by the technology already in place or the skill set of the developer(s) writing the services.
i've never really developed web services in java, but i have in .NET and if you're using Visual Studio they're an absolute cinch to whip up (i expect they're a little more difficult to do without the aid of VS).
if you're already working in java, and don't have any .NET stuff in place, stick with java - it'll save you a lot of money (if you were to get Visual Studio in, as i mentioned), and possibly some time involved in learning the specifics of .NET
In my experience, Web Services are a bit more tightly integrated into Visual Studio than they are into Java's editors.
The Eclipse IDE doesn't even have JAX-WS (Java standard web services stack) support built in, opting to use Apache Axis 1 instead.
Netbeans supports JAX-WS, though.
I personally prefer .NET to Java for many reasons I don't want to go through, since it doesn't really matter and is more a personal preference than a strict guideline I can recommend.
If you have Java infrastructure in place or using a platform other than Windows for your server applications, I strongly suggest Java. However, if you don't have anything in place and running on Windows platform, .NET is pretty cool in that area (WCF/ASMX/WSE/...).
As you say you're a C++ - er you'll probably find .NET easier as you can target it directly from C++.
I'm a Java guy, but I think Web Services are easier to code in .NET. Visual Studio takes care of everything, in Java it takes a bit to get started.
A bit of a problem in some projects with JAX-WS is, that SUN ships the "old" version 2.0 with Java 6. If you want to use the current version, it's some work to make it run with Java 5 and Java 6.
If your app must be portable, you should obviously choose Java. Otherwise I would say it's just a choice of your preferred language, since the above issues are really small (maybe you want to choose Axis or something else anyway, I haven't worked with something other than JAX-WS yet).
IMO if you want to do SOAP, then its a heck of a lot easier to use .NET and WCF. However, I've found REST to be a bit tricky with WCF, and had to implement a custom XML parser to do it instead of using their built-in one.
You probably want to consider your hosting environment too. If you are going to serve this from Windows hardware, you can drop .NET WCF web services into IIS. If you are going to run a Linux/Solaris server, then it isn't even a question...
I suggest implementation with JSP ,it provides a robust platform for development
I prefer JSP to ASP or any microsoft techonolgy!

Categories