How should I name a Java package? [duplicate] - java

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

Related

Regular expression to find the words with specific start and end characters [duplicate]

This question already has answers here:
How to remove square brackets and anything between them with a regex?
(3 answers)
Closed 2 years ago.
I have a some text copied from the internet. It contains lot of places, those I have to remove. Few lines and occurrences are these:
"
related to such contracts.[79]
References[edit]
smart contract platform.[65][66]
Quorum.[63] It's designed
separate version became Ethereum (ETH) with the theft reversed,[12]
and the original chain continued as Ethereum Classic (ETC).[13]
"
I tried using help on the internet:
^[\[]* [\]]$
I have to delete all [*]. And I have to get below output.
"
related to such contracts.
References
smart contract platform.
Quorum.It's designed
separate version became Ethereum (ETH) with the theft reversed,
and the original chain continued as Ethereum Classic (ETC).
"
Is it what you're trying to achieve ? Please confirm.
(?:\[\w+\]*)
Test here : https://regex101.com/r/nr0H99/2

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 to handle acronyms in class names? [duplicate]

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

# 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