Lecture 2: Simple java program and How to compile and interpret the java program смотреть онлайн
Simple java program and How to compile and interpret the java program
Simple java program:
class Sample
{
public static void main(String args[])
{
System.out.println(“Java is better than c and c++”);
}
}
Output:
Java is better than c and c++
Explanation:
1. main function:
public static void main(String args[])
Defines a method named main.
Every java application program must contains main method.
This is starting point for interpreter to begin execution of program.
Java application can have any number of classes but only one of them must inside a main method to initiate execution.
Note that Java applet is not using main method at all.
i. public: access specifier and making it accessible to all other classes.
Ii. static: which declares this method as one that belongs to entire class and not a part of any objects of the class. The main method must always be declared as static since interpreter calls this method before any object of that particular class is created.
Iii. void: does not return any value by main method.
main method requires one argument that is String args[], which of type String and args is an array of object of class String.
2. println method:
System.out.println(“Java is better than c++”);
Since Java is true object oriented programming language, every method must be part of a class.
println method is member function of PrintStream class, and out is object of that class which is declared as static data member in System class. So out data member of System class is called using class name System and method println is called using out object because println is instantiable method of class PrintStream. Method println always appends a newline character at the end of string and prints output on the text mode window.
Every java statement must end with semicolon.
Suppose, int x=20;
And System.out.println(x);
Then output will be now “20”, that is Java converts the value of x which is 20 from integer to string that is ‘”20”. String is always represented between “ ”.
System class contains data members as,
public final static InputStream in = new InputStream();
public final static PrintStream out = new PrintStream();
Also PrintStream class is present in java.io package and contains print(), println() and printf() methods. Therefore, to print string on console, we write
System.out.println(“Hello”);
out is static data member, so called by using class name that is System class here and println method is present in class PrintStream so it is called by object of that class and out is object of PrintStream class.
1.12 println methods and their respective outputs:
1.System.out.println();
Output: Blank line
2.System.out.println(2+3);
Output: 5
3.System.out.println(“2+3”);
Output: 2+3
4.System.out.println(Hello);
Output: error
5.System.out.println(“Value = “+3);
Output: Value = 3
6.System.out.println(“Value = ”+2+3);
Output: Value = 23
7.System.out.println(“value = ” +(2+3));
Output: Value = 5
8.System.out.println(“value = ”+2-3);
Output: error
9.System.out.println(“value = ”+(2-3));
Output: Value = -1
10.System.out.println(“value = ”+(2-3)+”OK”);
Output: value = -1 OK
11.System.out.println(4*2-2);
Output: 6
12.System.out.println(“value = ”+4*2);
Output: value = 8
13.System.out.println(“value = ”+4/2);
Output: value = 2
14.System.out.println(3*2+” value ”+2+2);
Output: 6 value 22
15.System.out.println(2+2+”value”);
Output: 4 value
Prof. Amol M. Jagtap
M.Tech CSE
7972761065
Please like comment share and subscribe.
Prof. Amol M. Jagtap
For more contact : 7972761065
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Lecture 2: Simple java program and How to compile and interpret the java program» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.