Thursday, 19 December 2013

wallpepars









java overview

4
An Introduction to Java Programming
M
T
W
R
F
S
S
DAY
DAY
1
P2/V4sqc7 TY Java in 21 Days 030-4 sdv 12.22.95 Ch01 LP#4
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 program-
ming 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.
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.
NEW
TERM
∗
030-4s CH01.i
1/29/96, 8:34 PM
4

Saturday, 19 October 2013

Concatenate two strings

\\ Concatenate two strings
 
 
 
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string str1("A");
  string str2("B");
  string str3("G");
  string str4;

  cout << "  str1: " << str1 << endl;
  cout << "  str2: " << str2 << endl;
  cout << "  str3: " << str3 << "\n\n";

  // Concatenate two strings.
  str4 = str1 + str3;
  cout << "str4 after begin assigned st1+str3: " << str4 << "\n\n";

  return 0;
}

Friday, 18 October 2013

Arrays of pointers to functions

\\ Arrays of pointers to functions

 
 
 
#include <iostream>
 
 void Square (int&,int&);
 void Cube (int&, int&);
 void Swap (int&, int &);
 void GetVals(int&, int&);
 void PrintVals(int, int);
 
 int main()
 {
     int valOne=1, valTwo=2;
     int i;
     const int MaxArray = 5;
     void (*pFuncArray[MaxArray])(int&, int&);
 
     pFuncArray[0] = GetVals; 
     pFuncArray[1] = Square; 
     pFuncArray[2] = Cube; 
     pFuncArray[3] = Swap; 
     pFuncArray[4] = Square; 
 
     for (i=0;i<MaxArray; i++)
     {
         pFuncArray[i](valOne,valTwo);
         PrintVals(valOne,valTwo);
     }
     return 0;
 }
 
 void PrintVals(int x, int y)
 {
     std::cout << "x: " << x << " y: " << y << std::endl;
 }
 
 void Square (int & rX, int & rY)
 {
     rX *= rX;
     rY *= rY;
 }
 
 void Cube (int & rX, int & rY)
 {
     int tmp;
 
     tmp = rX;
     rX *= rX;
     rX = rX * tmp;
 
     tmp = rY;
     rY *= rY;
     rY = rY * tmp;
 }
 
 void Swap(int & rX, int & rY)
 {
     int temp;
     temp = rX;
     rX = rY;
     rY = temp;
 }
 
 void GetVals (int & rValOne, int & rValTwo)
 {
     std::cout << "New value for ValOne: ";
     std::cin >> rValOne;
     std::cout << "New value for ValTwo: ";
     std::cin >> rValTwo;
 }

Search a two-dimension array

 \\ Search a two-dimension array
 
#include <iostream> 
#include <cstdio> 
using namespace std; 
 
int main() 
{ 
  int i; 
  char str[80]; 
  char numbers[10][80] = { 
    "A", "322", 
    "B", "976", 
    "C", "037", 
    "D", "400", 
    "E", "873" 
  }; 
 
  cout << "Enter name (A): "; 
  cin >> str; 
 
  for(i=0; i < 10; i += 2)  
    if(!strcmp(str, numbers[i])) { 
      cout << "Number is " << numbers[i+1] << "\n"; 
      break; 
    } 
   
  if(i == 10) cout << "Not found.\n"; 
   
 
  return 0; 
}

A function can be a member of one class and a friend of another

 
 \\ A function can be a member of one class and a friend of another
 
 
 
#include <iostream> 
using namespace std; 
 
class Cylinder; // a forward declaration 
 
enum colors { red, green, yellow }; 
 
class Cube  
{ 
 colors color; 
public: 
  Cube(colors c) { color= c; } 
  bool sameColor(Cylinder y); 
}; 
 
class Cylinder
 { 
 colors color; 
public: 
  Cylinder(colors c) { color = c; } 
  friend bool Cube::sameColor(Cylinder y); 
}; 
 
bool Cube::sameColor(Cylinder y) 
{ 
  if(color == y.color) 
    return true; 
  else 
    return false; 
} 
 
int main() 
{ 
  Cube cube1(red); 
  Cube cube2(green); 
  Cylinder cyl(green); 
 
  if(cube1.sameColor(cyl)) 
    cout << "cube1 and cyl are the same color.\n"; 
  else 
    cout << "cube1 and cyl are different colors.\n"; 
 
  if(cube2.sameColor(cyl)) 
    cout << "cube2 and cyl are the same color.\n"; 
  else 
    cout << "cube2 and cyl are different colors.\n"; 
 
  return 0; 
}

wapking

new images








Thursday, 15 August 2013

UNARY operetor in C++

#include<iostream.h>
#include<conio.h>

class data
{
    int x,y;
    public:
        void get()
        {
             cout<<"enter x";
            cin>>x;
             cout<<"enter y";
            cin>>y;


        }

        void operator -()
        {
            x=-x;
            y=-y;
        }

        void disp()
        {
            cout<<"\n x="<<x;
            cout<<"\n y="<<y;
        }
};
void main()
{
    data d;

    clrscr();

    d.get();
    -d;

    d.disp();

    getch();
}
www.java2s.com