How to send url to Intent in Android

This code will open the link in your Android browser. We suppose you have an Activity and you did the correct imports :

 

String url = "http://www.tutoref.com";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);

 

The necessary imports are:

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

 

PHP MySQL example

This example shows how to connect to a MySQL database and browse data using PHP:

<?php
$host= "localhost";
$username = "user";
$password = "pwd";
$dbname = "dbName";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT id, firstname, lastname FROM users";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

 

What is new in Java 8

Java 8 is a major release of the java programming language. It introduces new features and enhancements. The most significant ones are the following.

Lambda expressions

New Date and Time API

Method references

Default methods

Repeating annotations

Type annotations

Stream API

Optional

Narshon

new tools and utilities

HttpURLConnection example

HttpURLConnection allows to open an HTTP connection and get a response.

URL url = new URL("http://www.tutoref.com");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
int statusCode = http.getResponseCode();
// if statusCode == 200, it means it's ok.
// other ways, it's an error you can deal with it.

 

How to convert Date into LocalDateTime in Java 8

Date to LocalDateTime

Date date = new Date();
Instant instant = date.toInstant();
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

 

LocalDateTime to Date

LocalDateTime ldt = LocalDateTime.now();
ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault());
Date date = Date.from(zdt.toInstant());