Need of println command in java [closed] - java

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.
Improve this question
In java language we use two print method. One is "print" and second is "println".
But why we need an extra command "println" if there is only one difference is that it insert a new line in last but we can use a new line character with print command like we use in c/c++.
Why an extra command added in java.

I m not sure about my answer, but maybe it is because if we have to give new line by ourselves in c we give printf("\n"), here the problem is that for every operating system new line is different.
For example:
in windows - "\r\n"
in unix - "\n"
in mac - "\r".
So in order to save the developer from remembering this println is used.
edits
for mac's new line feed refer this discussion- https://superuser.com/questions/439440/did-mac-os-lion-switch-to-using-line-feeds-lf-n-for-line-breaks-instead-of
Note as suggested in below comment by Honza Zidek:
1. Java also has printf() method and this one accepts a control sequence %n which is replaced by the proper end-of-line for the target OS.
2. There is a method System.lineSeparator() returning the proper end-of-line marker. See How do I get a platform-dependent new line character?

Related

How to pass empty args to Netbeans [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I tried to pass blank command line arguments in a Netbeans Java project using Properties-->Run-->Arguments with "" or '' but nothing.
I have some arguments that some times have to be empty or null.
The common way to handle that is to not specify arguments when they are blank or empty. It is quite the norm in the CLI/scripting world to work like this. Unspecified arguments mean either to use the defaults or no value.
Aside there are Java nice libraries to help you parse your program options or arguments, such as:
Args4j http://args4j.kohsuke.org/
Apache CLI http://commons.apache.org/proper/commons-cli/
EDIT
Additonal remarks:
Without a smarter options/arguments parser, it is not possible to handle empty arguments properly (i.e. just by setting a blank, whitespace or quoted empty string). The only way to achieve that would be to define a keyword or special character in order to identify empty/unspecified arguments when processing args[].
This behavior is not bound to Netbeans. Rather it relates to how Java parses the varargs of the main() method from the command-line.
Interesting links:
What is "String args[]"? parameter in main method Java
How to handle empty parameters in a main method java call

Extracting specific charaters on different lines in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a file "file.txt" in Java. In the file I have the following values:
10 10
3 3 W
MMMMMRM
4 4 R
LRLRLML
I want to read each line and with each character I want to assign them to a variable which I will use for calculation.
Any idea with how I can proceed with?
Thanks
1) You can use a BufferedReader with the readLine() method to read each line.
2) Then you can use split() for each word or toCharArray() for each character.
3) Then assign said character to predefined variables.
It would be helpful if we could see what you've tried so far or if you could give more details on what you are trying to accomplish.

trying to obtain a first name in the path after first back slash [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to display the first folder name from the path.
/mnt/sdcard/Videos/lk.jpeg, I want to display mnt string. in java
/mnt/sdcard/Videos/lk.jpeg--> **mnt**
You can split on / and use [1] element from result array.
You can either use regular expressions or you can use String.split(). Note that the split() result should be checked for live usage (e.g. if it has at least two elements).
String desired = "/mnt/sdcard/foo".split("/")[1];
String str = "/mnt/sdcard/Videos/lk.jpeg";
System.out.println(str.split("/")[1]);
Try this out. This is a poor question. But maybe the asker can be a newbie.

File in Database is only 1 slash instead of double slash [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
can someone give me a proper explanation why in java (or is this applicable to all programming language?) if the path is retrieved from the database, it is okay to use only 1 slash like '\192.168.173.220\folder\folder1\folder2' instead of '\\192.168.173.220\folder\folder1\folder2'.
When you write a String literal in Java source code, you need to escape backslash characters.
But in a String object ... which is what you get at runtime when you read a String from a database (or anywhere else) ... each character stands for itself.

Looking for regex to find a sequence of characters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I don't know a single bit about regex. I want to find certain occurences in my java project using eclipse. The words could be
SEQ_NUM
SEQNUM
SEQNUMBER
SEQ_NUMBER
searching strings based on word "seq" would generate lots of results. What regex should suffice my problem?
These four cases can be combined to the following regex:
SEQ_?NUM(BER)?
SEQ_?NUM(BER)?
SEQ - must exist
_? - '_' can appear 0 or 1 time
NUM - NUM must also exist
(BER)? - 'BER' can appear 0 or 1 time
This should work for you.
SEQ[_NUMBER]+

Categories