Java Clean Coding
Coding guidelines.
-
BAE-Java-standard . pdf – Download
-
Java_standards_V1.0 . pdf – Download
-
Java Coding Guidelines . pdf – Download
Project Management
Tools & Methodologies
Frontend Development for Web Pages
JSP (JavaServer Pages)
JSP enables you to write dynamic, data-driven pages for your Java web applications. JSP is a relatively simpler and older technology than JSF, which is the standard for Java web frameworks like Eclipse Mojarra, MyFaces, and PrimeFaces. While it is not uncommon to see JSP used as the frontend for older JSF applications, Facelets is the preferred view technology for modern JSF implementations.
- JSTL
- The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates the core functionality common to many JSP applications.
JSF (JavaServer Faces)
It is a server side component based user interface framework. It is used to develop web applications. It provides a well-defined programming model and consists of rich API and tag libraries. The latest version JSF 2 uses Facelets as its default templating system. It is written in Java.
- PrimeFaces
- RichFaces
- OmniFaces
Example Code:
1 2 3 4 5 6 |
<f:view> <h:form> <h:panelGrid columns="2"> <h:outputLabel value="Celsius"></h:outputLabel> <h:inputText value="#{temperatureConvertor.celsius}"></h:inputText> </h:panelGrid> |
Database driven sites
You can use libraries those are already written for JAVA to manage MYSQL and other databases. But you can also use native php functions to access database. You can search at “composer“.
Mysql
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Date; public class MySQLAccess { private Connection connect = null; private Statement statement = null; private PreparedStatement preparedStatement = null; private ResultSet resultSet = null; Class.forName("com.mysql.jdbc.Driver"); connect = DriverManager.getConnection("jdbc:mysql:/---"); // Statements allow to issue SQL queries to the database statement = connect.createStatement(); resultSet = statement.executeQuery("select * from feedback.comments"); writeResultSet(resultSet); preparedStatement = connect .prepareStatement("insert into feedback.comments values (default, ?..........)"); preparedStatement.setString(1, "Test"); preparedStatement.executeUpdate(); preparedStatement = connect.prepareStatement("SELECT myuser, webpage, datum, summary, COMMENTS from feedback.comments"); resultSet = preparedStatement.executeQuery(); writeResultSet(resultSet); preparedStatement = connect.prepareStatement("delete from feedback.comments where myuser= ? ; "); preparedStatement.setString(1, "Test"); preparedStatement.executeUpdate(); resultSet = statement.executeQuery("select * from feedback.comments"); writeMetaData(resultSet); } catch (Exception e) { throw e; } finally { close(); } |
MySQL is the most popular database system used with Java. Mysql is tunable easily by developers. Performance is well enough for simple JAVA and Backend Systems.
For the projects, you can easily get backup of the mysql with Java. It is very easy to get data from mysql.
Hibernate Mysql
1 2 3 4 5 6 7 |
Annotation Configuration Entity Classes Factory Creation Creation of the Sessions |
Lazy Load
1 2 |
//Following code loads only a single category from the database Category category = (Category)session.get(Category.class,new Integer(42)); |
Postgresql
Postgresql is an alternative to MYSQL, if you want more and more stability and some better advantages that you need and not available at MYSQL side.
1 |
Hibernate : |
Mysql is faster BUT Postgresql handles the Concurrency better, and heavy inserts more stable processed.
Cassandra
Cassandra is Nosql DATABASE. It is distributed and you can set the data replication factors and multi datacenter avalibilities.
You can download the drive here. DATASTAX
Service Based Java
Services are very important to create activities with 3rd parties. Your scripts can access the data from 3rd parties or can send data to them. For stability , realibility, and avalibility services are also used. You can create back-end servers to create services and your php front-end can access these servers to access data requests and responses. If you have billions of requests you can do load balancing.
OAUTH – and V2
Oauth very important to access user data from 3rd parties. Such as If a user trying to register a web page over FACEBOOK, OAUTH can transfer the user data to the web page that user trying to register. Tokens or other mechanism used for validation exchanges.
User Account generates a cryptographically signed token which it hands off to the application to authenticate the user.
Here are the some important methods of the OAUTH
1 2 3 |
// // |
As you see above, it is saying, Disable redirects or get Last response, Auth type, Request tokens. Imagine that; You have 100 users trying to do outh in the same time. A lot of time saving for clients!.
Spring Ampq
1 2 3 4 |
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost"); connectionFactory.setUsername("guest"); connectionFactory.setPassword("guest"); |
Spring Boot
ttt
Java CSV
Link -> https://kutayzorlu.com/software-development/java/java-csv-15446.html
Jetty
Jetty Eclipse
EJB
REST (REST or Representational State Transfer )
The objective is to build a RESTful web service in PHP to provide resource data based on the request with the network call by the external clients.
- Create request URI with patterns that follow REST principles.
- Make the RESTful service to be capable of responding to the requests in JSON, XML, HTML formats.
- Demonstrate the use of HTTP Status code based on different scenarios.
- Demonstrate the use of Request Headers.
- Test the RESTful web service using a REST client.
RESTful-Style | RPC-Style | |
---|---|---|
Request URI | The request URI will differ based on the resource. | Same URI for all resources. |
Request methods | The service request parameters can be sent via GET, PUT, POST request methods. | Supports only the POST method. |
Service methods or handlers | Same method for all resources. | Methods and params are posted on request. |
Target on | The service request using this style targets resources. | The target is methods. |
Response data transmission | Over HTTP | wrapped with the requested methods and params. |
Hashset vs Hastable (Comparison)
# | Hash Map | Hash Set |
---|---|---|
1. | No method is synchronized. | Every method is synchronized. |
2. | Multiple threads can operate simultaneously and hence hashmap’s object is not thread-safe. | At a time only one thread is allowed to operate the Hashtable’s object. Hence it is thread-safe. |
3. | Threads are not required to wait and hence relatively performance is high. | It increases the waiting time of the thread and hence performance is low. |
4. | Null is allowed for both key and value. | Null is not allowed for both key and value. Otherwise, we will get a null pointer exception. |
5. | It is introduced in the 1.2 version. | It is introduced in the 1.0 version. |
6. | It is non-legacy. | It is a legacy. |
1 2 |
Hashtable<Integer,String> ht=new Hashtable<Integer,String>(); HashMap<Integer,String> hm=new HashMap<Integer,String>(); |
An alternative to REST, FACEBOOKS graphQL.
RPC is mostly related with actions.
JWT Token
* You can store data at JWT, you can select encryption type.
1 |
Ref Picture : toptal.com |
Ref
SOAP
SOAP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for exchanging information among computers. SOAP is an application of the XML specification.
- SOAP is easy to handle for security. Security at Rest little bit complex if you would like to do it.
- SOAP using RPC(Remote Process Call) method. SOAP contains WS-* like security protocols, SOAP memorize the state information at requests and responses.
- REST can work with JSON, XML and TEXT, SOAP should use XML. REST is more usefull in this case.
- Data sizes are more smaller at REST, Traffic is lower, in this case REST is better.
- For the performance, you should choose the REST.
- REST using HTTP methods. GET,POST,PUT,DELETE etc.
- REST is more easy to integrate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
POST /PHP_Kutayzorlu_com HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 SOAPAction: "http://www.w3.org/2003/05/soap-envelope" <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://www.example.org"> <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice> <m:StockName>T</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope> |
Mock Libraries
Android App Development
- ADB Device Commands
- WebView / JS access
- WebView / Events – Downloads / Uploads / Camera
The Java Cryptography
Some of the libraries
- Bouncy Castle
- Bouncy Castle is a collection of APIs used in cryptography
The Java Keystore
A Java KeyStore (JKS) is a repository of security certificates – either authorization certificates or public key certificates – plus corresponding private keys, used for instance in TLS encryption.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
KeyStore keyStore = KeyStore.getInstance("JKS"); //loads the keystore from givin input stream, and the password to unclock jks keyStore.load(new FileInputStream("x509-ca.jks"), "password".toCharArray()); // Create key manager KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); keyManagerFactory.init(keyStore, "password".toCharArray()); KeyManager[] km = keyManagerFactory.getKeyManagers(); // Create trust manager TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); trustManagerFactory.init(keyStore); TrustManager[] tm = trustManagerFactory.getTrustManagers(); // opens a secure socket with definied protocol SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); sslContext.init(km, tm, null); |
Java Cryptography Extension (JCE)
The Java Cryptography Extension is an officially released Standard Extension to the Java Platform and part of Java Cryptography Architecture
PKI (Public key infrastructure)
A public key infrastructure (PKI) is a set of roles, policies, hardware, software and procedures needed to create, manage, distribute, use, store and revoke digital certificates and manage public-key encryption.
X509
In cryptography, X.509 is a standard defining the format of public key certificates.
Conccurency
Atomic Reference
1 2 3 4 5 6 |
AtomicReference<Object> cache = new AtomicReference<Object>(); Object cachedValue = new Object(); cache.set(cachedValue); Object cachedValueToUpdate = cache.get(); Object newValue = someFunctionOfOld(cachedValueToUpdate); boolean success = cache.compareAndSet(cachedValue,cachedValueToUpdate); |
1 2 3 4 5 6 7 8 9 |
public static AtomicReference<String> shared = new AtomicReference<>(); String init="Inital Value"; shared.set(init); boolean success=false; while(!success){ String prevValue=shared.get(); String newValue=shared.get()+"lets add something"; success=shared.compareAndSet(prevValue,newValue); } |
Server
- Wildfy
- Tomcat EE
- WebLogic
Scrum
composer Example loading php libraries. (require ‘vendor/autoload.php’;)
1 2 3 4 5 6 7 8 9 10 |
<?php require 'vendor/autoload.php'; use Dotenv\Dotenv; use Src\System\DatabaseConnector; $dotenv = new DotEnv(__DIR__); $dotenv->load(); $dbConnection = (new DatabaseConnector())->getConnection(); |
Java Gradle Installation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ mkdir /opt/gradle $ unzip -d /opt/gradle gradle-7.2-bin.zip $ ls /opt/gradle/gradle-7.2 LICENSE NOTICE bin getting-started.html init.d lib media $ export PATH=$PATH:/opt/gradle/gradle-7.2/bin Set the build paths export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export ANDROID_HOME="~/Android/Sdk" export ANDROID_SDK_ROOT="~/Android/Sdk" export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools export PATH=$PATH:$ANDROID_SDK_ROOT/emulator Reference Link : https://gradle.org/releases/ |
Java Reactive Programming
1 2 3 4 5 6 7 8 9 10 |
Maven project, pom.xml: <dependency> <groupId>io.reactivex</groupId> <artifactId>rxjava</artifactId> <version>${rx.java.version}</version> </dependency> for Gradle : compile 'io.reactivex.rxjava:rxjava:x.y.z' |
Reactive systems are
- Responsive – systems should respond in a timely manner
- Message Driven – systems should use async message-passing between components to ensure loose coupling
- Elastic – systems should stay responsive under high load
- Resilient – systems should stay responsive when some components fail
1 2 3 4 |
Observable<String> observable = Observable.just("Hello"); observable.subscribe(s -> result = s); assertTrue(result.equals("Hello")); |
Payments
Please Click for JAVA Implementation
DDL – Data Definition Language
You can generate DDL in a script for database objects to:
- Keep a snapshot of the database structure
- Set up a test system where the database acts like the production system but contains no data
- Produce templates for new objects that you can create based on existing ones. For example, generate the DDL for the Customer table, then edit the DDL to create the table Customer_New with the same schema.
When you generate DDL, you can use the DDL statements to recreate everything about a database except for its contents. You can generate the DDL to completely recreate the database, or choose to recreate only certain aspects of it, such as its current statistics. You can also limit the statements that are generated so that only a segment of the database is recreated, for example, the statistics for a subset of tables.
Apache Lucene
Document Management
For generation of the office documents and BI reports.
Itext PDF (Office documents / PDF / HTML to PDF)
XML – XSLT – XSD validations
For the some of the backend services you need to validate the XML.
1 2 |
public DOMDocument::schemaValidate ( string $filename [, int $flags = 0 ] ) : bool |
Frameworks
Every developer can write own Framework. I have my own framework for E-Commerce / Crm systems
kcrm
Kcrm is private framework developed by Kutay ZORLU to FAST build CRM front-end applications. Advantages
- Built in REST services for Customer DATA
- Automatic Back-End failure detection and finding next Backend for Transactions
- Streaming Libraries impletemented, Data download, Data Stream, Data Upload
- Perfect design for CRM / ERP System coding.
- Invocing API implemented
- Usufull with multiple Data resources
- You can use, Mysql, REdis, Postgresql, Cassandra, and REST in the same time !
- FAST. Not loading toooo many libraries. Its using only what it needs.
- Caching library implemented.
- …. more and more.
Smarty
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic. This implies that PHP code is application logic, and is separated from the presentation.
Here is the sample Description : https://www.smarty.net/sampleapp1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
PHP <?php $counter=0; ?> <?php foreach($foo as $bar): ?> <?php if(($counter+1) % 4 == 0): ?> </tr><tr> <?php endif; ?> <td><?php echo $bar; ?></td> <?php $counter++; ?> <?php endforeach; ?> Smarty {foreach $foo as $bar} {if $bar@iteration is div by 4} </tr><tr> {/if} <td>{$bar}</td> {/foreach} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
header.tpl <html> <head> <title>{$title|default:"no title"}</title> </head> <body> footer.tpl </body> </html> index.tpl {include file="header.tpl" title="Info"} User Information:<p> Name: {$name|capitalize}<br> Address: {$address|escape}<br> {include file="footer.tpl"} output <html> <head> <title>Info</title> </head> <body> User Information:<p> Name: George Smith<br> Address: 45th & Harris<br> </body> </html> |
E-Commerce Systems
- XT-Commerce
- JTL WAVI – Web Service Development + XT- Commerce
- WordPress
- Gambio Installation
- Magento
- Modified E-Commerce
- B2B-E-Commerce
Code Guide Lines (richtlinien)
Object Oriented PHP
OOP is very important if your project becomes bigger and more complex. Clean programming and management of the classes are becoming very hard to handle. Composer is one of the best helper for php developers.
Modal view controller
Most important think for Development. MVC in PHP
Development with Source Code Controlling
Ref: https://blog.burakkutbay.com/java-keystore-keytool-nedir-keytool-komutlari.html/
ALL RIGHTS RESERVED
KUTAY ZORLU