1 / 12

The programming language Java fully supports the object-oriented programming paradigm

The programming language Java fully supports the object-oriented programming paradigm. An Introduction To Java. Java …. Has borrowed much of its syntactic structure from C++. Employs an extensive library of classes as does Smalltalk.

janina
Télécharger la présentation

The programming language Java fully supports the object-oriented programming paradigm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The programming language Java fully supports the object-oriented programming paradigm An Introduction To Java

  2. Java … Has borrowed much of its syntactic structure from C++ Employs an extensive library of classes as does Smalltalk Encapsulates within a single file both declaration and definition of classes as does Eiffel Uses an automated technique for linking all necessary files into one executable file as does Ada What Java brings to the table is … Its relative ease of use in conjunction with the Internet Its capability with respect to concurrent programming and …

  3. Platform Independence The output from the Java compiler is platform independent Instead of translating source code into native code, source code is transformed into the code of a virtual machine The Java compiler’s output is called bytecode Any platform having an interpreter from bytecode to its native code then a Java compiled program may be executed on that platform

  4. Runtime Approach Java source code may be composed as a standalone program (an application) or may be constructed in such a manner that it may be run through a Web browser (an applet) Versions of Java – from 1.0 to 1.2 Use Java 1.2 for applications and Java 1.02 for applets placed on the Internet (or Java 1.2 for Intranet applets)

  5. How to Compose, Compile, and Interpret a Java Application Compose source code using plain text editor Save source code under file name identical to code’s public class name with extension “.java” (e.g., First.java) Submit source code to Java compiler (e.g., javac First.java) Bytecode file(s) produced upon successful compilation, (e.g., First.class) Invoke bytecode interpreter to execute program (e.g., java First)

  6. The Look of a Simple Java Application Program //File CounterApplication.java import java.io.*; class Counter { } private int n=0; public void inc() { n++; } public void dec() { n--; } public void display() { System.out.print(n); } public class CounterApplication { } public static void main(String[] args) { Counter c=new Counter(); . . }

  7. The Java Underbelly Java is a case-sensitive, free-format language Comments: //… /*…*/ /**…*/ (documentation) Identifiers: ( <letter> | ”_” | “$” ) { <letter> | <digit> } Primitive Data Types (platform independent): Type Size Range Default Value

  8. Declaring Primitive Types Variable Declaration: <type> <name> [“=“ <expression>] e.g., short sh; boolean done; int n=19; char ch=‘A’; Constant Declaration: [“static”] “final” <type> <name> “=“ <value> e.g., final int MAX=20; static final double PI=3.14159;

  9. Arithmetic Operators, Expressions, and Assignment Statements The formation and evaluation of arithmetic expressions and their assignment -- effectively the same as C++ with respect to precedence and associativity of operators The Arithmetic Operators operator semantics (and value returned) ++,-- operand value incremented/decremented by 1; returns value depending on whether prefix or postfix *,/,% perform indicated operation on the two operands; ‘/’ returns quotient, ‘%’ returns remainder for integer types +,-, perform indicated operation on the one or two operands; returns result

  10. The Assignment Operators operator semantics (and value returned) = assign value of rhs to variable on lhs; returns value of rhs +=,-=,*=,/=,%= perform indicated operation on lhs & rhs; assign result to lhs variable; returns value of result The Relational Operators operator semantics The Boolean Operators operator semantics (short-circuit) <= less than or equal >= greater than or equal < less than > greater = = equal != not equal ! not &, && and, (and then) |, || or, (or else)

  11. Some Typical C++ Syntax And The Java Equivalents: In C++ In Java cout<<"Answer: "<<answer; System.out.println("Answer: " + answer); cin>>ch; ch=System.in.read(); void main() public static void main(String[] args) int main(int argc,char** argv) public static void main(String[] args) const int MAX=10; final int MAX=10; char* str; String str; int* scores=new int[5]; int[] scores=new int[5]; delete scores; N/A -- equivalent not needed

  12. Casting Primitive Types Java is a relatively strongly typed language But, at times, there is a need to convert (cast) one type to another Given a variable of some type, casting is the process of producing a new variable of the desired type whose value is based on that of the original Implicit Casting: From smaller to larger type E.g., short sh=56; float fl=34.87F; int n; double d=fl; n=sh; No degradation of data Explicit Casting: From larger to smaller type Syntax needed: “(” <type> “)” <variable> E.g., int n=345; byte b=(byte)n; Might be accompanied by degradation of data Casting has a higher precedence than arithmetic operations E.g., float x=4.6f, y=1.1f; double d=(int)(x/y); //trucate x/y, then assign result to d

More Related