Author

Browsing

Spring is a lightweight framework for building Java applications. You can use Spring to build any application in Java (for example, stand-alone, web, or JEE applications), unlike many other frameworks (such as Apache Struts, which is limited to web applications).

Spring architecture

Overview of the Spring Framework

Spring Core: Bean container and supporting utilities. The Core component is the most important component of the Spring Framework. This component provides the Dependency Injection features. The BeanFactory provides a factory pattern that separates the dependencies like initialization, creation and access of the objects from your actual program logic.
Spring Context: ApplicationContext, UI, validation, JNDI, Enterprise JavaBeans (EJB), remoting, and mail support
Spring DAO: Transaction infrastructure, Java Database Connectivity (JDBC), and data access object (DAO) support
Spring ORM: Hibernate, iBATIS, and Java Data Objects (JDO) support
Spring AOP: An AOP Alliance compliant aspect-oriented programming (AOP) implementation. Spring AOP is used for providing declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management, which builds on Spring’s transaction abstraction. To allow users to implement custom aspects, complementing their use of OOP with AOP
Spring Web: Basic integration features such as multipart functionality, context initialization through servlet listeners, and a web-oriented application context
Spring Web MVC: Web-based Model-View-Controller (MVC) framework

Arrays are a way to store a list of items. Each element of the array holds an individual item, and you can place items into and remove items from those slots as you need to

Declaring Array Variables

The first step to creating an array is creating a variable that will hold the array, just as you would any other variable. Array variables indicate the type of object the array will hold (just as they do for any variable) and the name of the array, followed by empty brackets ([]). The following are all typical array variable declarations:
String difficultWords[];
Point hits[];
int temps[];

An alternate method of defining an array variable is to put the brackets after the type instead of after the variable
String[] difficultWords;
Point[] hits;
int[] temps;

Creating Array Objects

The first way is to use the new operator to create a new instance of an array

String[] names = new String[10]; //create String array with 10 elements

When you create an array object using new, all its elements are initialized for you (0 for numeric arrays, false for boolean, empty string for character arrays, and null for everything else). You can also create and initialize an array at the same time. Instead of using new to create the new array object, enclose the elements of the array inside braces, separated by commas:

String[] vehicle = { "suzuki", "yamaha”, "honda", "toyota"};

Accessing Array Elements

To get at a value stored within an array, use the array with index expression (index start from 0)

array[index]

String animals[] = new String[10];
animals[10] = "tiger"; //set elements at position 11 with value "tiger"
System.out.println(animals[10]);//print element at position 11

Multidimensional Arrays

you can also declare and create an array of arrays (and those arrays can contain arrays, and so on, for however many dimensions you need), and access them as you would C-style multidimensional arrays:

int coords[][] = new int[12][12];
coords[0][0] = 1;
coords[0][1] = 2;

Fetch All Elements Of Array

int[] arr = {1, 2, 3, 4, 5};
for (int i=0; i < arr.length; i++) {
    System.out.println(arr[i]);
}

In cPanel you can swith to anther PHP version easily but in Sentora or any free panel web management, they doesn’t support this feature. You’ll must install every PHP version by your demand and config them manually . In this tutorial I will instruct you how to run a website with a specific PHP version beside default PHP version.

You can use this tutorial with LAMP (Linux Apache MySQL PHP) or use with Sentora panel on Centos, RedHat Enterprise Linux.

1. Install Sentora. Default PHP versiokn on Sentora is 5.4

# bash <(curl -L -Ss http://sentora.org/install)

2. Install php-fpm

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# yum install php56-php-fpm
# yum install php72-php-fpm

To run another PHP version you need install PHP FPM for that version.  Apache httpd to delegate PHP scripts execution to a backend using the FastCGI protocol. php-fpm package is available in the optional channel, to launch PHP FPM when reboot, you’ll need enable service PHP FPM

# systemctl enable php56-php-fpm
# systemctl enable php72-php-fpm

then make sure both versions are stopped:

# systemctl stop php56-php-fpm
# systemctl stop php72-php-fpm

3 . Configure for PHP FPM run on different port

By default, each php-fpm version is listening on port 9000. Because we want to run multiple php versions, we need to change default port. We will run 5.6 version on port 9056 and 7.2 version on 9072

# semanage port -a -t http_port_t -p tcp 9072
# semanage port -a -t http_port_t -p tcp 9056
# sed -i 's/:9000/:9056/' /etc/opt/remi/php56/php-fpm.d/www.conf
# sed -i 's/:9000/:9072/' /etc/opt/remi/php72/php-fpm.d/www.conf

4. Config php multiple version by web folder

# nano /etc/httpd/conf.d/php.conf

In php.conf we modify it as follows:

<Files ".user.ini">
    Require all denied
  </Files>


<FilesMatch \.php$>
    #SetHandler application/x-httpd-php
    SetHandler "proxy:fcgi://127.0.0.1:9056"
</FilesMatch>


<Directory /var/sentora/hostdata/zadmin/public_html/your_website_folder>
    <FilesMatch \.php$>
      SetHandler "proxy:fcgi://127.0.0.1:9072"
    </FilesMatch>
</Directory>

We use 5.6 version for all websites (default is 5.4) and all PHP scripts in folder your_website_folder will run with 7.2 version.

5. Start PHP FPM

# systemctl start php72-php-fpm
# systemctl start php56-php-fpm

# service httpd restart

For testing PHP version you can put a file with content like this in your website folder:

<?php phpinfo();?>

Tips: On PHP 7.2 you’ll need install PHP MySQLlnd for using MySQL

# yum install php72-php-mysqlnd

Loops in Java are designed to perform a specific task repeatedly. . In Java we have three types of basic loops: for, while and do-while.

The for and while statements perform the repetition declared in their body zero or more times until loop condition isn’t match (return false), then it will break from loop.  
The do…while loop: it executes the statements within its body first then compare condition in while and repeatedly zero or more times until condition in while return false.

While Loops

The while loop is used to repeat a statement or block of statements as long as a particular condition is true. while loops look like this:

while (condition) {
bodyOfLoop;
}

The condition is a boolean expression. If it returns true, the while loop executes the statements in bodyOfLoop and then tests the condition again, repeating until the condition is false.

while ((ch != "\\") &&   (ch != "\t") && (ch != "\n") && (ch != "\r")) {
addChar(ch, theName);
ch = instream.read();
}

do…while Loops

The do loop is just like a while loop, except that do executes a given statement or block until a
condition is false. The main difference is that while loops test the condition before looping,
making it possible that the body of the loop will never execute if the condition is false the first
time it is tested.

do {
bodyOfLoop;
} while (condition);

For example:

int x = 1;
do {
System.out.println("Looping, round" + x);
x++;
} while (x <= 10);

Output:
Looping, round 1
Looping, round 2
Looping, round 3
Looping, round 4
Looping, round 5
Looping, round 6
Looping, round 7
Looping, round 8
Looping, round 9
Looping, round 10

For loop

for (initialization; test; increment) {
   statements;
}

The start of the for loop has three parts:
–  initialization is an expression that initializes the start of the loop. If you have a loop
index, this expression might declare and initialize it, for example, int i = 0. Variables
that you declare in this part of the for loop are local to the loop itself; they cease
existing after the loop is finished executing. (This is different from C or C++.)
–  test is the test that occurs after each pass of the loop. The test must be a boolean
expression or function that returns a boolean value, for example, i < 10. If the test is
true, the loop executes. Once the test is false, the loop stops executing.
–  increment is any expression or function call. Commonly, the increment is used to
change the value of the loop index to bring the state of the loop closer to returning
false and completing.

For example:

 for (int i = 1; i <= 10; ++i) {
    System.out.println("Line " + i);
 }

Output:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

Breaking out of loop

In all the loops (for, while, and do), the loop ends when the condition you are testing for is met.
What happens if something odd occurs within the body of the loop and you want to exit the loop
early? For that, you can use the break and continue keywords.

break: it immediately halts execution of the current loop

 for(int i=1;i<=10;i++){  
        if(i==5){  
            //breaking the loop  
            break;  
        }  
        System.out.println(i);  
}  

Output:

1
2
3
4

continue: is used to continue the loop. It continues the current flow of the program and skips the remaining code at the specified condition. In case of an inner loop, it continues the inner loop only.

  for(int i=1;i<=10;i++){  
        if(i==5){  
            //using continue statement  
            continue;//it will skip the rest statement  
        }  
        System.out.println(i);  
  }  

Output:

1
2
3
4
6
7
8
9
10

Enhanced FOR Loop

for(type VARIABLE: COLLECTION)
{
    //Statements with VARIABLE
}

We must declare a VARIABLE of the same data type as the type of elements of the COLLECTION. Data type can Primitive like int, char, byte… or a Object type. There is NO CONDITION part in this enhanced for loop or for-each loop. By default, it works from the first element to the last element (fetch all elemtents from start to the end).

MySQL and MariaDB are popular choices for free database management systems. Both use the SQL querying language to manipulate and query data. If your application or website have a lot of data and you still use default configuration of MySQL/MariaDB, it will decrease performance and efficiency on your system. Below is some tips you can apply in your MySQL/MariaDB config to increase MySQL/MariaDB performance.

When reduced to their most basic form, all computer decisions are yes-or-no decisions. That is, the answer to every computer question is yes or no (or true or false, or on or off). This is because computer circuitry consists of millions of tiny switches that are either on or off, and the result of every decision sets one of these switches in memory.

What Is PHP? And Why I should learn PHP for developing a website?

PHP stands for PHP: Hypertext Preprocessor.  Generally speaking, PHP is used to add a functionality to websites that HTML alone can’t achieve. Â PHP is a scripting language is used for creating websites in the following ways: perform calculation, collect user information (such as submit form, comment…), interact with database (MySQL, Postgress and so on…), create graphics, work with cookies….

Java is an object-oriented language, which means that it has constructs to represent objects from the real world. Each Java program has at least one class that knows how to do certain things or how to represent some type of object.

Eclipse IDE is an open-source product that was originally created with a substantial code donation by IBM to the Java community, and from that moment Eclipse was a community-driven product. It started as an IDE for developing Java programs, but today it is a development platform used for building thousands of tools and plugins.