President Carter, arriving in Israel on the second leg of his trip to salvage the stalemated Middle East negotiations, said tonight he has "good reasons to hope" that an Egyptian-Israeli treaty can be reached.

After completing discussions with President Anwar Sadat of Egypt on what he termed "the final details" of a peace treaty, Carter said on arriving at Ben-Gurion Airport near here that he was looking forward to "completing the urgent business at hand on this brief visit."

"We have come a great distance together, perhaps a greater distance than many would have dreamed," Carter said at a welcoming ceremony at the airport.

But, in a pointed reference to Prime Minister Menachem Begin and Israel's Cabinet, which has vocally opposed any further concessions in the U.S.-sponssored compromise proposals, Carter added:

"But of course, the ultimate choice lies where those choices have always lain -- with chosen representatives of the people who have suffered directly from so many years of destruction and bloodshed."

Cater's remarks were strikingly optimistic and in sharp contrast to statements he made in Cairo and Alexandria. During his three days in Egypt, he studiously avoided presenting his discussions with Sadat in the context of nearing the conclusion of a treaty.

In a joint appearance with Sadat before leaving Cairo for the one-hour flight here, Carter said simply that the two leaders had "resolved some difficult issues," but that more disputed aspects of the treaty still need to be resolved.

Also, in a speech before the Egyptian parliament, Carter lent a new emphasis to the urgency of solving the question of self-determination for Palestinians in Gaza and on the West Bank of the Jordan River, apparently reflecting appeals on that topic conveyed by Sadat.

"I pledge to you today to move on to negotiations with regard to the West Bank and Gaza Strip, and also to the future of the Palestinians," Carter told the Egyptian assembly.

He added, "I feel a personal obligation in this regard."

Carter, Israeli sources said, brought with him from Cairo a personal message from Sadat to Begin, although the contents of the message were not known.

Israeli and U.S. sources, however, said it appeared that Sadat has agreed to make substantial concessions on the major unresolved issues -- linkage between the bilateral Egyptian-Israeli treaty and Palestinian autonomy and a timetable for autonomy negotiations -- in exchange for an intensified effort by the U.S. president to represent the interests of the Palestinians during his talks with Begin.

Sources said Carter and Begin also have to resolve major issues that, while tangential to the treaty, deal with the expense of a U.S. commitment to guarantee Israel future oil supplies and with the expense of military and economic assistance.

Israel reportedly has presented the United States with demands for $4 billion in grants to finance relocation of military bases in the Sinai Peninsula and dismantlement of other facilities, and for guarantees that the United States assure Israel supplies of oil equal to that it now pumps from wells in the Gulf of Suez that would return to Egyptian sovereignty under the peace treaty.

After driving from Ben-Gurion Airport to Jerusalem in the U.S. president's armor-plated limousine, Begin and Carter dined with their wives at the prime minister's residence on the eve of two days of intensive peace discussions scheduled to end with an address by Carter before the Israeli parliament, the Knesset, on Monday.

Begin's press secretary, Dan Pattir. said Carter and Begin held "very frank discussions" in a private meeting in Begin's study following the dinner, but he declined to reveal the substance of what they said.

Carter was greeted warmly at the airport by a small but enthusiastic crowd of dependents of American officials here, several hundred journalists, the entire Israeli Cabinet, top military officers and other government officials.

After reviewing an Israeli military honor guard, Carter said, "As I walked down the ranks of representatives of your military forces... I said a silent prayer to God that none of these men nor their compatriots would ever again have to give their lives in war.

"As Prime Minister Begin has said many times, Israel truly wants peace. Of that, there can be no doubt. And I feel absolutely certain, after my experience of the past three days, that the people of Egypt fully share that desire for peace," the president added.

The president of Israel, Yitzhak Navon, injected an element of suspense by saying to Carter, "At this moment, we do not know, as yet, what tidings you carry with you from your visit to our great neighbor, Egypt.

"Does the dove of peace which has emerged from the ark carry an olive branch in his beak, or will it have to wait some time longer until the waters of the flood are abated from off the earth, so that it can, at last, find a resting piace for its feet?"

Begin, who stood beside Carter throughout the welcoming ceremonies, did not make any remarks.

As he approached the entrance to Jerusalem, Carter stopped briefly for the traditional Jewish welcoming ceremony of receiving bread and salt before going on to Begin's house for the private dinner.

Carter's visit, although his first as president, marked his second trip to Jerusalem. He first came as governor of Georgia in 1973.

Only a few thousand people lined the main roads leading into Jerusalem, in sharp contrast to the turnout for Sadat when he visited here in November 1977 to launch his peace initiative.

Some of those greeting Carter did so with shouts of "Carter go home," reflecting fears that the U.S. president intends to pressure the Cabinet into more concessions. At one point, Carter's limousine was hit by an egg.

Members of the nationalist Gush Emunim movement waved banners saying, "Welcome Billy's Brother."

Another sign of protest came from Geula Cohen, a hawkish member of the Israeli parliament who frequently takes radically nationalist positions. She announced she would boycott official ceremonies connected with Carter, saying: "I will not shake the hand that puts pressure on Israel."

Earlier in the day, Palestinian students at Beir Zeit University near the West Bank town of Ramallah, and high school students in the town itself boycotted classes and held demonstrations protesting Carter's visit. They issued a "manifesto" declaring that the Palestine Liberation Organization is the sole representative of West Bank Palestinians.

High school students in Ramallah set up roadblocks and burned tires until they were dispersed by soldiers.

All along the 37-mile route from the airport, Israeli soldiers, some in armored vehicles, were evident in a display of intensified security following an attempted guerrilla attack early this morning. About midnight, an Israeli Army patrol surprised a group of four Palestinian commandos that had crossed the Jordan River south of the Adam Bridge. In an exchange of gunfire, the four Palestinians were killed, the army command said.

Army officials said they recoverea a number of automatic weapons and notes indicating that the Palestinians intended to seize Jewish hostages and demand the release of Palestinian prisoners in exchange. The notes indicated the commandos wanted the Vatican to negotiate the terms, the officials reported.

Army officials said the intrusion apparently was infended to mar Carter's visit.