Is any way to convert a java applet code to java script?
Not really, no. They're different languages with different libraries.
If you want to develop for the client-side Web with Java, have a look at GWT
I don't think there is a good way to do so. Please remember: Java and JavaScript are two entirely different technologies. Don't mix them up.
Not directly and without effort as far as I know. However people have ported many things to HTML/JS, like Quake 2 on GWT. So you could invest some time and step into the code and port it with GWT.
Advantages of going with GWT arise from the fact that your applet is in Java language, which is the same language you use for GWT. Here is a list of what you can use in your code: GWT JRE Emulation
No.
Google Web Toolkit (GWT) is what you might need. I recommend book GWT In Practice 2008
12 years later there is now a tool called "JSweet" which claims to do exactly that: converting Java code to JavaScript: https://www.jsweet.org/
There is also a blog post from 2019 of someone using JSweet to convert some Java Applets to JavaScript: https://www.lprp.fr/2019/08/jsweet-convert-applets-to-javascript/
Related
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.
I am trying to write an extension to google chrome and I want to use my own java classes and it's attributes, methods inside a javascript code. I search on the internet but I did'nt find enough resources in terms of implementation. Can you give me any idea how to integrate and use my own java classes inside a javascript code. If you can help me , I will appreciate
Thanks.
This will not work. Both are totally different programming languages. Javascript is a script that is interpreted by the web browser. Java is a object oriented programming language that needs to be compiled and run in a virtual machine (JVM). Many people are confused by the similar names.
Isn't Google Web Toolkit (GWT) what you are looking for? It translates code written in Java to native Javascript to be run on the browser.
I wonder if it would be possible to integrate the generated code with your code, to run it as a browser extension, though.
If you need only instance variables of your classes, you would do well by converting your object into JSON and sending it to you extension. Check http://www.json.org/java/index.html. As pointed out by Marcelo, GWT will help you but only if you are deploying your app on Google App Engine. It is not for chrome extensions.
I guess you wanted a bean like access from a scripting language to java 'objects'..
http://commons.apache.org/bsf/ may help you to access Java objects and methods from scripting languages.
it claims to support javascript.
Mozilla has something like this through XP-COM.
also: see this, Chrome and XPCOM
I am wondering if you found a solution to this.
If I have implemented a Java Library (that offers certain functionality), could I transform this into a JavaScript library, such that the same functionality can be offered?
I know this may be an ask, but, I was wondering if there are frameworks existing that help in this?
No, in general this is not possible, Java and JavaScript are more or less completely different languages.
However there are a couple of Java to JavaScript translators that you can try. Java2Script is one such tool. Apparently the Google Web Toolkit (GWT) does this as well. Source.
While you could probably do some sort of conversion, it's important to note that Java and JavaScript, while similarly named, are not at all related. Unfortunately, I think you'll be hard pressed to find a framework or system that does a good job converting one to the other. :(
I am a .NET Developer with about 5 years of web development experience using Microsoft technologies starting with classic ASP to ASP .NET 3.5.
I do have a little background in Java as well and can write/understand Java code very easily. I am looking for resources (online, books) that are compatible with my .NET experience. I am only interested in web development in Java and want to start at intermediate level even if it may require me to look up some details.
What path or resources would you recommend for intermediate .NET web developers to gain equivalent proficiency in Java web development tools?
Get an IDE: IntelliJ (my preference), Eclipse, Netbeans;
Get an application server: Glassfish (my preference; either v2 or v3 Prelude), JBoss or, if you're feeling adventurous, SpringSource dm server;
Get a JDK eg 6u11;
Get a copy of Spring 2.5.6 (or 3.0M2 if you're feeling adventurous);
Get a copy of the Spring reference documentation;
Put the pieces together.
Get yourself a copy of eclipse, and just start reading other people's code, and reading some java docs. The Java website has all the docs online, and they're one of the best language specs I've seen.
Really, if you know C# pretty well, Java should be a cake walk. The languages are pretty similar, so you just need to get to know the different frameworks.
Probably the most helpful book in regards to learning Java's web development framework, Java Server Faces:
Core JSF
- Great examples and explainations throughout on the whole process of using the JSF Framework.
And of course for anyone new to Java I would recommend:
Effective Java
- Covers various design patterns and practices.
In my experience that official Java exams are better than the .Net equivalents, so it may be worth starting there?
Search for a servlet/JSP tutorial (Good, albeit a little old, example here).
You'll get basic knowledge of Java web application development.
Whatever your level is, JSF for Nonbelievers is the best introduction to JSP/JSF.
I'd check out Bitter Java.
It's a book that shows you the wrong way to do things, why it's wrong, and then it shows you the right way.
It pretty much falls in line with the evolution of the j2ee framework. Started with servlets, then moved into jsps, then command pattern, etc.
I am interested to create a drag-and-drop layout designer using only JavaScript, HTML and CSS. The designer will allow the user to drag the page elements from one place to another (something like Blogger's layout designer) to create a site layout. But I don't want to hand code everything in JavaScript, I would prefer to write my application in .NET (preferably) or Java and rely on a compiler to compile it to JavaScript and HTML.
What are the .NET or Java to JavaScript compilers that you have used and can recommend? For Java to JavaScript I know GWT is available. What about .NET to JavaScript? Microsoft did come out with Volta, but the project seems to be no longer available.
Look no further, you already mentioned GWT pick that!
It has a very good API and many good applications have use them.
Even JavaScript frameworks like http://extjs.com/ have GWT support.
I use it for an small JavaScript calendar recently.
To be honest, I don't really like JavaScript that much. Most of the times the errors are hard to track (specially for a non JavaScript guy as me) and the workarounds included some plug-ins for the explorer just to get exactly what a compiler should do. Catch silly error early.
In the other hand I'm very familiar with the Java Programming language, and many of the libraries (if not the most important) such as java.lang and java.util have been ported to GWT.
Plus, the guy who wrote relevant parts of java.util is the same behind GWT (google Joshua Bloch.)
Check out Nikhil Khotari's Script# project. It allows you to write C# code and compiles it to JavaScript.
Script# has already been mentioned. It hasn't been updated since August 2008.
Milescript is another, but also has seen very little for 6 months.
Extsharp for the Ext library. Adds Ext support for Script#
Javascript compiler to Java (going the wrong way for you)
Java to script Eclipse plugin
My issues with Script# (a known issue) is it doesn't support jQuery yet. However it comes with a very lightweight library to tie in with the .NET framework, in Nikhil's sscorlib.js file and ssfx.core.js files. And also has support for lots of other Javascript APIs (mostly Microsoft, seeing as he is in the ASP.NET team).
I'd love to see a Script# extension for jQuery (I'm thinking about writing it if it's easy enough). As it stands, most don't provide full compilation yet but they're certainly getting there.
Update: I wrote a small extension to enable JQuery support Script# a few months ago. The project can be found here.
I'm going to second the use of GWT. I've used it for several projects and, when used in combination with a modern editor like Eclipse or IDEA, it really makes the mess manageable.
It's important to note that not only does it allow you to write in Java and have that transformed into optimized and obfuscated Javascript it also comes with a substantial subset of the core Java API. In addition to this they provide lots of additional classes for doing things like parsing and working with JSON and XML and communicating with a server via asynchronous HTTP. You can check out the docs to get an idea of what else they offer.
Another feature that might be of special interest to you for implementing drag and drop functionality is it's integration with javascript libraries like Ext and scriptaculous. Either through pre-built interfaces or via JSNI
Also for Java there is J2S.
Java2Script (J2S) Pacemaker provides
an Eclipse Java to JavaScript compiler
plugin and an implementation of
JavaScript version of Eclipse Standard
Widget Toolkit (SWT) with other common
utilities, such as java.lang.* and
java.util.*. You can convert your
SWT-base Rich Client Platform (RCP)
into Rich Internet Application (RIA)
by Java2Script Pacemaker.
This means that if you use the SWT IDE (drag and drop) you can then convert the generated code to JS + HTML.
I wouldn't hand write any Javascript for UI. This can lead to maintenance disaster. jQuery is what I am using but I still wouldn't use it to write full UI Javascript code. ExtJS is also another good option if you plan to write in Javascript. In general what I am saying here is that it's so much easier to main in Java/C# than Javascript. Check out cappuccino framework and Atlas. Never used GWT. Script# is similar to GWT but for ASP.NET framework. Also depends on the requirement, if your site is public facing then RIA isn't a good option. It's all about which extreme end you pursuit (hand written and web standard, or RAD or libraries like jQuery/ExtJS as the middle option).
Check out Axial, a .NET to JavaScript converter that works well in ASP.NET. It supports WebForms, jQuery and canvas. It's not very mature, but it's worth a look.
http://jsc.sourceforge.net/ is a C# to JavaScript, Java, Flash and PHP compiler.
JscriptSuite offers another free .NET to Javascript compiler. There is a big difference to Saltarelle (jsc, SharpKit# etc.). Developer write down and debug only C# code (or any other .NET langauge), like in GWT. Javascript will be generated für deployment only.