Tutorialspoint

Java Examples File Modification Time1

import java.net.URL;
import java.net.URLConnection;

public class Main {
   public static void main(String[] argv)throws Exception {
      URL u = new URL("http://127.0.0.1/java.bmp");
      URLConnection uc = u.openConnection();
      uc.setUseCaches(false);
      long timestamp = uc.getLastModified();
      System.out.println("The last modification time of java.bmp is :"+timestamp);
   }
}

F# If Elif Statement

let a : int32 = 100

(* check the boolean condition using if statement *)

if (a = 10) then
   printfn "Value of a is 10\n"
elif (a = 20) then
   printfn " Value of a is 20\n"
elif (a = 30) then
   printfn " Value of a is 30\n"
else
   printfn " None of the values are matching\n"
   printfn "Value of a is: %d" a

Java Examples Getting connected to Server

import java.net.InetAddress;
import java.net.Socket;

public class WebPing {
   public static void main(String[] args) {
      try {
         InetAddress addr;
         Socket sock = new Socket("www.javatutorial.com", 80);
         addr = sock.getInetAddress();
         System.out.println("Connected to " + addr);
         sock.close();
      } catch (java.io.IOException e) {
         System.out.println("Can't connect to " + args[0]);
         System.out.println(e);
      }
   }
}

F# For Loop Example2

let main() =
   for i = 20 downto 1 do
      printfn "i: %i" i
main()

Java Examples Host Specific IP Address2

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Demo {
   public static void main(String[] args) {
      InetAddress ipadd;
      String hostname;
      try {
         ipadd = InetAddress.getLocalHost();
         hostname = ipadd.getHostName();
         System.out.println("Your IP address : " + ipadd);
         System.out.println("Your Hostname : " + hostname);
      } catch (UnknownHostException e) {
      }
   }
}

F# For Loop Example

let main() =
   for i = 1 to 20 do
      printfn "i: %i" i
main()

Python Single Statement Suite

#!/usr/bin/python

var = 100
if ( var == 100 ) : print "Value of expression is 100"
print "Good bye!"

Java Examples Host Specific IP Address1

import java.net.InetAddress;
import java.net.UnknownHostException;

public class GetIP {
   public static void main(String[] args) {
      InetAddress address = null;
      try {
         address = InetAddress.getByName("www.javatutorial.com");
      } catch (UnknownHostException e) {
         System.exit(2);
      }
      System.out.println(address.getHostName() + "=" + address.getHostAddress());
      System.exit(0);
   }
}

F# For...In Loop

// Looping over a list.
let list1 = [ 10; 25; 34; 45; 78 ]
for i in list1 do
   printfn "%d" i

// Looping over a sequence.
let seq1 = seq { for i in 1 .. 10 -> (i, i*i) }
for (a, asqr) in seq1 do
   printfn "%d squared is %d" a asqr

Python Operator Precedence

#!/usr/bin/python

a = 20
b = 10
c = 15
d = 5
e = 0

e = (a + b) * c / d       #( 30 * 15 ) / 5
print "Value of (a + b) * c / d is ",  e

e = ((a + b) * c) / d     # (30 * 15 ) / 5
print "Value of ((a + b) * c) / d is ",  e

e = (a + b) * (c / d);    # (30) * (15/5)
print "Value of (a + b) * (c / d) is ",  e

e = a + (b * c) / d;      #  20 + (150/5)
print "Value of a + (b * c) / d is ",  e

Advertisements
Loading...