with Java
Topic
Lecture 1
Fundamentals of Java
Operator overloading √ ×
Template classes √ ×
Global variables √ ×
Header files √ ×
Pointers √ ×
Interface and Package × √
API × √
Programming code
Environment Java
compiler
independent interprter
WIN32
interprter
Solaris
interprter
Macintosh
programming
Intel Pentium Sun Solaris Apple Macintosh
2. class HelloWorldApp {
3. public static void main ( String args[] ) {
4. System.out.println ("Hello Java !");
5. }
6. }
2. import java.awt.Graphics;
3. import java.applet.Applet;
4. public class HelloWorld extends Applet {
5. public void paint (Graphics g ) {
6. g.drawString("Hello World!" 50, 25);
7. }
8. }
class HelloWorldApp {
public static void main ( String args[ ] ) {
System.out.println ("Hello Java !");
}
}
class
public, static, void, main
String args[ ]
System.out.println
Short Term Course on C++ and
Java, 14-30 June, 2004, IIT
19.03.2018 Kharagpur, Lecture #1 31
General Structure of an Application
Document section (optional)
import java.lang.Math;
class SquareRoot
{
public static void main (String args[ ]) {
double x = 45; // Variable declaration and initialization
double y; // Declaration of another variable
y = Math.sqrt (x);
System.out.println("Square root of "+ x +"=" + y);
}
}
class FirstClass {
intidNo;
iIdNo = 555;
public static void print( ) {
System.out.println ( " First Class citizen" + idNo );
}
}
class SecondClass {
int idNo;
idNo = 111;
public startic void print( ) {
System.out.println ( " Second Class citizen " + idNo) ;
}
}
Short Term Course on C++ and
Java, 14-30 June, 2004, IIT
19.03.2018 Kharagpur, Lecture #1 34
Application with Multiple Classes
(contd..)
principalAmount
numberOfYears
rateOfInterest
tempString = in.readLine();
numberOfYears = Integer.parseInt(tempString);
Part 4
Method(s) for object interaction declared and defined here
import java.awt . *;
import java.applet. * ;
< applet code = " RectangleTest" width = 150 height = 100 >
< param name = xValue value = 20 >
< param name = yValue value = 40 >
<param name = wValue value = 100>
< param name = hValue value = 50 >
< /applet >