rewars 1.com

Sunday, December 14, 2008

23 suspected pirates captured, Indian navy says

The Indian navy captured 23 piracy suspects who tried to take over a merchant vessel in the Gulf of Aden, between the Horn of Africa and the Arabian Peninsula, Indian officials said.
Piracy suspects raise their hands in surrender as an Indian navy boat approaches.

Piracy suspects raise their hands in surrender as an Indian navy boat approaches.

Click to view previous image
1 of 2
Click to view next image

In addition to the 12 Somali and 11 Yemeni suspects, the Indian navy seized two small boats and "a substantial cache of arms and equipment," the military said in a statement.

Among the seized items were seven AK-47 automatic rifles, three other automatic weapons and 13 loaded magazines; a rocket-propelled grenade launcher along with rockets, cartridges and grenades; up to three outboard motors and a global positioning system receiver.

Pirate attacks in the waters off Somalia have increased this year, with armed men staging increasingly bold attacks on ever-larger targets. This year, pirates have attacked nearly 100 vessels off Somalia's coast and hijacked nearly 40, the International Maritime Bureau said. Map: See where incidents have been reported »

The Indian warship Mysore, which carried out Saturday's operation, is on anti-piracy patrol in the Gulf of Aden, the release said. The Mysore received a distress call Saturday morning from the MV Gibe, a merchant vessel sailing under an Ethiopian flag.

The Gibe reported that two boats were firing small arms at it. The merchant ship, which was 13 nautical miles from the Mysore, fired back with small arms onboard the vessel.

The Mysore changed course toward the Gibe and launched an armed helicopter, the Indian military said.

Upon seeing the helicopter and the Mysore closing in, the attackers broke off and tried to flee, the release said. The warship caught up to the boats, the larger of which was described as a 24- to 30-foot dhow, a traditional Arab sailboat. The dhow, identified as bearing the name Salahaddin, was towing a smaller skiff.

Indian sailors boarded the Salahaddin, the military said, and the 23 suspects surrendered peacefully.

The suspects, weapons, ammunition and equipment will be handed over to authorities, and the Mysore will return to patrol duties, India said.

Last month, the Indian navy said it had sunk a pirate "mother vessel" in the Gulf of Aden.

The ship's owner said the sunken vessel was a Thai trawler that was being seized by pirates when an Indian warship fired on it.

Sixteen crew members were aboard the ship, said Wicharn Sirichaiekawat, owner of the Ekawat Nava 5. Two have been accounted for. One crewman was found alive after six days adrift in the Gulf of Aden, and one is confirmed dead, the ship's owner said.

Indian authorities insisted that their ship, the frigate INS Tabar, had acted against a pirate vessel that had threatened to attack it.

"We fired in self-defense and in response to firing upon our vessel," Commodore Nirad Sinha, a navy spokesman, told CNN. "It was a pirate vessel in the international waters, and its stance was aggressive."

He said the ship the Tabar fired on was laden with ammunition.

All sorts of vessels -- freight and cargo ships, cruise liners and private yachts -- have been attacked in the waters off Somalia. In many hijackings, pirates take the crew and passengers hostage and demand a ransom.

Just this month, Somali pirates captured two Yemeni fishing boats and 22 Yemeni fishermen in the Gulf of Aden, Yemen's official news agency SABA reported. A day earlier, the German cruise liner MS Columbus said it would fly its 246 passengers and most of its crew over the Gulf of Aden instead of through it to avoid any pirate attack.

advertisement

The United States is reportedly circulating a proposal in the U.N. Security Council that would allow military forces to enter Somali territory in "hot pursuit" of pirates.

The Pentagon said Friday, however, that there are no plans for U.S. forces to go ashore in pursuit of pirates in Somalia.

British PM in Pakistan, India for talks after attacks

British Prime Minister Gordon Brown arrived in Pakistan on Sunday for a lunch meeting with Pakistan President Asif Ali Zardari, just hours after holding talks in New Delhi with Indian Prime Minister Manmohan Singh.
Flames and smoke gush from the Taj Mahal hotel in Mumbai, India, on November 27.

Flames and smoke gush from the Taj Mahal hotel in Mumbai, India, on November 27.

Click to view previous image
1 of 3
Click to view next image

Brown's shuttle diplomacy -- aimed at easing tensions between India and Pakistan in the wake of last month's Mumbai terror attacks -- comes as Pakistan's military said Indian fighter jets encroached on its airspace.

Before leaving India, Brown told reporters he had no doubts there was a connection between the Mumbai attacks and Lashkar-e-Tayyiba (LeT), a Pakistani-based terror group.

"We also know there have been arrests in Pakistan," Brown said. "We also know that the group responsible is LeT."

Relations between India and Pakistan -- both neighbors with nuclear arms -- deteriorated amid evidence that the militants who targeted 10 sites in Mumbai last month were trained in Pakistan.

More than 160 people were killed in the three-day siege that began November 26 and targeted two luxury hotels, a popular train station and other landmarks. Of the 10 suspects in the attacks, only 21-year-old Mohammad Ajmal Kasab survived, according to police.

Reports have emerged that Mohammad Ajmal Kasab has confessed to his role in the assault on the city.

Meanwhile, despite the reported violation of Pakistani airspace by Indian jets, Pakistani Prime Minister Syed Yousuf Raza Gilani said his government was not concerned that India's Air Force might attack suspected terror camp sites in Pakistan.

Pakistan Information Ministry spokeswoman Sherry Rehman said the Indian government "explained to us that these violations were inadvertent."

Indian Air Force spokesman, Wing Commander Mahesh Upasani, denied there was an airspace violation in an interview with CNN sister network, CNN-IBN. He said the report was part of a campaign designed to divert attention from the main issues.

"These allegations are utterly untrue and I would call them rather preposterous," Upasani said.

Rakesh Maria, Mumbai's joint police commissioner of crime, told a news conference on Saturday that the surviving attacker, Mohammad Ajmal Kasab, has confessed to his part in the attacks, according to CNN-IBN.

The confession was made in a three-page letter written in Urdu, which will be delivered to the Pakistan High Commission, or embassy, in New Delhi, India, possibly on Monday, the network reported.

He has asked for legal aid in the letter, a Mumbai police official said.

Maria paraphrased parts of the letter at a news conference but did not release a copy to the media, CNN-IBN said.

Investigators said Kasab is from Faridkot village in the Okara district of Pakistan's Punjab province and that the other nine alleged attackers also were from Pakistan.

Pakistani officials have denied that assertion, instead blaming "stateless actors."

Last week, Pakistani authorities banned a charity linked to the attacks and placed its leader under house arrest, Pakistan's information minister told CNN. The move came after the U.N. Security Council designated the charity, Jamaat-ud-Dawa (JuD), a terror organization because of its links to Lashkar-e-Tayyiba (LeT) and placed sanctions on the group.

advertisement

India has blamed LeT for training the attackers who carried out the Mumbai attacks.

Pakistani officials have said they are cooperating with the Mumbai investigation and are committed to fighting terrorism.

Friday, December 12, 2008

worls stocks slip on auto bailout failure

World markets endured another punishing session Friday as U.S. lawmakers' rejection of a $14 billion bailout for the ailing Detroit auto industry, weakening currencies in the U.S. and the UK and the bleak economic outlook weighed on investors' minds.
Wall Street traders watch the boards as the markets open Friday.

Wall Street traders watch the boards as the markets open Friday.

Click to view previous image
1 of 2
Click to view next image

In New York, the Dow Jones pared early losses of 150 points before slipping back again. By early afternoon trading in the benchmark index had lost 0.58 percent of its value, falling to 8,515.

Meanwhile the dollar continued to fall, hitting a 13-year low of 88.16 yen against the Japanese yen.

In the UK, the pound slipped further against the euro, hitting an all-time low of €1.118 as analysts predicted the currencies could be heading for parity. The pound has shed about 20 percent of its value against the euro in the past year. Video Watch report on possible pound-euro parity »

In Brussels, European Union leaders approved a €200 billion ($267 billion) stimulus plan to help the bloc's battered economy by providing support for vulnerable sectors such as construction and motors.

European stocks in France and Germany rallied a little after dipping more than 4 percent in morning trading. Paris' CAC closed down 2.5 percent and Frankfurt's DAX was down 1.8 percent.

In London, the FTSE 100 was down almost 100 points, or 2.2 percent. Banking stocks were hit hard as shareholders at HBOS voted in favor of a proposed takeover by Lloyds TSB -- a merger that will create a retail bank accounting for a quarter of British mortgages and half of savings.

Earlier, Japan's Nikkei 225 finished the day down 5.6 percent at 8,236, and Hong Kong's Hang Seng index slid 5.5 percent to 14,758. South Korea's Seoul Composite lost nearly 4.4 percent. Indexes in Sydney, Shanghai, Jakarta, and and Singapore all closed the day sharply lower.

Experts fear the failure of the U.S. automaker bailout plan and the possible collapse of any of the "Big Three" -- General Motors, Ford and Chrysler -- could have devastating consequences for the economy far beyond the boardrooms and production lines of Detroit. Video Watch how the bailout failure will play out with investors »

The collapse of negotiations could possibly doom General Motors to bankruptcy and closure in the coming weeks, with Chrysler potentially following close behind.

While Ford Motor has more cash on hand to avoid an immediate crisis, its production could be disrupted by problems in the supplier base, as could the production of overseas automakers with U.S. plants such as Toyota and Honda.

Hopes for congressional approval of a bailout fell apart on Thursday night as Democrats and Republicans were unable to reach a deal.

The rescue plan would have provided $14 billion in federal loans as a stopgap measure until the new Congress and the incoming administration of President-Elect Barack Obama could reach a longer-term solution.

On Friday U.S. President George W. Bush's press secretary said it would be "irresponsible" to allow the U.S. auto industry to collapse and said the White House was seeking alternative ways of using bailout money to help automakers.

"Given the current weakened state of the U.S. economy, we will consider other options if necessary... to prevent a collapse of troubled automakers," Dana Perino said in a statement.

"A precipitous collapse of this industry would have a severe impact on our economy, and it would be irresponsible to further weaken and destabilize our economy at this time."

Stocks are also struggling after surging in a short period of time. Between November 20, when stocks hit the current bear market low and Monday, the S&P 500 surged 21 percent. Since then, the stock market has been seesawing.

advertisement

"We had a large rally in a pretty short period of time and so the market is taking a breather here," said Christopher Colarik, portfolio manager at Glenmede. "We're in a bottoming process, but its still going to take a while."

In the week ended December 10, investors pulled roughly $2.8 billion out of equity mutual funds, after pulling $12.1 billion out of funds in the previous week. Investors have cashed out of equity mutual funds in 17 of the last 19 weeks.

Zimbabwe introduces $500 million note

Zimbabwe's central bank is introducing a $500 million note -- the highest current denomination -- as the once-prosperous southern African nation battles against spiraling hyperinflation.
Zimbabwe's new $500 million note

Zimbabwe's new $500 million note

Finance Minister Samuel Mumbengegwi made the announcement about the new note in a government gazette set for release Friday. On the back, the purple cotton bill will feature pictures of dairy cows being milked mechanically and a miner drilling underground, he said.

The Reserve Bank of Zimbabwe (RBZ) last week introduced a new set of denominations, including a $100 million note, but that has not helped to clear long lines for cash at banks. Some people sleep outside banks after failing to get cash.

The RBZ said a $200 million note would be in circulation Friday, together with the $500 million note.

The $500 million note is worth about 8 U.S. dollars and enough to buy just eight loaves of bread. Thursday, the greenback was trading around ZW$60 million and is expected to shoot up in light of the new note's introduction.

Prices change on an almost daily basis as businesses now peg their prices against the U.S. dollar.

Zimbabwe has had higher denominations than the $500 million note in the past. But over the past two years, the country has slashed zeros from the amount of its worthless currency -- the latest being 10 zeros in August.

Once one of Africa's most promising economies, Zimbabwe is reeling under its worst humanitarian and economic crisis. A cholera outbreak has killed nearly 800 Zimbabweans, forcing hundreds to cross the border into South Africa and Botswana to seek treatment.

The situation has been exacerbated by the closure of government hospitals for more than a month as health personnel demand the government review their salaries and equip the hospitals with medicines and modern machinery.

In addition, 5 million people are in need of food aid, the United Nations says, in a nation that once exported food to its neighbors.

advertisement

There has been a spate of protests -- including two by soldiers -- over the past four weeks as people voice their displeasure over President Robert Mugabe's policies.

Shortages of most essentials such as electricity, fuel, medical drugs and food have become a common feature in Zimbabwe. That has forced many people to flee the country.

son disappears:" I'm in somalia"

Last month, 17-year-old Burhan Hassan told his family he was catching a ride to school with a friend. He then vanished.
Islamic fighters drill in Somalia last month. The FBI says men are traveling from the U.S., potentially to fight.

Islamic fighters drill in Somalia last month. The FBI says men are traveling from the U.S., potentially to fight.

Click to view previous image
1 of 2
Click to view next image

His mother spoke to her son just a few days ago over the phone. To her shock, she says, he told her he was no longer in the United States.

"Mom, I'm in Somalia! Don't worry about me; I'm OK," the mother quoted her son as saying.

Details of how he got there and what has transpired in his life since his November disappearance are sketchy. His mother, who agreed to be identified only as Amina, says her son has clearly changed.

"He was different," she said of his attitude on the phone. Video Watch a report on missing Somalis »

Hassan is one of more than a dozen young men of Somali descent -- many U.S. citizens -- to have disappeared from Minneapolis over the past six months, according to federal law enforcement authorities. Authorities say young men have also disappeared in Boston, Massachusetts; Portland, Maine; and Columbus, Ohio.

"A number of young Somali men have traveled from throughout the United States to include Minneapolis to Somalia, potentially to fight," said FBI Special Agent E.K. Wilson.

Amina speaks about her son in the past tense, almost as if he were dead. She worries about him night and day.

"Now that he's gone, I can't sleep," she said. Video Watch Amina talk about her son »

The fear among the Somali community in Minneapolis is that their young men are being preyed upon and recruited to fight jihad, or holy war, in Somalia. Some have even called to tell their parents not to look for them.

"Those I talked to were completely shocked and dismayed as to what happened. They were completely in disbelief," said Omar Jamal of the Somali Justice Advocacy Center, based in St. Paul, Minnesota.

The shock is magnified by what happened to one of them: Authorities say a 27-year-old named Shirwa Ahmed blew himself up in an apparent suicide bombing in northern Somalia in October.

Amina doesn't like to think about that and refuses to believe that her son could be learning similar tactics.

She and her son lived in an apartment along the Mississippi River in a thriving Somali neighborhood in Minneapolis. Hassan's father died years ago, and she raised him as a single parent. Hassan's other siblings have all moved out.

"I'm feeling empty tonight, like I have [nothing]," she said.

Amina says she now forgets to cook. It's gotten so bad that when she's out shopping, she'll often feel that her son is back home again. She'll quickly return, only to remember he's still away.

She struggles when she recalls how smart he is and how he was studying to become a doctor. Holding up a copy of his high school class schedule, which includes Advanced Placement courses in mathematics, chemistry and biology, she says Hassan was to graduate in May.

He wanted to attend college in Arizona, and he wanted her to move there with him.

"He was planning to be a physician assistant. He told me to move ... to Arizona because he said in Arizona, we can get [those jobs] as soon as possible after graduating," she said. "His expectations were high."

She added, "He doesn't like to fight. Sometimes, he was a comedian. He likes to laugh or to say things that make you laugh. He was a very kind person."

Amina says her son has called a few times, most recently Saturday. She says that each time, it feels as if her son is being watched or listened to by at least one or two other men, because she can hear other voices in the background.

"It's like a kidnapped person. And he has no freedom, because if he said, 'Mom, I have to leave here; I have no life,' then they would kill him."

The question that plagues Amina and just about everyone in Minneapolis' Somali community is: How could these young men who were well-educated and who stayed out of trouble in the United States wind up in war-torn Somalia, possibly as fighters?

In Hassan's case, his mother fled the nation when she was pregnant with him, and they eventually came to the United States to escape the country's violence. She says her son's demeanor changed a couple months before he disappeared. He became more withdrawn, and she doesn't know why.

Other local Somalis have voiced concern that, because a large number of the men missing attended the same Islamic center after school, it could have played a role.

Amina does not believe the center itself played a role but thinks there are certain people associated with it who may be involved.

On Monday, representatives of the mosque, Abubakar As-Saddique Islamic Center, held a news conference to address the issue. The mosque's attorney, Mahir Sherif, strongly denied any allegations that it is connected to the men's disappearance, saying the center "has not and will not recruit for any political cause."

"I haven't talked to any of them [since the stories came out]. I haven't seen any of them fighting," Sherif said. "I mean, I would be speculating. I'm hearing what everybody else hears."

advertisement

Amina keeps hoping her son will return and that somebody in the community will come forward with more information.

"I'm asking for those who took my son or know anything about it to come forward. I'm asking you kindly to help and facilitate how to make possible to return [him]. Most sincerely."

'1000' things you need know about

Several years ago, in honor of the new millennium, Playboy magazine asked musicians for lists of their top 10 songs of the previous 1,000 years.
The Beatles placed six albums in Tom Moon's "1,000 Recordings to Hear Before You Die."

The Beatles placed six albums in Tom Moon's "1,000 Recordings to Hear Before You Die."

Click to view previous image
1 of 2
Click to view next image

Most of them stuck to the era of recorded sound, but guitarist Richard Thompson cheekily took Playboy's request seriously and submitted a list that included such songs as "Sumer Is Icumen In," a hit from the 13th century, and "Blackleg Miner," a folk ballad of the 1800s.

Playboy was not amused, and did not print Thompson's list.

Such is the fate that awaits many people who compile expansive lists of the greatest or most influential songs, movies, TV shows, romantic getaways or baseball players shorter than 5 feet 9. Everybody's a critic. At best, your list will inspire furious discussion; at worst, it will be ignored by your prospective debaters and sink as forlornly as a pebble in the Atlantic Ocean.

Which hasn't stopped a slew of new entries in the list-making business -- and not just simple top 10s, either. A handful of authors and publications have released, or are planning to release, works with up to 1,001 suggestions you should know about right now.

Tom Moon, author of "1,000 Recordings to Hear Before You Die" (Workman), knew what a daunting task he had been assigned.

"Could one person be counted on to do all kinds of music?" says Moon, the former music critic for The Philadelphia Inquirer and a regular contributor to NPR, describing himself as apprehensive about the project.

But he found himself warming to the idea. As a music journalist, he prides himself on being a generalist, though he admits he's mostly stayed close to the pop realms. A book such as "1,000 Recordings," he says, can help people see past their particular favorite artists or genres and tap into the whole world of recorded music.

"It's like having a tour guide with a flashlight shining into unknown places," he says in a recent interview at CNN Center. "It's someone saying, 'This is cool. Check this out.' " Video Watch Moon defend the inclusion of Britney Spears' "Toxic" »

Moon isn't the only one marking time by making lists this season. Movie critic David Thomson put out " 'Have You Seen ...?': A Personal Introduction to 1,000 Films" (Knopf) in October. The January issue of Blender magazine blares "1,001 Greatest Songs to Download Right Now" on its cover. The minds behind the music Web site Pitchfork have "The Pitchfork 500: Our Guide to the Greatest Songs from Punk to the Present" (Simon and Schuster).

And then there are the other big lists, past and future, including Dave Marsh's 1989 singles compendium "The Heart of Rock and Soul" (Marsh chose 1,001 influential singles) and Robert Hofler's forthcoming "Variety's 'The Movie That Changed My Life' " (120 notables pick their favorites).

So where does one start?

Thomson and Moon wanted references that included well-known titles and obscurities, often cheek by jowl.

"I wanted a 'bumper' book for your laps," writes Thomson in his introduction. "I wanted old favorites to be neighbors with films you've never heard of. I wanted you to entertain the unlikely possibility that 'everything' is here. Of course, it is not -- everything remains out in our scattered 'there.' "

So "Have You Seen ...?", which is organized in alphabetical order by title, includes some interesting juxtapositions. The laconic Humphrey Bogart film "The Big Sleep," directed by the no-nonsense Howard Hawks, precedes Alfred Hitchcock's "The Birds." The Frank Capra-directed "Mr. Smith Goes to Washington," starring an earnest James Stewart, resides next to David Lynch's loopily creepy "Mulholland Dr." Thomson picks some films for their artistry, others because ... well, because he wanted to, and it's his book.

Moon says he set some ground rules. He wanted to stick with albums, not singles or specific cuts. He knew he'd have to include certain essential recordings, but wanted room to roam.

"There's no way to be definitive about music," he says. "My thought was, let me find some of the best of the best ... then find stuff as thrilling, but perhaps not as accessible."

So "1,000 Recordings" includes the Jimi Hendrix Experience's "Are You Experienced" and Glenn Gould's two albums of Bach's Goldberg Variations, but also Guided By Voices' "Bee Thousand" and Toumani Diabate and Ballake Sissoko's "New Ancient Strings." "Born to Run" makes the list; so does Henry Mancini's score for "Breakfast at Tiffany's."

But like Thomson's film book, it has some idiosyncracies. The Beatles get six selections; the Rolling Stones get two, and one is a singles collection. There's a Beau Brummels album, but only a Dion single (yes, Moon breaks his own rules occasionally). And the curmudgeonly listeners at Pitchfork, Down Beat and the classical magazine Gramophone no doubt are wondering where some of their favorites are.

advertisement

For Moon -- as with probably anyone who's ever tried to make a comprehensive list of anything -- that's all part of the fun. Go ahead and argue; passion is better than indifference.

"These are starting points," he says.

Thursday, December 11, 2008

Teach yourself JAVA--day 1

An Introduction to Java Programming

Hello and welcome to Teach Yourself Java in 21 Days! Starting today and for the next three weeks you'll learn all about the Java language and how to use it to create applets, as well as how to create stand-alone Java applications that you can use for just about anything.

An applet is a dynamic and interactive program that can run inside a Web page displayed by a Java-capable browser such as HotJava or Netscape 2.0.

The HotJava browser is a World Wide Web browser used to view Web pages, follow links, and submit forms. It can also download and play applets on the reader's system.

That's the overall goal for the next three weeks. Today, the goals are somewhat more modest, and you'll learn about the following:

  • What exactly Java and HotJava are, and their current status

  • Why you should learn Java—its various features and advantages over other programming languages

  • Getting started programming in Java—what you'll need in terms of software and background, as well as some basic terminology

  • How to create your first Java programs—to close this day, you'll create both a simple Java application and a simple Java applet!


What Is Java?

Java is an object-oriented programming language developed by Sun Microsystems, a company best known for its high-end Unix workstations. Modeled after C++, the Java language was designed to be small, simple, and portable across platforms and operating systems, both at the source and at the binary level (more about this later).

Java is often mentioned in the same breath as HotJava, a World Wide Web browser from Sun like Netscape or Mosaic (see Figure 1.1). What makes HotJava different from most other browsers is that, in addition to all its basic Web features, it can also download and play applets on the reader's system. Applets appear in a Web page much in the same way as images do, but unlike images, applets are dynamic and interactive. Applets can be used to create animations, figures, or areas that can respond to input from the reader, games, or other interactive effects on the same Web pages among the text and graphics.


Figure 1.1. The HotJava browser.

Although HotJava was the first World Wide Web browser to be able to play Java applets, Java support is rapidly becoming available in other browsers. Netscape 2.0 provides support for Java applets, and other browser developers have also announced support for Java in forthcoming products.

To create an applet, you write it in the Java language, compile it using a Java compiler, and refer to that applet in your HTML Web pages. You put the resulting HTML and Java files on a Web site much in the same way that you make ordinary HTML and image files available. Then, when someone using the HotJava browser (or other Java-enabled browser) views your page with the embedded applet, that browser downloads the applet to the local system and executes it, and then the reader can view and interact with your applet in all its glory (readers using other browsers may see text, a static graphic, or nothing). You'll learn more about how applets, browsers, and the World Wide Web work together further on in this book.

The important thing to understand about Java is that you can do so much more with it besides create applets. Java was written as a full-fledged programming language in which you can accomplish the same sorts of tasks and solve the same sorts of problems that you can in other programming languages, such as C or C++. HotJava itself, including all the networking, display, and user interface elements, is written in Java.

Java's Past, Present, and Future

The Java language was developed at Sun Microsystems in 1991 as part of a research project to develop software for consumer electronics devices—television sets, VCRs, toasters, and the other sorts of machines you can buy at any department store. Java's goals at that time were to be small, fast, efficient, and easily portable to a wide range of hardware devices. It is those same goals that made Java an ideal language for distributing executable programs via the World Wide Web, and also a general-purpose programming language for developing programs that are easily usable and portable across different platforms.

The Java language was used in several projects within Sun, but did not get very much commercial attention until it was paired with HotJava. HotJava was written in 1994 in a matter of months, both as a vehicle for downloading and running applets and also as an example of the sort of complex application that can be written in Java.

This book is current as of the 1.0 Java Developer's Kit (JDK). The 1.0 JDK includes tools for developing Java applets and applications on Sun systems running Solaris 2.3 or higher and for Windows NT and Windows 95. By the time you read this, new releases of the JDK may be available, or there may be support for the JDK on other systems and platforms. All the examples and code in this book should work with any Java development environment that supports the 1.0 API.

To run and view Java applets, you'll need a Java-capable browser or other tool. Netscape 2.0 provides Java capabilities for most platforms, and other browsers may also be Java-enabled. As of this writing, however, Sun's HotJava does not support applets written under the 1.0 JDK. By the time you read this a more current version of HotJava may exist.

Sun's 1.0 JDK does include an application called appletviewer that allows you to test your Java applets as you write them. If an applet works in the appletviewer, it should work with any Java-capable browser. You'll learn more about applet viewer later today.

What's in store for the future? In addition to the next Java release from Sun, other companies have announced support for Java in their own World Wide Web browsers. Netscape Communications Corporation has already incorporated Java capabilities into the 2.0 version of their very popular Netscape Navigator Web browser—pages with embedded Java applets can be viewed and played with Netscape. With support for Java available in as popular a browser as Netscape, tools to help develop Java applications (debuggers, development environments, and so on) most likely will be rapidly available as well.

Why Learn Java?

At the moment, probably the most compelling reason to learn Java—and probably the reason you bought this book—is that HotJava applets are written in Java. Even if that were not the case, Java as a language has significant advantages over other languages and other programming environments that make it suitable for just about any programming task. This section describes some of those advantages.

Java Is Platform-Independent

Platform independence is one of the most significant advantages that Java has over other programming languages, particularly for systems that need to work on many different platforms. Java is platform-independent at both the source and the binary level.

Platform-independence is a program's capability of moving easily from one computer system to another.

At the source level, Java's primitive data types have consistent sizes across all development platforms. Java's foundation class libraries make it easy to write code that can be moved from platform to platform without the need to rewrite it to work with that platform.

Platform-independence doesn't stop at the source level, however. Java binary files are also platform-independent and can run on multiple platforms without the need to recompile the source. How does this work? Java binary files are actually in a form called bytecodes.

Bytecodes are a set of instructions that look a lot like machine code, but are not specific to any one processor.

Normally, when you compile a program written in C or in most other languages, the compiler translates your program into machine codes or processor instructions. Those instructions are specific to the processor your computer is running—so, for example, if you compile your code on a Pentium system, the resulting program will run only on other Pentium systems. If you want to use the same program on another system, you have to go back to your original source, get a compiler for that system, and recompile your code. Figure 1.2 shows the result of this system: multiple executable programs for multiple systems.


Figure 1.2. Traditional compiled programs.

Things are different when you write code in Java. The Java development environment has two parts: a Java compiler and a Java interpreter. The Java compiler takes your Java program and instead of generating machine codes from your source files, it generates bytecodes.

To run a Java program, you run a program called a bytecode interpreter, which in turn executes your Java program (see Figure 1.3). You can either run the interpreter by itself, or—for applets—there is a bytecode interpreter built into HotJava and other Java-capable browsers that runs the applet for you.


Figure 1.3. Java programs.

Why go through all the trouble of adding this extra layer of the bytecode interpreter? Having your Java programs in bytecode form means that instead of being specific to any one system, your programs can be run on any platform and any operating or window system as long as the Java interpreter is available. This capability of a single binary file to be executable across platforms is crucial to what enables applets to work, because the World Wide Web itself is also platform-independent. Just as HTML files can be read on any platform, so applets can be executed on any platform that is a Java-capable browser.

The disadvantage of using bytecodes is in execution speed. Because system-specific programs run directly on the hardware for which they are compiled, they run significantly faster than Java bytecodes, which must be processed by the interpreter. For many Java programs, the speed may not be an issue. If you write programs that require more execution speed than the Java interpreter can provide, you have several solutions available to you, including being able to link native code into your Java program or using tools to convert your Java bytecodes into native code. Note that by using any of these solutions, you lose the portability that Java bytecodes provide. You'll learn about each of these mechanisms on Day 20.

Java Is Object-Oriented

To some, object-oriented programming (OOP) technique is merely a way of organizing programs, and it can be accomplished using any language. Working with a real object-oriented language and programming environment, however, enables you to take full advantage of object-oriented methodology and its capabilities for creating flexible, modular programs and reusing code.

Many of Java's object-oriented concepts are inherited from C++, the language on which it is based, but it borrows many concepts from other object-oriented languages as well. Like most object-oriented programming languages, Java includes a set of class libraries that provide basic data types, system input and output capabilities, and other utility functions. These basic classes are part of the Java development kit, which also has classes to support networking, common Internet protocols, and user interface toolkit functions. Because these class libraries are written in Java, they are portable across platforms as all Java applications are.

You'll learn more about object-oriented programming and Java tomorrow.

Java Is Easy to Learn

In addition to its portability and object-orientation, one of Java's initial design goals was to be small and simple, and therefore easier to write, easier to compile, easier to debug, and, best of all, easy to learn. Keeping the language small also makes it more robust because there are fewer chances for programmers to make difficult-to-find mistakes. Despite its size and simple design, however, Java still has a great deal of power and flexibility.

Java is modeled after C and C++, and much of the syntax and object-oriented structure is borrowed from the latter. If you are familiar with C++, learning Java will be particularly easy for you, because you have most of the foundation already.

Although Java looks similar to C and C++, most of the more complex parts of those languages have been excluded from Java, making the language simpler without sacrificing much of its power. There are no pointers in Java, nor is there pointer arithmetic. Strings and arrays are real objects in Java. Memory management is automatic. To an experienced programmer, these omissions may be difficult to get used to, but to beginners or programmers who have worked in other languages, they make the Java language far easier to learn.

Getting Started with Programming in Java

Enough background! Let's finish off this day by creating two real Java programs: a stand-alone Java application and an applet that you can view in either in the appletviewer (part of the JDK) or in a Java-capable browser. Although both these programs are extremely simple, they will give you an idea of what a Java program looks like and how to compile and run it.

Getting the Software

In order to write Java programs, you will, of course, need a Java development environment. At the time this book is being written, Sun's Java Development Kit provides everything you need to start writing Java programs. The JDK is available for Sun SPARC systems running Solaris 2.3 or higher and for Windows NT and Windows 95. You can get the JDK from several places:


Note: The Java Development Kit is currently in release 1.0. By the time you read this, the JDK may be available for other platforms, and other organizations may be selling Java development tools as well.

Although Netscape and other Java-enabled browsers provide an environment for running Java applets, they do not provide a mechanism for developing Java applications. For that, you need separate tools—merely having a browser is not enough.

Applets and Applications

Java programs fall into two main groups: applets and applications.

Applets, as you have learned, are Java programs that are downloaded over the World Wide Web and executed by a Web browser on the reader's machine. Applets depend on a Java-capable browser in order to run (although they can also be viewed using a tool called the appletviewer, which you'll learn about later today).

Java applications are more general programs written in the Java language. Java applications don't require a browser to run, and in fact, Java can be used to create all the kinds of applications that you would normally use a more conventional programming language to create. HotJava itself is a Java application.

A single Java program can be an applet or an application or both, depending on how you write that program and the capabilities that program uses. Throughout this first week, you'll be writing mostly HotJava applications; then you'll apply what you've learned to write applets in Week 2. If you're eager to get started with applets, be patient. Everything that you learn while you're creating simple Java applications will apply to creating applets, and it's easier to start with the basics before moving onto the hard stuff. You'll be creating plenty of applets in Week 2.

Creating a Java Application

Let's start by creating a simple Java application: the classic Hello World example that all language books use to begin.

As with all programming languages, your Java source files are created in a plain text editor, or in an editor that can save files in plain ASCII without any formatting characters. On Unix, emacs, pico, or vi will work; on Windows, Notepad or DOS Edit are both text editors.

Fire up your editor of choice, and enter the Java program shown in Listing 1.1. Type this program, as shown, in your text editor. Be careful that all the parentheses, braces, and quotes are there.

    Listing 1.1. Your first Java application.
1: class HelloWorld {

2: public static void main (String args[]) {
3: System.out.println("Hello World!");
4: }
5: }

Warning: The numbers before each line are part of the listing and not part of the program; they're there so I can refer to specific line numbers when I explain what's going on in the program. Do not include them in your own file.

This program has two main parts:

  • All the program is enclosed in a class definition—here, a class called HelloWorld.

  • The body of the program (here, just the one line) is contained in a method (function) called main(). In Java applications, as in a C or C++ program, main() is the first method (function) that is run when the program is executed.


You'll learn more about both these parts of a Java application as the book progresses.

Once you finish typing the program, save the file. Most of the time, Java source files are named the same name as the class they define, with an extension of .java. This file should therefore be called HelloWorld.java.

Now, let's compile the source file using the Java compiler. In Sun's JDK, the Java compiler is called javac.

To compile your Java program, Make sure the javac program is in your execution path and type javac followed by the name of your source file:

javac HelloWorld.java

Note: In these examples, and in all the examples throughout this book, we'll be using Sun's Java compiler, part of the JDK. If you have a third-party development environment, check with the documentation for that program to see how to compile your Java programs.

The compiler should compile the file without any errors. If you get errors, go back and make sure that you've typed the program exactly as it appears in Listing 1.1.

When the program compiles without errors, you end up with a file called HelloWorld.class, in the same directory as your source file. This is your Java bytecode file. You can then run that bytecode file using the Java interpreter. In the JDK, the Java interpreter is called simply java. Make sure the java program is in your path and type java followed by the name of the file without the .class extension:

java HelloWorld

If your program was typed and compiled correctly, you should get the string "Hello World!" printed to your screen as a response.


Note: Remember, the Java compiler and the Java interpreter are different things. You use the Java compiler (javac) for your Java source files to create .class files, and you use the Java interpreter (java) to actually run your class files.

Creating a Java Applet

Creating applets is different from creating a simple application, because Java applets run and are displayed inside a Web page with other page elements and as such have special rules for how they behave. Because of these special rules for applets in many cases (particularly the simple ones), creating an applet may be more complex than creating an application.

For example, to do a simple Hello World applet, instead of merely being able to print a message, you have to create an applet to make space for your message and then use graphics operations to paint the message to the screen.


Note: If you run the Hello World application as an applet, the Hello World message prints to a special window or to a log file, depending on how the browser has screen messages set up. It will not appear on the screen unless you write your applet to put it there.

In the next example, you create that simple Hello World applet, place it inside a Web page, and view the result.

First, you set up an environment so that your Java-capable browser can find your HTML files and your applets. Much of the time, you'll keep your HTML files and your applet code in the same directory. Although this isn't required, it makes it easier to keep track of each element. In this example, you use a directory called HTML that contains all the files you'll need.

mkdir HTML

Now, open up that text editor and enter Listing 1.2.

    Listing 1.2. The Hello World applet.
1: import java.awt.Graphics;

2:
3: public class HelloWorldApplet extends java.applet.Applet {
4:
5: public void paint(Graphics g) {
6: g.drawString("Hello world!", 5, 25);
7: }
8:}

Save that file inside your HTML directory. Just like with Java applications, give your file a name that has the same name as the class. In this case, the filename would be HelloWorldApplet.java.

Features to note about applets? There are a couple I'd like to point out:

  • The import line at the top of the file is somewhat analogous to an #include statement in C; it enables this applet to get access to the JDK classes for creating applets and for drawing graphics on the screen.

  • The paint() method displays the content of the applet onto the screen. Here, the string Hello World gets drawn. Applets use several standard methods to take the place of main(), which include init() to initialize the applet, start() to start it running, and paint() to display it to the screen. You'll learn about all of these in Week 2.

Now, compile the applet just as you did the application, using javac, the Java compiler.

javac HelloWorldApplet.java

Again, just as for applications, you should now have a file called HelloWorldApplet.class in your HTML directory.

To include an applet in a Web page, you refer to that applet in the HTML code for that Web page. Here, you create a very simple HTML file in the HTML directory (see Listing 1.3).

    Listing 1.3. The HTML with the applet in it.
1:

2:
Hello to Everyone!3:
4:
5:

My Java applet says:
6:
7:
8:

You refer to an applet in your HTML files with the tag. You'll learn more about later on, but here are two things to note:
  • Use the CODE attribute to indicate the name of the class that contains your applet.





  • Use the WIDTH and HEIGHT attributes to indicate the size of the applet. The browser uses these values to know how big a chunk of space to leave for the applet on the page. Here, a box 150 pixels wide and 25 pixels high is created.





Save the HTML file in your HTML directory, with a descriptive name (for example, you might name your HTML file the same name as your applet—HelloWorldApplet.html).

And now, you're ready for the final test—actually viewing the result of your applet. To view the applet, you need one of the following:

  • A browser that supports Java applets, such as Netscape 2.0.





  • The appletviewer application, which is part of the JDK. The appletviewer is not a Web browser and won't enable you to see the entire Web page, but it's acceptable for testing to see how an applet will look and behave if there is nothing else available.






Note: Do not use the alpha version of HotJava to view your applets; applets developed with the beta JDK and onward cannot be viewed by the alpha HotJava. If, by the time you read this, there is a more recent version of HotJava, you can use that one instead.

If you're using a Java-capable browser such as Netscape to view your applet files, you can use the Open Local... item under the File menu to navigate to the HTML file containing the applet (make sure you open the HTML file and not the class file). You don't need to install anything on a Web server yet; all this works on your local system.

If you don't have a Web browser with Java capabilities built into it, you can use the appletviewer program to view your Java applet. To run appletviewer, just indicate the path to the HTML file on the command line:

appletviewer HTML/HelloWorldApplet.html

Tip: Although you can start appletviewer from the same directory as your HTML and class files, you may not be able to reload that applet without quitting appletviewer first. If you start appletviewer from some other directory (as in the previous command line), you can modify and recompile your Java applets and then just use the Reload menu item to view the newer version.

Now, if you use the browser to view the applet, you see something similar to the image shown in Figure 1.4. If you're using appletviewer, you won't see the text around the applet (My Java applet says...), but you will see the Hello World itself.


Figure 1.4. The Hello World applet.

Summary

Today, you got a basic introduction to the Java language and its goals and features. Java is a programming language, similar to C or C++, in which you can develop a wide range of programs. The most common use of Java at the moment is in creating applets for HotJava, an advanced World Wide Web browser also written in Java. Applets are Java programs that are downloaded and run as part of a Web page. Applets can create animations, games, interactive programs, and other multimedia effects on Web pages.

Java's strengths lie in its portability—both at the source and at the binary level, in its object-oriented design—and in its simplicity. Each of these features help make applets possible, but they also make Java an excellent language for writing more general-purpose programs that do not require HotJava or other Java-capable browser to run. These general-purpose Java programs are called applications. HotJava itself is a Java application.

To end this day, you experimented with an example applet and an example application, getting a feel for the differences between the two and how to create, compile, and run Java programs—or, in the case of applets, how to include them in Web pages. From here, you now have the foundation to create more complex applications and applets.

Q&A

Q: I'd like to use HotJava as my regular Web browser. You haven't mentioned much about HotJava today.

A: The focus of this book is primarily on programming in Java and its library of standard classes, rather than on using HotJava itself. Documentation for using the HotJava browser comes with HotJava (see http://java.sun.com/).

Q: I know a lot about HTML, but not much about computer programming. Can I still write Java programs?

A: If you have no programming experience whatsoever, you most likely will find programming Java significantly more difficult. However, Java is an excellent language to learn programming with, and if you patiently work through the examples and the exercises in this book, you should be able to learn enough to get started with Java.

Q: According to today's lesson, Java applets are downloaded via a Java-enabled browser such as HotJava or Netscape 2.0 and run on the reader's system. Isn't that an enormous security hole? What stops someone from writing an applet that compromises the security of my system—or worse, that damages my system?

A: Sun's Java team has thought a great deal about the security of applets within Java-capable browsers and has implemented several checks to make sure applets cannot do nasty things:

  1. Java applets cannot read or write to the disk on the local system.





  2. Java applets cannot execute any programs on the local system.





  3. Java applets cannot connect to any machines on the Web except for the server from which they are originally downloaded.

    Note that some of these restrictions may be allowed in some browsers or may be turned on in the browser configuration. However, you cannot expect any of these capabilities to be available.

    In addition, the Java compiler and interpreter check both the Java source code and the Java bytecodes to make sure that the Java programmer has not tried any sneaky tricks (for example, overrunning buffers or stack frames).

    These checks obviously cannot stop every potential security hole (no system can promise that!), but they can significantly reduce the potential for hostile applets. You'll learn more about security issues later on in this book.






Q: I followed all the directions you gave for creating a Java applet. I loaded it into HotJava, but Hello World didn't show up. What did I do wrong?

A: I'll bet you're using the alpha version of HotJava to view the applet. Unfortunately, between alpha and 1.0, significant changes were made as to how applets are written. The result is that you can't view 1.0 applets (as this one was) in the alpha version of HotJava, nor can you view alpha applets in browsers that expect 1.0 applets. To view the applet, either use a different browser, or use the appletviewer application that comes with the JDK.

ss_blog_claim=275a20a4857e533d845cca9b04445ef3