Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

Using Stream in Java 8:
***
String[] both = Stream.concat(Arrays.stream(a), Arrays.stream(b))
.toArray(String[]::new);
***
Or like this, using flatMap:
***
String[] both = Stream.of(a, b).flatMap(Stream::of)
.toArray(String[]::new);
***
To do this for a generic type you have to use reflection:
***
@SuppressWarnings("unchecked")
T[] both = Stream.concat(Arrays.stream(a), Arrays.stream(b)).toArray(
size -> (T[]) Array.newInstance(a.getClass().getComponentType(), size));
***
4 years ago
Use setRoundingMode, set the RoundingMode explicitly to handle your issue with the half-even round, then use the format pattern for your required output.

Example:
***
DecimalFormat df = new DecimalFormat("#.####");
df.setRoundingMode(RoundingMode.CEILING);
for (Number n : Arrays.asList(12, 123.12345, 0.23, 0.1, 2341234.212431324)) {
Double d = n.doubleValue();
System.out.println(df.format(d));
}
***
gives the output:
***
12
123.1235
0.23
0.1
2341234.2125
***
4 years ago
For sorting an ArrayList you could use the following code snippet:
***
Collections.sort(studList, new Comparator(){
public int compare(Student s1, Student s2) {
return s1.getFirstName().compareToIgnoreCase(s2.getFirstName());
}
});
***
4 years ago
Run the command java -X and you will get a list of all -X options:
***
C:\Users\Admin>java -X
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:
set search path for bootstrap classes and resources
-Xbootclasspath/a:
append to end of bootstrap class path
-Xbootclasspath/p:
prepend in front of bootstrap class path
-Xdiag show additional diagnostic messages
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc: log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms set initial Java heap size.........................
-Xmx set maximum Java heap size.........................
-Xss set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs reduce use of OS signals by Java/VM (see documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.
-XshowSettings show all settings and continue
-XshowSettings:all show all settings and continue
-XshowSettings:vm show all vm related settings and continue
-XshowSettings:properties show all property settings and continue
-XshowSettings:locale show all locale related settings and continue
The -X options are non-standard and subject to change without notice.
***
I hope this will help you understand Xms, Xmx as well as many other things that matters the most. :)
4 years ago
The configuration property is called hibernate.hbm2ddl.auto

In our development environment we set hibernate.hbm2ddl.auto=create-drop to drop and create a clean database each time we deploy, so that our database is in a known state.

In theory, you can set hibernate.hbm2ddl.auto=update to update your database with changes to your model, but I would not trust that on a production database. An earlier version of the documentation said that this was experimental, at least; I do not know the current status.

Therefore, for our production database, do not set hibernate.hbm2ddl.auto - the default is to make no database changes. Instead, we manually create an SQL DDL update script that applies changes from one version to the next.
4 years ago
***
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='tableName'
***
This is better than getting from sys.columns because it shows DATA_TYPE directly.
4 years ago
***
DBCC CHECKIDENT ('TestTable', RESEED, 0)
GO
***
Where 0 is identity Start value
4 years ago
Does not matter for inner joins

Matters for outer joins

a. WHERE clause: After joining. Records will be filtered after join has taken place.

b. ON clause - Before joining. Records (from right table) will be filtered before joining. This may end up as null in the result (since OUTER join).
4 years ago
***
ORDER BY column1 DESC, column2
***
This sorts everything by column1 (descending) first, and then by column2 (ascending, which is the default) whenever the column1 fields for two or more rows are equal.
4 years ago
***
SELECT id,
IF(type = 'P', amount, amount * -1) as amount
FROM report
***

Additionally, you could handle when the condition is null. In the case of a null amount:
***
SELECT id,
IF(type = 'P', IFNULL(amount,0), IFNULL(amount,0) * -1) as amount
FROM report
***
The part IFNULL(amount,0) means when amount is not null return amount else return 0.
4 years ago
You don't have FULL JOINS on MySQL, but you can sure emulate them.

For a code SAMPLE transcribed from this SO question you have:

with two tables t1, t2:
***
SELECT * FROM t1
LEFT JOIN t2 ON t1.id = t2.id
UNION
SELECT * FROM t1
RIGHT JOIN t2 ON t1.id = t2.id
***
4 years ago
You can use sp_rename to rename a column.
***
USE YourDatabase;
GO
EXEC sp_rename 'TableName.OldColumnName', 'NewColumnName', 'COLUMN';
GO
***
The first parameter is the object to be modified, the second parameter is the new name that will be given to the object, and the third parameter COLUMN informs the server that the rename is for the column, and can also be used to rename tables, index and alias data type.
4 years ago