Is it possible to use javascript instead of java in such conditions? - javascript

I made up desktop application using java few years ago. It is no problem to use until now, but these day I think it's better way to run web application than desktop, for some reasons. anyway, I use some objects in java desktop application, for example...
BufferedReader, DataOutputStream, InputStreamReader, OutputStreamWriter,
PrintWriter, HttpUrlConnection ....
Do javascript have such objects supporting similar fucntions...? I'm afraid to they don't have it. I'm just newbie on this, It is just a hobby. so I don't know much about it. but I heard these day's hottest language is javascript, so I just want to jump to javascript...so please help me if you know about something. thanks.

Although the default JavaScript language doesn't allow reading and writing to files the program node.js is designed to act as a server side JavaScript and does allow reading and writing of files along with a broad npm library to add different functionalities.
More information on the nodejs web site

Related

Wondering how to use Python within Node.js / Electron

I am working on an audio editing prototype. At the moment it is very simple, so it currently works as a Web App using JavaScript, HTML and CSS. This makes it possible to build as an Electron app, using Node.js to access the file system.
However, it makes heavy use of a Python program called Gentle, particularly the file align.py. I was wondering if it was possible to integrate this program somehow, given how frequently it is used.
I am not familiar with Python, but I have tried to work out if this can be done. I have read about child_process, python-shell and zerorpc. However, if possible, I do not want to force the user to install Python along with all the dependencies required for Gentle, as it is a difficult process with lots of room for error.
This is where I have become stuck. Ultimately I am looking for a way to use Gentle in a way which gives the appearance of it being part of the functionality as a single self-contained program, rather than butchered on with duct tape.
I realize Gentle includes the option for a REST API and a Python server, but I am more interested in using Gentle offline for faster functionality. I am also too broke to afford hosting.
I realize I am kind of working backwards, as the front-end normally comes after the back-end. If it is easier I can try to rewrite the code base in Python or a lower-level language, but I am trying to avoid this if possible.
Any help or suggestions would be greatly appreciated!
You can compile the Python program and include the resulting binary file into your Electron app and just run the binary via child_process. There are several ways to create executables from Python programs.

javascript IDE or visual studio alternatives maintain experience and quality of coding

i am a beginner in asp.net, and in a stage where most of my approach / implementation is moving more and more to using javascript and jQuery ... ajax all those J's family members , as opposed to coding server side C# ( which i really like working with)
as i have learned lately that if you are not using JavaScript often ,in your application it means you are not really building an application(web) ..atleast not a good one , as client side coding has it's way to simply be charming doing almost every thing i used to do , with c# . and it started from the full page postback issue i learned how to avoid by using $ajax , then got to know jQuery +jQueryUI... etc
My question is What could i use as an alternative to Vs , a suitable IDE or way to develop application besides use of Notepad++ (mentioned in a chat when i was asking about that question ) but an IDE , that will pay better attention to the existence of the javascript like the ExpressionWeb does better with Css for instance
If you're willing to pay for a commercial IDE, I'd go with WebStorm. In my experience, it has very good autocompletion and a complete feature set.
Take a look at Komodo Edit from Activestate. It actually parses your javascript files to generate things like tooltips, autocompletion etc. On top of that it actually comes with built-in database that understands jQuery and other popular javascript libraries.
It's also one of the best editors for mixed-language files like html and shell scripts. The commercial Komodo IDE has more features but the free Komodo Edit generally does everything a web developer needs.

how can i convert a javascript variable to a java string variable

I'm trying to get a javascript variable from my webview and convert it to a String variable in Java. But i'm new to javascript and can't figure out how i can do this.
Can anyone help me?
How about using the Android Java/JavaScript bridge to send data between the two layers. The integration technique is part of the core Android framework.
PhoneGap is also great but is overkill if you just want to stick to Android
Here is a tutorial on how this stuff works: http://code.google.com/p/openmobster/wiki/JavascriptBridge
Full Disclosure: I am the Chief Engineer of OpenMobster and I wrote this tutorial
There is no easy way to just pull a variable from client side javascript into application level Java. Hopefully someone can come along and give a good original answer. However, the PhoneGap library has an easy way to do this. PhoneGap can tie javascript events to native application events which is extremely useful. If you really want to do this I would recommend at least checking out PhoneGap.

Avoiding writing the same algorithm in multiple different languages

I am a web developer, and I have observed that many times I need the same function on both client and server. So I write it in JS as well as in PHP or whichever server side language. I am fed up with this. If I have to change it then I need to change it in both places. If I want to use it for some hand held devices, then I will have to rewrite that code yet again using objective-C or Java etc. Then if I need to change that function then I will need to change it everywhere.
Is there a solution for this? If I will call some webservice via ajax, then the client will have a delay. If it will be in JS then it can't be accessed from within PHP or Java, etc. If I use some service in PHP from another language then that can also become a performance issue.
It is also possible that some time we need such functions output from some paramters as input using db or without db.
I know there would be some pretty simpler solution but I am not aware of that. Please tell some language independent solution as I don't have VPS always.
I am not sure if my question actually belongs to stackoverflow.com or programmers.stackexchange.com so please transfer it to programmers.stackexchange.com instead of closing this question if it belongs to there.
Typically, the solution to this problem is to write common code in one language and use translators or library linking to allow access from other languages.
Node.js allows you to write server-side code in JavaScript.
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
You can also use JavaScript to write HTML5 apps for mobile devices.
"Building iPhone Apps with HTML, CSS, and JavaScript"
Now web designers and developers can join the iPhone app party without having to learn Cocoa's Objective-C programming language. It's true: You can write iPhone apps quickly and efficiently using your existing skills with HTML, CSS, and JavaScript. This book shows you how with lots of detailed examples, step-by-step instructions, and hands-on exercises.
If you don't want to try to write large complex applications in JavaScript, GWT provides a way to write Java and via-translation, run it on the client.
The GWT SDK contains the Java API libraries, compiler, and development server. It lets you write client-side applications in Java and deploy them as JavaScript.
If you develop in .Net languages: C# -> JavaScript ScriptSharp
Script# is a free tool that enables developers to author C# source code and subsequently compile it into regular script that works across all modern browsers
you could use the spidermonkey extension to translate php into javascript. this way you can write your functions in php then simply convert them to javascript and re-use them at the browser.
here is a good tutorial to show you how this is done

Should I use Google Web Toolkit for my new webapp?

I would like to create a database backed interactive AJAX webapp which has a custom (specific kind of events, editing) calendaring system. This would involve quite a lot of JavaScript and AJAX, and I thought about Google Web Toolkit for the interface and Ruby on Rails for server side.
Is Google Web Toolkit reliable and good? What hidden risks might be if I choose Google Web Toolkit? Can one easily combine it with Ruby on Rails on server side? Or should I try to use directly a JavaScript library like jQuery?
I have no experience in web development except some HTML, but I am an experienced programmer (c++, java, c#), and I would like to use only free tools for this project.
RoR is actually one of the things the GWT is made to work well with, as long as you're using REST properly. It's in the Google Web Toolkit Applications book, and you can see a demo from the book using this kind of idea here. That's not to say that you won't have any problems, but I think the support is definitely out there for it.
There's a neat project for making RoR/GWT easy that you can find here (MIT license). I haven't had a chance to try it out yet, but it looks like a good amount of thought has been put into it. One catch is that it looks like it hasn't been fully tested with 2.1 Rails yet, just 2.0, so you may run into a few (probably minor and fixable) errors.
If you are looking to integrate GWT with non-Java backends such as ROR, PHP etc., you should bear in mind that GWT 1.5 now supports JavaScript Overlay types. This feature lets you write classes that can be mapped over the top of native JavaScript objects to easily provide accessor methods for properties of those objects and other extended functionality.
See this link for more details:
JavaScript Overlay Types
So you could return JSON encoded data from your backend via AJAX calls, parse it into a JavaScript Object and then access the data through your GWT Java code using the overlay classes you've created. Or when you render your page you can render static config data as JavaScript Objects and read it in via this mechanism, rather than having to do an AJAX call to grab the data.
If you know JAVA, and have somewhere you can host it (like a tomcat or glassfish container) I would recommend that much more than using Ruby for the back end. The main reason is that then you can share all of your objects, and use the built in RPC mechanism. I've done this for quite a lot of our projects and it's a huge timesaver, not to mention that the code is less error prone, because you don't convert your java objects to anything and then back again.
I have linked my GWT with Rails before, using the to_json function in Rails and then reading the JSON in GWT. It's all supported, but it is far more annoying than just doing the back end in JAVA.
Of course if you have cheap hosting, then Java containers are pretty much out of the question, in which case I would think Rails would be the next best thing.
GWT is very high quality with a great community. However you do need to know CSS if you want to adjust the look of things (you will) - CSS can do a lot of the layout, just like regular web if you want it to. Libraries like GWT-ext or ExtGWT can help a bit as they have stunning "out of the box" looks but for a price (extra size to your app).
You can code everything in Java using GWT, and you can integrate existing 3rd party javascript libraries with it. It's very good. I've never used RoR much though, so can't say anything about that.
If you're experienced in Java but not in Javascript/CSS, then GWT is going to be a lifesaver (unless you want to learn them, of course). CSS has so many little fiddly details. It is not uncommon to spend half a day fixing a 2 pixel misalignment that only occurs in IE6.
I am not sure about how easy it would be to use ROR for the back end... It is possible, I am sure, since GWT ajax communication is just servlets. But they provide some really nice functionality for passing Java objects back and forth which you won't be able to utilize if your server isn't also using Java.
I wrote about some of the disadvantages of GWT recently. Mainly, the disadvantages are: long deployment cycle for changes to some parts of the application and a rather steep learning curve. As a seasoned Java programmer, the second should be less of a problem and if you use a seperate backend, the first is also mitigated (as a complete redeploy is primarily required when you change the 'server' part of the application).
GWT is a wonderful framework with lots of potential. Keep in mind that it's still quite new, though. There are some unresolved bugs that can really annoy you, and they usually require ugly workarounds to get past. The community is great but you'll probably end up with a few problems sooner or later that Google can't answer yet.
But hey, I say go for it. The potential for GWT is awesome, and I bet it's future will be bright.
You should definitely use GWT for a new project (it's pretty easy to use in an old project too).
I my experience it's very fast to learn and use. The compiled javascript code is much better than anything you could ever write by hand and it works fast too.
Another benefit is the ability to debug you're code (which is hell with javascript alone)
This blog has inputs from many experienced users of GWT and have some great discussion points. I personally have huge experience with varied UI Frameworks. I will add my two cents. Lets look at fundamental advantages and disadvantages of GWT
Fundamental Advantage
GWT takes the web layer programming to JAVA. So, the obvious advantages of Java start getting into play. It will provide Object Oriented programming. It will also provide great debugging and compile time checks. Since it generates HTML and Javascript, it will also have ability to hide some complexity within its generator.
Fundamental Disadvantage
The disadvantage starts from the same statement. GWT takes the web layer programming to JAVA. If you know JAVA, probably you will never look out for an alternative language to write your business logic. It's self sufficient and great. But when it comes to writing configurations for a JAVA application. We use property files, database, XML etc. We never store configurations in a JAVA class file. Think hard, why is that?
This is because configuration is a static data. It often require hierarchy. It is supposed to be readable. It never requires compilation. It doesn't require knowledge of JAVA programming language. In short, it is a different ball game. Now the question is, how it relates to our discussion?
Now, lets think about a web page. Do you think when we write a web page we write a business logic? Absolutely not. Web page is just a configuration. It is a configuration of hierarchical containers and fields. We need to write business logic for the data that will be captured from and displayed on the web page and not to create the web page itself.
Previous paragraph makes a very very strong statement. This will explain why HTML and XML based web pages are still the most popular ones. XML is the best in business to write configurations. A framework must allow a clear separation of web page from business logic (the goal of MVC framework). By doing this a web designer will be able to apply his skills of visualization and artistry to create brilliant looking web pages just by configuring XMLs and without being bothered about the intricacies of a programming language. Developers will be able to use their best in business JAVA for writing business logic.
Finally, lets talk about the repercussions in direct terms. GWT breaks this principal so it is bound to fail. The cost for developing GWT application will be very high because you will need multiskill programmers to write web pages. The required look and feel will be very hard to achieve. The turn around time of modifying the web page will be very high because of unnecessary compilation. And lastly, since you are writing web pages in JAVA it is very easy to corrupt it with business logic. Unknowingly you will introduce complexities that must be avoided.
You could also consider Grails ("Groovy on Rails") which gives you the benefits of a Rails framework and the use of the Java VM.
Our team recently asked the same question, and we chose to go with GWT, especially since the designer plugin made working with GWT more accessible to non-java experts on the team. Whoever makes this choice, just beware you DON'T use the GWT Designer plugin !! It has not been updated (in at least a year, apparently) to create a GWT application that is compatible with IE8.
Our team had almost completed our application layouts, which were working perfectly in Chrome, FF and Safari. Then they blew up in IE. IE 7 would load partial pages (but not composite includes), and IE8 was not even able to load up the application. It just hung.
The designer plugin has buttons that allow the user to add CellTable widgets that are not IE compatible (CellTable, DeckPanel, Horizontal Panel, Vertical Panel, among others). These will cause intense pain when the layouts have to be re-done in java without assistance from the designer.
Experienced GWT users love it, but the designer plugin will kill you.

Categories