Örnekler Defteri :)

Herkese Merhaba, Bugün uzun süredir yazı giremiyordum. Artık yaptığım, üzerinde çalıştığım örnekleri internet üzerine koymaya karar verdim. Hem iyi bir yedek olur, hemde siz de yararlanırsınız diye umuyorum 🙂

1-) HighCharts Örneği

2016-03-12_22h31_01

 

Kodları :

 

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Merhaba,İlk Ornek :) </title>
<script src="js/jquery-1.12.1.js"></script>
<script src="js/highcharts.js"></script>
  <script type="text/javascript">
  $(function(){
$('#container').highcharts({
chart:{type:'bar'},
title:{text:'Bilgisayar'},
xAxis:{categories:['Android','Html','Xml']},
yAxis:{title:{text:'Değerler'}},
series:[{
  name:'Umit',
  data:[25,6,4]
},{
name:'Umut',
data:[5,7,3]
  }],

});
    });
    </script>
</head>
<body>
<div id="container" style="width:100%;height:400px;margin 0 auto;"></div>

</body>
</html>

Kodlar’ı İndirmek için –> deneme1

2-) Java MYSQL bağlantısı

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dbConnection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 *
 * @author um
 */
public class MYSQLConnection {
     static Connection connection = null;
    static PreparedStatement preparedStmt = null;
    final static String DBdriver = "com.mysql.jdbc.Driver";
    final static String DBurl = "jdbc:mysql://localhost:3306/yardimlasmaplatformu";
    final static String DBuser = "root";
    final static String DBpassword = "";
    
        public static Connection connectToDB() {
        try {
            if (connection == null) {
                
                System.out.println("Bağlantı Tamam Baby :) ");
                Class.forName(DBdriver);
                return connection = DriverManager.getConnection(DBurl, DBuser, DBpassword);
            }
            return connection;
        } catch (Exception e) {
            return null;
        }
    }
}

DBurl,user ve password’u kendinize göre düzenlersiniz 🙂

3-) HighCharts grafik çizdirme

 

2016-03-17_21h04_28

 

Kodlar:

 

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Merhaba,İlk Ornek :) </title>
<script src="js/jquery-1.12.1.js"></script>
<script src="js/highcharts.js"></script>
<script type="text/javascript">
$(function(){
$('#container').highcharts({
title:{text:'data series style 1'},
xAxis:{categoris:['Jan','Feb','Mar','Apr','May']},
series:[{
data:[14,12,45,62,35]
}]
});
});
</script>
</head>
<body>
<div id="container" style="width:100%;height:400px;margin 0 auto;"></div>

</body>
</html>

4: Java’da Socket İşlemleri yaparak istemciden servera belirtilen bir dosyayı paylaşma uygulaması

İstemci-Client Kısmı :

import java.io.*;
import java.net.Socket;
import java.util.Arrays;
import java.lang.*;
import java.util.Scanner;
 
 
public class Client {
    public static void main(String[] args) throws Exception {
        String fileName = null;
        //Dosya yolu giricem -- Dosyaya dönüştürcem. bunu soket programlama da paylaşma ve yazma işlemleri ile uygulayacağım.
        
        
        
        System.out.println("Paylaşılacak olan dosya yolunu giriniz :");
        Scanner scanner = new Scanner(System.in);
        String file_name = scanner.nextLine();
          
        File file = new File(file_name);
        Socket socket = new Socket("192.168.1.6", 3332);
        ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
 
        oos.writeObject(file.getName());
 
        FileInputStream fis = new FileInputStream(file);
        byte [] buffer = new byte[Server.BUFFER_SIZE];
        Integer bytesRead = 0;
 
        while ((bytesRead = fis.read(buffer)) > 0) {
            oos.writeObject(bytesRead);
            oos.writeObject(Arrays.copyOf(buffer, buffer.length));
        }
 
        oos.close();
        ois.close();
        System.exit(0);    
}
 
}

Server Kısmı :

import java.io.*;
import java.net.*;
 
public class Server extends Thread {
    public static final int PORT = 3332;
    public static final int BUFFER_SIZE = 100;
 
    @Override
    public void run() {
        try {
            ServerSocket serverSocket = new ServerSocket(PORT);
 
            while (true) {
                Socket s = serverSocket.accept();
                saveFile(s);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private void saveFile(Socket socket) throws Exception {
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
        FileOutputStream fos = null;
        byte [] buffer = new byte[BUFFER_SIZE];
 
        // 1. Read file name.
        Object o = ois.readObject();
 
        if (o instanceof String) {
            fos = new FileOutputStream(o.toString());
        } else {
            throwException("Something is wrong");
        }
 
        // 2. Read file to the end.
        Integer bytesRead = 0;
 
        do {
            o = ois.readObject();
 
            if (!(o instanceof Integer)) {
                throwException("Something is wrong");
            }
 
            bytesRead = (Integer)o;
 
            o = ois.readObject();
 
            if (!(o instanceof byte[])) {
                throwException("Something is wrong");
            }
 
            buffer = (byte[])o;
 
            // 3. Write data to output file.
            fos.write(buffer, 0, bytesRead);
           
        } while (bytesRead == BUFFER_SIZE);
         
        System.out.println("File transfer success");
         
        fos.close();
 
        ois.close();
        oos.close();
    }
 
    public static void throwException(String message) throws Exception {
        throw new Exception(message);
    }
 
    public static void main(String[] args) {
        new Server().start();
    }
}

 

Yazar: umiitkose

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir