-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample.java
More file actions
66 lines (52 loc) · 1.93 KB
/
Example.java
File metadata and controls
66 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Class - A class can be defined as a template/blueprint that describes the behavior/state that the object of its type supports.
Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behavior such as wagging
their tail, barking, eating. An object is an instance of a class.
Methods - A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written,
data is manipulated and all the actions are executed.
Write you first program on Notepad :
Example : Source Code
public class Student{
public static void main(String[] args){
System.out.println("Hello, Student!");
}
}
save this file Student.java (.java is used for java code) save in any folder (use cd foldername)
C:\> javac Student.java
C:\> java Student
Output : Hello, Student!
*/
//define class using class keyword
class Dog{ //Dog is class Name
//State of Dog Class
String dogName = "Tomy";
String color = "Black";
//behaviour of Dog Class
void barking(){};
void eating(){};
}
public class Example { //Main Class
public static void main(String[] args) { // Main Method of Example Class
/*
public - Access Modifer
static - Keyword
void - return type
main - Method name
args - array Name
String[] - data type of Array
*/
//Identifiers : All Java components require names. Names used for classes, variables, and methods are called identifiers.
//Note : A key word cannot be used as an identifier.
//valid Identifiers :
int salary = 200;
long $dollars = 500;
String _name = "Ritik";
long _1_value = 23445555;
//Invalid Identifiers : 123abc, -salary
//Java Modifiers :
/*
Access Modifers : default,public,private,protected
Non Access Modifiers : final, abstract, strictfp
*/
}
}