/*
* Main.java
*
* Created on 2006年11月11日, 下午12:30
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package javaapplication2;
/**
*
* @author Star
*/
import java.net.*;
import java.io.*;
public class HostLookup {
public static void main (String[] args) {
if (args.length > 0) { // use command line
for (int i = 0; i <>
System.out.println(lookup(args[i]));
}
}
else {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter names and IP addresses. Enter \"exit\" to quit.");
try {
while (true) {
String host = in.readLine();
if (host.equalsIgnoreCase("exit") || host.equalsIgnoreCase("quit")) {
break;
}
System.out.println(lookup(host));
}
}
catch (IOException ex) {
System.err.println(ex);
}
}
} /* end main */
private static String lookup(String host) {
InetAddress node;
// get the bytes of the IP address
try {
node = InetAddress.getByName(host);
}
catch (UnknownHostException ex) {
return "Cannot find host " + host;
}
if (isHostname(host)) {
return node.getHostAddress();
}
else { // this is an IP address
return node.getHostName();
}
} // end lookup
private static boolean isHostname(String host) {
// Is this an IPv6 address?
if (host.indexOf(':') != -1) return false;
char[] ca = host.toCharArray();
// if we see a character that is neither a digit nor a period
// then host is probably a hostname
for (int i = 0; i <>
if (!Character.isDigit(ca[i])) {
if (ca[i] != '.') return true;
}
}
// Everything was either a digit or a period
// so host looks like an IPv4 address in dotted quad format
return false;
} // end isHostName
} // end HostLookup
hostLookUp
Nov112006aSimleCalender
/*
* Main.java
*
* Created on 2006年11月4日, 下午1:27
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package javaapplication1;
/**
*
* @author Karpar
*/
import java.io.*;
public class PrintCalender {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
InputStreamReader stdin = new InputStreamReader(System.in);
BufferedReader console = new BufferedReader(stdin);
int year = 0,month = 0;
String s1,s2;
try
{ System.out.print ("Enter full year:");
s1 = console.readLine();
year = Integer.parseInt(s1);
System.out.print ("Enter month in number between 1 and 12:");
s2 = console.readLine();
month = Integer.parseInt(s2);
}
catch(IOException ioex)
{
System.out.println("Input error");
System.exit(1);
}
catch(NumberFormatException nfex)
{
System.out.println("\"" + nfex.getMessage() + "\" is not numeric");
System.exit(1);
}
//Print calender for the month of the year.
printMonth (year, month);
}
//Print the Calender for a month in a year
static void printMonth (int year, int month)
{
//Get start day of the week for the first date in the month
int startDay = getStartDay (year , month);
//Get number of days in the month
int numOfDaysInMonth = getNumOfDaysInMonth(year, month);
//print headings
printMonthTitle (year, month);
//Print body
printMonthBody (startDay ,numOfDaysInMonth);
}
//Get the start day of the first day in a month
static int getStartDay(int year , int month)
{
//Get total number of days since 1/1/1800
int startDay1800 = 3;
long totalNumOfDays = getTotalNumOfDays(year ,month);
//Return the start day
return (int)((totalNumOfDays + startDay1800) % 7);
}
//Get the total number of days since Jan 1,1800
static long getTotalNumOfDays(int year,int month)
{
long total = 0;
//Get the total days from 1800 to year -1;
for (int i = 1800 ;i <>
if(isLeapYear (i))
total = total + 366;
else
total = total + 365;
//Add day from Jan to The month prior to the calender
for (int i = 0; i <>
total = total + getNumOfDaysInMonth(year,i);
return total;
}
//Get the number of days in a month
static int getNumOfDaysInMonth(int year ,int month)
{
if (month == 1 || month == 3 || month == 5 || month == 7
|| month == 8 || month == 10 || month == 12)
return 31;
if (month == 4 || month == 6 || month == 9 || month ==11)
return 30;
if (month == 2)
if(isLeapYear(year))
return 29;
else
return 28;
return 0;
}
//Determine if it is a leap year
static boolean isLeapYear (int year)
{
if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
return true;
return false;
}
//Print month body
static void printMonthBody(int startDay,int numOfDaysInMonth)
{
//Pad space before the first day of the month
int i = 0;
for(i=0; i <>
System.out.print(" ");
for (i = 1 ;i <= numOfDaysInMonth ; i++){
if(i <>
System.out.print(" " + i);
else
System.out.print(" " + i);
if((i + startDay) % 7 == 0)
System.out.println();
}
System.out.println();
}
//Print the month title,i.e. May, 1999
static void printMonthTitle(int year,int month)
{
System.out.println(" " + getMonthName(month)
+ " , " + year);
System.out.println("-------------------------------------");
System.out.println(" Sun Mon Wed Thu Fri Sat");
}
//Get the entire name for the month
static String getMonthName(int month)
{
String monthName = null;
switch(month)
{
case 1: monthName = "January";break;
case 2: monthName = "February";break;
case 3: monthName = "March";break;
case 4: monthName = "April";break;
case 5: monthName = "May";break;
case 6: monthName = "June";break;
case 7: monthName = "July";break;
case 8: monthName = "August";break;
case 9: monthName = "September";break;
case 10:monthName = "October";break;
case 11:monthName = "November";break;
case 12:monthName = "December";break;
}
return monthName;
}
}
Visited to the James Gosling's blog
Nov092006wowow,i visited james' blog today,yes,the photo was from his blog!i was exited to see the masterpiece which, of cource,is JAVA Programming Languge.There are words taken from his blog:
I just installed Ubuntu 6.06 and it was the nicest out-of-the-box install experience I've ever had with Linux - real competition for the folks at Apple. Thanks for the lovely piece of work!
haham,he did use linux too.i also use that,i was finally able to find something similar with him,a figure in Computer.And the second may be the enthusiasm of Java.
YES!!!!Gentoo
After a day's hardwork,i eventually made a success in configuring a Gentoo Linux myself.Of course,i followed the Gentoo Linux X86 handbook step by step.And i was so happy about doing that,i am sure that i've made a great progress by configure a Linux myself.So i show lots of thanks to Gentoo Linux development team.However, i don't want to introduce anything about the detail steps that i did.Because the handbook produced by Gentoo team is the best guideline i could find.
Great honor:
Sven Vermeulen Author
Grant Goodyear Author
Roy Marples Author
Daniel Robbins Author
Chris Houser Author
Jerry Alexandratos Author
Seemant Kulleen Gentoo x86 Developer
Tavis Ormandy Gentoo Alpha Developer
Jason Huebel Gentoo AMD64 Developer
Guy Martin Gentoo HPPA developer
Pieter Van den Abeele Gentoo PPC developer
Joe Kallar Gentoo SPARC developer
John P. Davis Editor
Pierre-Henri Jondot Editor
Eric Stockbridge Editor
Rajiv Manglani Editor
Jungmin Seo Editor
Stoyan Zhekov Editor
Jared Hudson Editor
Colin Morey Editor
Jorge Paulo Editor
Carl Anderson Editor
Jon Portnoy Editor
Zack Gilburd Editor
Jack Morgan Editor
Benny Chuang Editor
Erwin Editor
Joshua Kinard Editor
Tobias Scherbaum Editor
Xavier Neys Editor
Joshua Saddler Editor
Gerald J. Normandin Jr. Reviewer
Donnie Berkholz Reviewer
Ken Nowack Reviewer
Lars Weiler Contributor
They all are figures!
Gentoo Linux x86 Handbook
a poem
Nov062006
And ar't return'd againe with all thy faults
Thou greate Commander of the all=go=naughts
And left the lle behinde thee?what's the matter
Did winter make thy Chapps to chatter,
Could not the Surging,and distempred Seas
thy queasy Stomacke(gorg'd)with sweete meats please
Or didst thou sodainly remooue thy Station
throughe Iealousy of Hollands supplantation
Or was't for want of wenches,or did'st feare
the king(thou absent)durst wrong'd Bristoll heare,
Or didst thou hasten headlong to prevent
A fruitlesse hope't for needfull Parlianment?
Allthese noe question with a restlesse motion
Vext thy bespotted soule,as that blacke potion
tortur'd the Noble Scott,whose Ghost can tell
thy swolne ambition made his carcase swell,
But their's a reason worse,then this,they say
the Frenchmen beate thee,and thou ran'st away
Can this bee true,could not thy glorious boast
before thy goeing:fright them from that Coast?
Could not thy tytles feare them, nor the Lambes
Protection, saueguard thee from these French Rambs
Could not thy Cambridge Pupills zealous prayers
compos'd of Brownish, and Arminian ayres
confound thy foes? or els did their distraction
Make in thy hopeles
Could not thy Parliament Majesticke Vowes
Prevayle t'impose the garland on thy browes
Could not thy Chaplaine Londons sacrifice
nor moue, nor suffocate the destin
that sends from paunches Altar more fumes forth
of Smoake, and vapour, then Landaphe is worth.
Could not thy mothers masses, nor her Crosses
Nor her sorceries, prevent these fatall losses
Nor Regall wishes, nor embraces neither,
Nor th'armies Vallour, nor all these togeather
Hence wee conclude, to these that will be Vitious
Pray will, pray, Heauen will not bee propitious
God's deafe to them, that will not heare the cryes
Of their Oppressed subiects injuries,
About Object.
Nov022006Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.
Take a minute right now to observe the real-world objects that are in your immediate area. For each object that you see, ask yourself two questions: "What possible states can this object be in?" and "What possible behavior can this object perform?". Make sure to write down your observations. As you do, you'll notice that real-world objects vary in complexity; your desktop lamp may have only two possible states (on and off) and two possible behaviors (turn on, turn off), but your desktop radio might have additional states (on, off, current volume, current station) and behavior (turn on, turn off, increase volume, decrease volume, seek, scan, and tune). You may also notice that some objects, in turn, will also contain other objects. These real-world observations all translate into the world of object-oriented programming.
Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages). Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication. Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation — a fundamental principle of object-oriented programming
By attributing state (current speed, current pedal cadence, and current gear) and providing methods for changing that state, the object remains in control of how the outside world is allowed to use it. For example, if the bicycle only has 6 gears, a method to change gears could reject any value that is less than 1 or greater than 6.
Bundling code into individual software objects provides a number of benefits, including:
- Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.
- Information-hiding: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.
- Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code.
- Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.