Eclipse and Java for Total Beginners

Mới lượm lặt được cái này Share cho anh em . Cực kỳ là bổ ích và đặc biệc cho những ai là Fan của Eclipse
Total_Beginner_Companion_Document
Part1 – Part2 – Part3 – Part4
Part5 – Part6 – Part7 – Part8
Part9 – Part10 – Part11 – Part12
Part13 -Part14 – Part15 – Part16
Cái này của 1 chú Hungarian [...]

Ping 1 Server…

import java.io.*;
import java.net.*;
class PingServer
{
public static void main(String args[])
{
try
{
Socket t = new Socket(args[0], 7);
DataInputStream dis = new DataInputStream(t.getInputStream());
PrintStream ps = new PrintStream(t.getOutputStream());
ps.println(“Hello”);
String str = is.readLine();
if (str.equals(“Hello”))
System.out.println(“Con Song!”) ;
else
System.out.println(“Chet roai`! Truy van bi tu choi”);
t.close();
}
catch (IOException e)
{
e.printStackTrace();}
}
}
}

Dự đoán đề thi java …Connect Data và Show Data

Question 1   Develop a Java application which allows user to browse the database for  STUDENT information.  Database specificationStudent is required to create the STUDENT database in SQL server, create 2  table
and insert data as in the following description:       
  Table : Class

Field Name
Data Type
Description

ClassID
Char (10) primary key
Class ID

ClassName
Char(20) not null
Name of class

Field Name
Data Type
DesCription

Sid
Char(10) primary key
Student ID

Sname
Char(20)
Student [...]

Lấy thông tin Host hiện hành…

import java.net.*;
public class CurrentHost
{
public static void main(String[] args) throws UnknownHostException
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(“This host’s name: ” + address.getHostName());
System.out.println(“This host’s fully qualified address: ” +
address.getCanonicalHostName());
System.out.println(“This host’s numerical address: ” + address.getHostAddress());
}
}

Ping 1 Server…

import java.io.*;
import java.net.*;
class PingServer
{
public static void main(String args[])
{
try
{
Socket t = new Socket(args[0], 7);
DataInputStream dis = new DataInputStream(t.getInputStream());
PrintStream ps = new PrintStream(t.getOutputStream());
ps.println(“Hello”);
String str = is.readLine();
if (str.equals(“Hello”))
System.out.println(“Con Song!”) ;
else
System.out.println(“Chet roai`! Truy van bi tu choi”);
t.close();
}
catch (IOException e)
{
e.printStackTrace();}
}
}
}

Kết nối CSDL thông qua ODBC-JDBC

import java.net.URL;
import java.sql.*;
class JDBC
{
static myConnection theConn;
public static void main (String args[])
{
theConn = new myConnection();
theConn.Connect2Db(“meopro”, “dba”, “sql”);//thường thì khi cài SQl ở nhà ai cúng để chế độ tự động đăng nhap = hệ thông nên cần tùy biến ở đây
}
}
class myConnection
{
Connection dbConn = null;
void Connect2Db(String db, String user, String passw)
{
try
{
Driver d = (Driver)Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”).newInstance();
// URL tương [...]