Difference between revisions of "IT-SDK-Java"
Jump to navigation
Jump to search
Samerhijazi (talk | contribs) (→Installing Java) |
Samerhijazi (talk | contribs) (→Ubuntu) |
||
| Line 46: | Line 46: | ||
sudo apt install openjdk-17-jre ### JRE | sudo apt install openjdk-17-jre ### JRE | ||
sudo apt install openjdk-17-jdk ### JDK | sudo apt install openjdk-17-jdk ### JDK | ||
| + | </pre> | ||
| + | =Settings= | ||
| + | <pre class="code"> | ||
| + | -Xms1g ### Setting the initial and minimum heap size for 1G. | ||
| + | -Xmx1g ### Setting the maximum heap size for 1G. | ||
| + | -XX:+PrintGCDetails ### Detaillierte GC Logging. | ||
| + | -XX:+PrintGCDateStamps ### Jeder Zeile eine absolute Datums- und Zeitangabe vorangestellt. | ||
| + | -Xloggc:file.log ### Das GC Log wird in der Datei <file.log> geschrieben. | ||
</pre> | </pre> | ||
Revision as of 09:13, 10 June 2022
Contents
Ref.
- http://tutorials.jenkov.com/
- Books: https://www.manning.com/
- Tutorial: https://www.javatpoint.com/java-tutorial
- Tutorial: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/object-oriented-programming
- Tutorial: https://www.tutorialspoint.com/design_pattern/index.htm
- Tutorial: https://howtodoinjava.com/
- Patterns: https://en.wikipedia.org/wiki/Facade_pattern
- Patterns: https://www.baeldung.com/java-core-structural-patterns
- https://www.jrebel.com/blog/what-is-jrebel
- Hibernate: http://hibernate.org/
Tools
Setting
* JAVA_HOME=C:\sdk\Java\jdk_1.8.0_65 * JDK_HOME=%JAVA_HOME% * JRE_HOME=%JAVA_HOME% * ---------------------------------- * Windows: PATH=%JAVA_HOME%/bin * Linux: PATH=$PATH:$JAVA_HOME/bin
Installing Java
- Java Version 21 Long-Term-Support (LTS), 2023 September
- Java Version 17 Long-Term-Support (LTS), 2021 September
- Java Version 11 Long-Term-Support (LTS), 2018 September
- Java Version 08 Long-Term-Support (LTS), 2014 March
Settings
sudo update-alternatives --config java sudo update-alternatives --config javac
fedora
sudo dnf install java-17-openjdk-devel ## JDK sudo dnf install java-17-openjdk-headless ## JRE-Min sudo dnf install java-17-openjdk ## JRE-Full
Ubuntu
sudo apt install default-jre ### JRE sudo apt install default-jdk ### JDK ---- sudo apt install openjdk-17-jre ### JRE sudo apt install openjdk-17-jdk ### JDK
Settings
-Xms1g ### Setting the initial and minimum heap size for 1G. -Xmx1g ### Setting the maximum heap size for 1G. -XX:+PrintGCDetails ### Detaillierte GC Logging. -XX:+PrintGCDateStamps ### Jeder Zeile eine absolute Datums- und Zeitangabe vorangestellt. -Xloggc:file.log ### Das GC Log wird in der Datei <file.log> geschrieben.
Keystore
keytool -importkeystore -srcstorepass [password] -srckeystore [keystore_source.jks] -destkeypass [password] -deststorepass [password] -destkeystore [keystore_destination.jks] -noprompt ### Merge two keystores keytool -list -v -keystore keystore.jks ### Check which certificates are in a Java keystore keytool -list -v -keystore keystore.jks -alias mydomain ### Check a particular keystore entry using an alias
- Convert a PKCS12 file to a JKS file.
keytool -importkeystore -srckeystore certificate.p12 -srcstoretype PKCS12 -srcstorepass <certificate_password> -keystore <keystore_filename> -storepass <stored_password>
- Convert a PKCS12 file to PEM files.
openssl pkcs12 -in file.p12 -out newfile.crt.pem -clcerts -nokeys ## certificate openssl pkcs12 -in file.p12 -out newfile.key.pem -nocerts -nodes ## private key
Maven
- ref: https://maven.apache.org/guides/mini/guide-multiple-repositories.html
- ref: https://www.vogella.com/tutorials/ApacheMaven/article.html
wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
sudo tar xzf apache-maven-3.6.3-bin.tar.gz
sudo ln -s apache-maven-3.6.3 maven
sudo vi /etc/profile.d/maven.sh
-------------------------------------
export MAVEN_HOME=/opt/maven
export PATH=${MAVEN_HOME}/bin:${PATH}
-------------------------------------
source /etc/profile.d/maven.sh
mvn -version
mvn archetype:generate -DgroupId=net.samerhijazi -DartifactId=maven-startup -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
mvn clean mvn compile mvn package mvn dependency:list-repositories mvn dependency:tree mvn dependency:analyze mvn dependency:copy-dependencies mvn dependency:get -Dartifact=com.google.protobuf:protobuf-java:3.19.1 mvn dependency:get -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0
Code-Collections
import java.util.concurrent.TimeUnit;
---------------------------------------------
try {
TimeUnit.SECONDS.sleep(secondsToSleep);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
---------------------------------------------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import io.agroal.api.AgroalDataSource;
public class SettingDatabase{
AgroalDataSource dataSource;
String db = "jdbc:db2://localhost:5245/DATABASE:user=db2;password=db2;";
String sql = "SELECT * FROM users";
public void init_DriverManager()throws SQLException{
try{
Connection connection = DriverManager.getConnection(db); //Connection connection = AgroalDataSource.getConnection(db);
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
}
}
}
Architekture
Database
- JDBC is a low level standard for interaction with databases. JPA is higher level standard for the same purpose.
- JDBC allows you to do more things with the Database directly. JPA allows you to use an object model in your application.
- Datasource & Pooling (JDBC) >> Agroal
- Datasource & Pooling (Reactive) >> Vert.x
- Agroal is a datasource connection pool implementation with integration with transaction, security and other systems.
- Agroal library allows the definition of java.sql.DataSource with connection pooling.
- JPA (Java Persistence API) & Hibernate ORM (Object-relational mapping). JPA is only a specification. Hibernate is an implementation of JPA.
- JDBC: https://quarkus.io/guides/datasource
- Reactive: https://quarkus.io/guides/reactive-sql-clients
- Oracle: https://blogs.oracle.com/developers/configuring-the-oracle-jdbc-drivers-with-quarkus
RESTFul
- RESTEasy is an implementation of JAX-RS and it is used to implement RestFul-services.
- Microservices communicating either synchronously via REST or asynchronously using Kafka.
- https://quarkus.io/guides/rest-json
- https://quarkus.io/guides/rest-client
- https://quarkus.io/guides/resteasy-reactive
- https://lankydan.dev/building-a-rest-api-with-quarkus
- https://dzone.com/articles/building-a-rest-api-with-quarkus