How to handle acronyms in class names? [duplicate] - java

This question already has answers here:
Naming Conventions For Class Containing Acronym
(3 answers)
Closed 9 years ago.
Instead of explaning I'll provide a simple and short example:
I would call a class that parses XMLs XMLParser. Sometime I run into problems,
e.g. I want to create a class that labels XMLs, but XMLLabeler seems kind of odd, because of the two same letters.
Since XML is a wide spread term it should be no problem to resolve this 'issue',
but for more complex acronyms this leaves a bad taste.
How would you handle these kind of things? Stricty applying camel case? I. e. XmlParser, XmlLabeler? Are there any naming conventions for acronyms in class names?

Camel Case (XmlParser) is the preferred way because it is easier to read

Related

Convert a serialized Java object to C# object [duplicate]

This question already has answers here:
Deserializing a java serialized file in C#
(3 answers)
Closed 6 years ago.
I have a very old Java application that I am rewriting in .net, I can't change the Java code or the old files in any way.
They have created and stored 10,000+ files that match the format described in this article, a bunch of serialized Java objects.
Question
How can I parse these Java objects in c#?
Is this even possible?
In the end, if I can read in and serialize the data, I can store it in a more universal format. When I try to deserialize the file I reach an exception, usually telling me the binary format is not valid.
A similar question has been asked here.
You have a few options. One is to write a C# class capable of reading objects in Java's serialized format (the one you linked) but this is likely very time consuming. Using C#'s native deserialization algorithm won't work because the format is different (as you've encountered).
An easier alternative is to read the objects from the files using a Java program, and save them as a more universal format such as JSON. (As recommended in an answer to another question here)

Extract a date in various formats from a String? [duplicate]

This question already has answers here:
Parse any date in Java
(6 answers)
Closed 7 years ago.
I would like to know if there is a easy way to extract the first encountered date from a String in Java.
My program will analyse a lot of String texts, in different languages. These Strings can contain a date. Because of the languages (and the different sources), I have an awful lot of formats to take into consideration.
I first thought about Regex, making one regex for each format I could find... But there are an awful lot, for exemple "Month (d)d, yyyy" or "mm/dd/yyyy" or "dd-mon-yyyy"...
So I wanted to know if there is an easier way to extract date from a String maybe by using DateFormat, so I can convert the found date to "dd/mm/yyyy".
Thank you for your help. ^^
I think the best solution is to use a regex, but obviously you have to know all the possible patterns.
A (possible) way to do this is by means of machine learning: you can provide a set of representative examples and let the algorithm finds the patterns for you.
Your problem is really similar to the one addressed in this article.
You can try to use this webapp to find a good regular expression for you.
The main problem is that you have to provide significant examples.
I hope this will help you!

Are class names allowed to be lower case [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
The community reviewed whether to reopen this question 8 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I ran my program successfully when declaring a class name starting with a lower case letter. I don't understood why it is asked to start with first capital letter.
You can declare it with lower case, but the convention is to start with a capital letter. The conventions were created to make it easier on others to read and understand your code.
Unlike this definition :
class someClass
{
otherClass b = null;
}
Sticking with the conventions even helps Stack Overflow color your code in a way that makes it more readable :
class SomeClass
{
OtherClass b = null;
}
It's not a matter of can but rather a matter of should. Java naming conventions dictate that class names should begin with an upper case letter. By following conventions, others (including us and your instructors, bosses and co-workers) can better understand and evaluate your code. If you need our help in the future with your code, this can make a big difference. There can be some local variability in some specific rules, so you will want to learn and follow all the specific rules of your office / school.
For more on this, please see Java Naming Conventions.
Also, some code editors/IDEs will hyphenate or space out related generated code file names based on capitalization in your class file.
For instance, Android Studio(https://developer.android.com/sdk/installing/studio.html) will read a Java Activity's class name, and insert a hyphen or underscore when you transition from a capital to a lower case letter for the file name of the layout.
An example: When creating a new activity(which is just a new class) called "MyActivity.java", Android Studio will also create a new layout file called "activity_my.xml" and link to it in the java file.
By sticking to the convention of capitalizing your class names, not only is your source code easier for others to follow and learn, but it will be much easier for you to navigate and keep track of files in your project. Naming conventions are everything.
Nothing happens if class names are lower case or upper, as long as the the code runs, then it shouldn't be a problem.
Its doesn't matter whether you choose uppercase or lower case but just for code to be readable without ambiguity.

How should I name a Java package? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What package naming convention do you use for personal/hobby projects in Java?
I am learning Java and have found a problem. I would need a domain name for my packages, but I don't have one. I wouldn't like to use my email address. So should I make an account on SourceForge or GitHub and use that? If so, which one is best? Or is there another, better method?
Thanks
A common naming scheme used is the following (| means or):
country| org|com.name.applicationName.subpackages
Name is either a company or your name. And after the applicationName you start all your subpackages (that is what I mean in the end) e.g. util, ui,db etc
For example if you are John Dave from England use en.jdave.smartapp.ui.core.forms. Or Marcus German From Germany: de.mgerman.smartapp.ui.core.forms etc
Generally Profession uses package name according to there reverse Site name
For instance
com.site_name.applicaton_name

# in java string instead of backslashes [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Raw Strings in Java?
In C# there is such a thing as # ("at sign") that can be put before string if forbidden symbols occurs. For example:
#"a\b\c"
In java I have to put backslashes
"a\\b\\c"
Is there any way in Java to make this easier?
Another way may be use equvivalent code for the symbols you want to escape.
Not really. I have made the transition not long ago and at first was constantly looking for "what is C#'s equivalent in Java for xyz?"
This is sometimes helpful but mostly frustrating. C# is a much more advanced language than Java and it will take a long time for Java to catch up.
You get used to it over time :-)

Categories

Resources