Similarities and differences between java and object-c (object-c Entry 1)

Source: Internet
Author: User

Basic knowledge of ios:

XCode: You can regard it as a development environment, just like Visual Studio, Netbeans, or SharpDevelop. You can think of Interface Builder as a separate program that is used to draw interfaces in Visual Studio.

Objective-C: This is a language, as if c ++ is a language, Java is a language, c # is a language, and the history of Yingge is also a language.

Cocoa: There are a lot of function libraries, such as MFC,. NET, and Swing. People have already written a bunch of ready-made stuff. You only need to know how to use it.

Some may confuse Objective-C and Cocoa, as if some may confuse c # And. NET. These two things are actually two different things.



Object-c Knowledge:

1. Role of minus signs

Declaration method. obj has no permissions such as public and private.

+ Indicates static, which can be called without instantiation.

Java:

Public void hello (boolean isHello ){

//

}

Obj statement:

-(Void) hello :( BOOL) isHello {

//

}

2. brackets (call method)

This is self in obj, and yes, no is used in Boolean.

Java:

This. hello (true );

Obj:

[Self hello: YES];


3. NS, UI, CA, and so on start with a written function library. You can call it.

NSLog (@ "% d", myInt );


4. nil indicates null.


5, # import is equivalent to importing a package

# Improt and # include are the same


6, @ interface

Obj is implemented after being declared first. The H file declaration, @ interface + @ end, and m file implementation @ implementation + @ end. Isn't it troublesome?

Java:

public class Bird extends Animal{private string name = "tom"private bool isDie(){return true;}}


Obj:

Write a Bird. h file first.

@interface Bird :NSObject {NSString *name;}-(BOOL) isDie;@end



Write another Bird. m file.

#import "Bird.h"@implementation Bird-(void) init{name = @"tom";}-(BOOL) isDie{return YES;}@end



7 multi-parameter Methods

Java:

Public void eat (int count, String name ){

}

Call: this. eat (3, "frog ");

Obj:

Definition

-(Void) eat :( int) count second :( NSString *) name;

Implementation:

-(Void) eat :( int) count second :( NSString *) name {

//

};

Call: [self eat: 3 second @ "frog"]; why is it so troublesome ??


They are all object-oriented languages. They used to learn java. If you have any mistakes, please correct them.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.