I have been following along on this beginner's tutorial (https://developer.android.com/training/basics/firstapp/creating-project) on Android application development to help me create my first Android application.
For the "Configure your project" window, the tutorial suggests using "com.example.myfirstapp" as a package name. Obviously, my real app would not be called "myfirstapp", and it is not restricted to ".com" (can be ".io" or ".org" as well), but this is just an example.
Let's say that I design an app called "Application XY". When I use a version control system, such as Git, I would name the repository "application-xy". I usually make use of the free tier of GitHub Pages, which allows organization sites with the URL structure: "https://application-xy.github.io/".
I was thinking of using the above URL as a package name for my Android application, but I wanted to make sure that Android and Java will not throw any errors if I name my application package "io.github.application-xy" (the special character in question is a dash "-", but this could also apply to asterisks "*", pound signs "#", etc.).
Thank you!
A Java package name is a sequence of simple identifiers separated by dots.
Each simple identifier is made up of Java letters and Java digits (these are not limited to just the letters and digits in US ASCII).
Underscore is allowed in Java 8 though I've heard rumours it's being deprecated.
Hyphen/dash/etc. are not allowed.
Link to Java language spec for package names.
Link to Java language spec for identifiers.
Related
I learnt that, Java allows file names to have unicode characters.
How to name a file,
naïve.java,
using english keyboard?
Is there a notation similar to unicode escape notation(used in java source code) that we can use to name java files with unicode characters?
It seems that you are referring to JLS §7.2 “Host Support for Packages”:
A package name component or class name might contain a character that cannot correctly appear in a host file system's ordinary directory name, such as a Unicode character on a system that allows only ASCII characters in file names. As a convention, the character can be escaped by using, say, the # character followed by four hexadecimal digits giving the numeric value of the character, as in the \uxxxx escape (§3.3).
Under this convention, the package name:
children.activities.crafts.papierM\u00e2ch\u00e9
which can also be written using full Unicode as:
children.activities.crafts.papierMâché
might be mapped to the directory name:
children/activities/crafts/papierM#00e2ch#00e9
Note that this is described as a convention and only for characters not being supported by the host’s filesystem. So the first obstacle is to find a system without Unicode support in the file system API before you can check whether javac still adheres to this convention.
So for most systems, if you want to name a file naïve.java, there’s not only support to name it directly that way, you also have to name it that way as the fallback escaping scheme is not supported by tools designed to run only on systems which don’t need it.
That leads to your other question about how to enter it via the keyboard. Well, that’s system dependent. The most portable solution is:
open your browser
navigate to this question and mark naïve.java with the mouse
press ctrl+c
use your favorite tool to create a new .java file
when asked for the new name, press ctrl+v
As a general solution, refrain from using every feature, the Java programming language offers…
All String objects in Java contain UTF-16 Unicode. All Java objects that open files eventually name those files strings.
However, your keyboard is not Java's problem, it's your operating system's problem.
So:
File foo = new File("n\u00e4ive.java");
You edited the question to say that what you really want is to have a Java source file with interesting characters. That's a matter for your favorite text editor and operating system.
Java is perfectly happy to compile files with arbitrary names. However, creating those files and managing those files is not its problem. How you would go about creating such a file is between you and your operating system. Windows, Linux, OSX: all have different tools for entering Unicode characters that aren't part of the obvious keyboard map.
I have written comments in English in my Java files but now my client wants it in Spanish, So is there any tool/Plugin available in RAD or ECLIPSE IDE to convert all the comments in other language. I am using google translator to convert comments manually.
I'm not aware of any plugin like that. First, I would make sure the client really really wants this. Doing an automatic translate of highly technical text will not give a very good quality. I question if they will be usable at all, do a test translate of a couple of comments first to get approval.
If they really want something that is usable someone with language and technical skill would have to manually translate everything, which would take time/money.
But, if I had to do it, I would take the idea from this answer to automatically launch a web browser from Eclipse, and use the URL to google translate, https://translate.google.se/#en/es/${selected_text}, should work.
If the codebase is large and the comments can be easily found, such as a javadoc, I would write some script to automatically handle this. Google translate has an API you can use. See REST API doc
Every now and then a developer has to work on a code base that is in a language that is unknown to him. In this case, he would need to copy variable, class, method names to Google Translate to see what they actually mean.
The Source Code Translation in Eclipse tries to help such developers, by providing a popup with the translated words, when hovering the mouse over them. The plugin is able to handle compound words or phrases that use camelCase or underscore "_" as separation methods.
For the plugin to work, a properties file containing the word to be translated, and the translation needs to be created and added from the Preferences section of the plugin.
Add this URL to your Eclipse Installation to reach this solution's update site.
https://github.com/Testehan/TranslationPluginInstall/raw/master
In External Tools Configurations
Location : ${system_path:cmd.exe}
Arguments : /C start "" "https://translate.google.com/#en/fr/${selected_text}"
I'm a new programmer at a software house, and let's just say I can't make too much modification that includes a major changes, for example like adding library. In the current project, we're using JSP and Servlet, and some other advanced GUI that I never knew (they said it's a derivative of Eclipse, called Enfinity). The Enfinity also hides the libraries under obscure locations, and it's very different than in Java. So I don't think I will able to understand about the library location too, moreover adding some new library.
The problem here, I need to escape HTML characters like &, <, >, ", and ', but when I search solution on the internet, usually the solution involves using JSTL ( c:out or ${fn:escapeXML} ) or importing a library (Spring's HTMLEscape, or Apache's StringEscapeUtils). JQuery, on the other hand, is imported, but sadly, not related to solution. But the problem is JSTL is not part of the library readily imported into the project. Java, JSP, and Servlet are kinda new to me, as I didn't get Java at all in my college, so I don't know either what library is standard in JSP (already present, without I have to add it physically). I don't even know whether the Apache's StringEscapeUtils is present or not. Do you have any suggestion / codes on how I should escape the HTML characters under my circumstances? Thank you very much.
If your target platform is really Enfinity - as you are stating in your questions and in the tags - you should be using the Enfinity constructs even though this is not completely what you know from JSP. Please allow me to reopen this old thread and try to help you with that.
Enfinity got an own "templating language" called ISML. In the end ISML is precompiled to JSP. You can find a documentation with any installation of the Enfinity application server (a PDF called enfsuite_dev_programming). You should ask your project manager or build engineer if you don't have it available.
On the other hand I read from your statement that you possibly have the Enfinity Studio available (which is the IDE of Enfinity - a derivate of Eclipse. You should be able to access the developer guide through Enfinity Studios Help Menu. This menu may have some errors in some versions of the Studio unfortunately. However, you can get there through Window > Show View > Other > Help. On bottom of the help window is a "Content" link that will take you to the overview. The developer guide is under the table of contents link Enfinity Suite Application Programming Guide.
However you get to the guide: in the appendix you find a section "Reference > ISML Tags / ISML Functions / ISML Modules". Browsing through it you will find the function:
<isprint value="#value#" encoding="on|off">
Encoding is "on" by default and this statement will do exactly what you need: it will encode all HTML special characters in #value#. The special here is that the key value matches to an object in the so called Pipeline Dictionary which is a construct storing objects coming out of the Enfinity business logic workflow layer (so called pipelines).
This pipeline dictionary can be manipulated in JSP using:
Map<String, Object> pdict = getPipelineDictionary();
The dictionary is a standard java Map and can be manipulated using the known operations. However, the preferred way would be using pipelines or at least the respective ISML tag
<isset name="name" value="#value#" scope="request|session">
A full example for usage with JSP/ISML would be:
<%
String myString = "<b>Test</b>";
getPipelineDictionary().put("myDictKey", myString);
%>
<isprint value="#myDictKey#">
You can import org.apache.commons.lang.StringEscapeUtils and add its jar file. That are not by default present in jsp/servlets. It will provide you facility to escape characters from html, mysql, xml etc. Also you can make your own method to check for the character sequence and then use it as a escape function to escape data you want.
Hello there fellow Android developers. I am looking for some feedback. I am about to do a major international deployment of an android application. Something I need to worry about is language settings. What I have done right now is used the default language setting specific /res/values- setting where you have multiple folders called values-en, values-es, values-pt, things like that. So what I am wondering the following.
When my android default strings.xml is in English, will the way I am handling language be sufficient. It works here in development and probably deployed from the US store. But when deployed from other stores will the device think, I am from the Spanish store so the default strings.xml file should be in Spanish, or will it know, I am Spanish store so I will use values-es?
Anyways I would like feedback from someone who has deployed like this before please. It seems to be a question that is pretty guessable, however I am wanting to confirm with other developers what their experiences have been.
Thanks,
Anthony
If your read this page, it stated :
To add support for more languages, create additional values
directories inside res/ that include a hyphen and the ISO country code
at the end of the directory name. For example, values-es/ is the
directory containing simple resourcess for the Locales with the
language code "es". Android loads the appropriate resources according
to the locale settings of the device at run time.
Add the string values for each locale into the appropriate file.
At runtime, the Android system uses the appropriate set of string
resources based on the locale currently set for the user's device.
The language folder that is used is based on the user's selected language, not anything relating to where they are. You can test what each language looks like in your app by changing your device to a different language.
From my experience, the selected language resource is based on the selected language on device, so no matter which store your app is downloaded from, if the device language setting is english, values-en will be selected.
But you don't need to worry about it, as long as you have i18n files for all language you want your application to be translated to, the device will do the rest of the work for you.
I am developing one Android application in three languages named English,Spanish and German.First I completed development in English and wish to complete it in other two languages. Here my question is:
Can I use the same code of Android project(which is in english) in the other two languages with different package names in the same project ?.
Please help me with the sample code/links.
of course you can. Follow these steps
make sure all of your strings through the application are listed as a resource in yourAppFolder/res/values/strings.xml and that you use strings in your app only via getString(R.string.myString1) and NEVER via hard-coded strings in your activities
create a new folder for each language you want to localize your app with the following syntax: for germany, values-de
copy the strings.xml file in the new folder you just created
translate each string in the file into your desired language
Now android OS will use the proper language based on the device's locale.
I bet that you don't fulfill requirement #1 and that will be the most of your work to do. At least that was happened to me in my first real android app ;)