楼主: ReneeBK
1467 13

Technical Java™: Developing Scientific and Engineering Applications [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49407 个
通用积分
51.8704
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

  • Technical Java™: Developing Scientific and Engineering Applications
  • By: Grant Palmer

  • Publisher: Prentice Hall

  • Pub. Date: April 21, 2003

  • Print ISBN-10: 0-13-101815-9

  • Print ISBN-13: 978-0-13-101815-0

  • Pages in Print Edition: 496

  • Subscriber Rating: [0 Ratings]



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Applications Application Engineering engineerin Developing Java

本帖被以下文库推荐

沙发
ReneeBK 发表于 2015-7-26 06:51:55 |只看作者 |坛友微信交流群
Java Classes vs. C Structs

Java is an object-oriented programming language. C is not. The C language does not support objects. The closest C comes to defining an object is the struct or union programming constructs. As you probably know, a struct is a collection of named data members. The data members can be of different types. You can declare a struct variable that is a reference to a struct. The values of the struct data members can be accessed by typing the structvariable name, a period, and the data member name.

If you are familiar with using structs, it shouldn't be too great a leap to become familiar with the concept of a class. A Java class is basically just a named block of code that defines a collection of both fields and methods. A class is more self-contained than a struct in that a class can (and should) define all the methods required to manipulate its data members. Java classes can make use of the powerful object-oriented concepts of inheritance, polymorphism, and encapsulation. There are many different types of classes according to whether one or more modifying keywords are applied to them. You can have public and private classes, abstract and final classes. You can nest a class definition inside another class definition

You can create instances of a class. A class instance is also known as an object. You can declare variables that are references to class instances. A class can define a class instance as one of its fields.


使用道具

藤椅
ReneeBK 发表于 2015-7-26 06:54:39 |只看作者 |坛友微信交流群
Variables

Both C and Java define a variety of data types. The types each language supports are shown in [url=]Table 3.1[/url].

Some of the types supported by C are not supported by Java and vice versa. Java does not support signed or unsigned types. All Java integral types (including char) are signed. Java does not use the long double or void type. Java does not support pointers, so there are no pointer or function pointer types in Java. The same can be said of struct and union types.

Java does provide some useful data types that are not provided by C. The boolean type has a true or false value. Using a boolean variable is more convenient than using 0 for false and 1 for true as in C. Java provides the byte type that represents a single byte of data. Because Java is object oriented, you can declare variables that are references to class instances (objects).

When a C variable is declared outside of any function definition it is a global variable and is available anywhere inside a C program. Java does not support global variables. A Java class variable is one that is declared outside of any method definitions and is available anywhere inside the class in which it is declared. Both C and Java support local variables. A local variable is declared inside a method, a for statement, or other block of code and exists only inside the block in which it is defined.



使用道具

板凳
ReneeBK 发表于 2015-7-26 06:55:59 |只看作者 |坛友微信交流群
Pointers

A C program can make use of pointers to directly access locations in memory. Pointers can be used to change the value of a variable and are also routinely used to manipulate arrays. Pointers can be useful in certain situations but can also be dangerous in that pointers have the potential to do bad things such as corrupt memory.

Java does not support publicly accessible pointers. Java has been designed so that there is no reason to use pointers. A Java primitive type variable stores a single value. You can manipulate the value directly. A reference type variable holds the address where a class instance or array is stored. The reference type variable provides all the access you will need.


使用道具

报纸
ReneeBK 发表于 2015-7-26 06:57:41 |只看作者 |坛友微信交流群
Functions and Methods

In C they are called functions. Java calls them methods. Both are named blocks of code that can be called from somewhere else in a program. Functions are the basic building blocks of a C program. Java methods, on the other hand, are always declared inside of a class. Java methods do not have to be prototyped.

A C function declaration includes the return type, function name, and input parameter list. The only modifying keywords that can be applied to a C function are extern, which means the function is defined outside of the current file, or static, which means the function cannot be referenced from other files. The body of the function is enclosed in braces.

Java method declarations contain the return type, name, and input parameter list of the method. The declaration may also include modifying keywords and a throws clause. Java methods are more powerful and versatile than their C counterparts. For one thing, Java methods can be given an access modifier. This keyword defines how and when the method can be accessed by other code. Java methods can be declared to be static, abstract, final, native, andsynchronized. As with C, the body of a Java method is enclosed in braces.

Input arguments are passed to a C function by value, meaning that a copy of the value of the variable is sent to the function. Any changes made to the variable inside the function will not be reflected in the original variable. To have a C function alter the value of the original variable, a pointer to the variable must be passed to the function.

Arguments to Java methods are also passed by value. For arguments representing primitive types, a copy of the argument value is sent to the method. Any changes made to the value inside the method will not be made to the original value. For arguments representing reference types (objects or arrays), a copy of the reference to the location in memory where the data for the object or array is stored is sent to the method. Any changes made to the object inside the method will also be made to the original object.

C functions are called by simply typing the function name and providing the appropriate arguments. The way that Java methods are called depends on where the method call occurs. Inside the class in which they are defined, Java methods can be called by typing the method name and providing the appropriate arguments. Outside of the class in which they are defined, Java methods are called relative to a class instance or the class name depending on whether it is an instance or static method.


使用道具

地板
ReneeBK 发表于 2015-7-26 06:59:36 |只看作者 |坛友微信交流群
Arrays

While Java and C both start array indices from zero, there is a fundamental difference in the way the two languages treat arrays. With C, an array of a given data type is treated as a sequence of members of that type stored in contiguous locations in memory. The declaration syntax is the data type, the array name, and the size of the array enclosed in brackets.

int data[5];

The members of a C array can be accessed using the array name and index or with a pointer to the array. C arrays can be given a fixed size when they are declared or you can create a dynamically allocated array using pointers and themalloc() function.

In Java, arrays are reference types just like class instances. Creating a Java array is a two-step process. You first declare an array variable by specifying its type and name followed by a pair of brackets—

int data[];

Declaring an array variable does not allocate any memory for it. The second step in the array creation process is to allocate memory for the array variable using the new keyword followed by the type and size of the array.

data = new int[5];—

The two steps can be combined to a single line

int data[] = new int[5];

Elements of a C array can be accessed either through the array index or by using a pointer to the array. Because Java does not support pointers, Java array elements are accessed only through indexes. Both C and Java use a pair of brackets around the index of the element to be accessed. For example, to assign the value 45 to the third element of an array named data you would type—

data[2] = 45;

When looking at the above syntax, keep in mind that Java array indices start at 0. The first element of the data array would be data[0].


使用道具

7
ReneeBK 发表于 2015-7-26 07:02:39 |只看作者 |坛友微信交流群
Dynamic Memory Allocation

With C, you can define the size of an array when the array is declared. Using pointers, you can also determine the size and dynamically allocate memory for an array at runtime. This can be useful if the required size for the array may vary from run to run in that you don't have to worry about declaring a really large array to cover all possibilities. The downside to dynamic memory allocation is that it is up to the programmer to properly allocate and deallocate the dynamic memory. If memory is not properly deallocated, you can create the dreaded memory leak.

Java does not support explicit dynamic memory allocation and deallocation because a sophisticated memory management system is part of the JVM that executes Java programs. As part of the memory management system, Java uses a mechanism known as the garbage collector that periodically monitors a Java program while it is running. Whenever a variable goes out of scope it is eligible to be garbage collected, meaning that memory assigned to the variable is deallocated and made available for use by some other part of the program. A Java programmer never has to worry about manually deallocating memory.


使用道具

8
ReneeBK 发表于 2015-7-26 07:08:02 |只看作者 |坛友微信交流群
Exception Handling

Exception handling allows you to recover from errors that might occur while your program is running. The C language has no built-in exception handling. If you want exception handling in a C program, you have to do it yourself. User-defined exception handling usually involves a potentially complicated series of if-then statements and user-defined error codes. The exception handling generally has to take place where the exception occurs. In a C program you cannot easily pass the exception handling off to another part of the code.

Exception handling is a part of the Java language. There are a series of classes and programming constructs that allow you to easily build exception handling capabilities into your Java program. You can define your own exception classes for any unique needs that your program might have. Blocks of code are used to catch and process exceptions. What's more, the exception handling can be passed on to another part of the program. The exception handling does not have to be performed where the exception occurs.


使用道具

9
ReneeBK 发表于 2015-7-26 07:08:43 |只看作者 |坛友微信交流群
C Libraries and the Java APIs

Both C and Java have built-in libraries that you can access when writing your programs. The C libraries are somewhat limited in scope and consist mostly of functions and constants. You can import C libraries into your program using#include statements placed at the top of your program.

One of the great strengths of the Java language is the enormous collection of code libraries that you can utilize when developing your programs. The Java libraries are more commonly referred to as the Java Application Programming Interfaces (APIs). The Java APIs cover everything from I/O to GUI development to security and anything in between. The APIs consist of a collection of classes and interfaces organized in groups called packages. You can import part or all of a package into your program by placing import declarations at the top of the program. As well as providing a lot of useful methods and constants, the Java APIs include the class declarations that constitute a rich and sophisticated source of reusable code for your Java applications.


使用道具

10
ReneeBK 发表于 2015-7-26 07:11:22 |只看作者 |坛友微信交流群
Strings

A string is a sequence of characters. Strings are very important when it comes to displaying, naming, and describing data. The C and Java languages represent strings in very different ways. In C, a string is represented by an array of characters. The end of the string is designated as such by the null character '/0'. The C libraries provide functions to manipulate strings such as the strcpy(), strcat(), and strcmp() functions. When dealing with these functions and with C strings in general you often use pointers.

In Java, strings are represented by the String class and as such are treated as any other reference type. The String class defines a large number of methods for creating, manipulating, and modifying strings. Java strings are immutable. Once a String object is initialized it cannot be changed. If a method is used to modify a string, a new String object is created containing the modified string. Both Java and C support the concept of a string literal. Any text surrounded by double quotes is a string literal.


使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 03:07