Some facts about java

() - This is called a pair of Parentheses

;  The semicolon or semi-colon (;) 

"  double  quotation mark

https://en.wikipedia.org/wiki/Quotation_mark


class first character will be capital.

To create an object in java

class_name      object_name(as you want)   = new(keyword)    class_name ();

To call variables or fields in java

object_name.variable_name = value;

To refer the variables of another class 

first create object of that class and then call it like this

object_name.variable_name=input.nextInt();

//remember we are using (.) separator operator in between object and variable name

 object_name.fields_name = value;

To call methods in java

object_name.method_name = value;

To call methods from another class

first create object of that class for example if the name of the class is Add then we need to create an object  like this 

Add object_name(anything you want) = new Add();

now call it in another class with this object_name.method_name(name of the method you want to call)(if any argument);

for example -System.out.println("Sum is "+object.AdditionTwo(num1,num2)); 


To take input from keyboard

Scanner  object_name(as you want)  = new Scanner(System.in);

here scanner is class name when we import java.util.Scanner package it includes the class Scanner

sometimes we write import java.util.* package this includes all classes of util package
including Scanner classes

System.in //here System is class that's why it starts with a capital letter and in is an object.

for taking int type value

variable_name =object_name.nextInt(); 

for taking double type value


variable_name =object_name.nextDouble(); 

for taking Float type value

variable_name =object_name.nextFloat(); 

For creating array in java


Data_Type[]    array_name = new  int [size];

public static void main(string args[]){

public means we can access methods or fields outside the class.

static means we don't need need to create an object to access the method we are creating.

void means method will not return anything.

main this is the main method that means program will start executing from here.

Constructor

constructor is a special type of method in which there is no return type(Even void) and name will be same as the name of the class.

Constructor are used to initialize the value of object

1.Default constructor

2.Parameterized constructor

Abstract Window Toolkit (AWT)


Abstract Window Toolkit (AWT) is a set of application program interfaces ( API s) used by Java programmers to create graphical user interface ( GUI ) objects, such as buttons, scroll bars, and windows. AWT is part of the Java Foundation Classes ( JFC ) from Sun Microsystems, the company that originated Java. The JFC are a comprehensive set of GUI class libraries that make it easier to develop the user interface part of an application program.
A more recent set of GUI interfaces called Swing extends the AWT so that the programmer can create generalized GUI objects that are independent of a specific operating system's windowing system .


public void init() {

method is a named group of Java statements that can be called. It is similar to a subroutine or function in other programming languages. The term init() is a methodname in Java. The name is followed by Java code within { and }. A method has a name, such as init, and parentheses, such as ( ). The parentheses may contain arguments if the method is intended to receive some information to use in its statements. The init() method has no arguments inside the parentheses. That means that no data are passed to the init() method. Still, a method must have the parentheses to be identified as a method in Java. That is an important rule to know.

The init() method is started by the browser when the Java program (MyProgram.class) is loaded and run by the browser. The programmer does not write a call to the init() method.
The init() method has already been written inside the Applet class. The JApplet class is a subclass of the Applet class, and MyProgram is a subclass of the JApplet class. This means that the init() method is built-in to Java. It is not a custom method, even though you write it again inside the program that you are learning to write. Because MyProgram is a subclass of JApplet (...MyProgram extends JApplet...) and JApplet extends Applet, the programmer may use the init() method because a subclass inherits all the methods in any class that is higher up the hierarchy (the superclasses). To inherit methods from a superclass simply means that you are able to use them in your program if you need to. This is one of the powerful features of object-oriented programming. This is an important rule to know.

Here is a diagram showing the above relationships.




Inside the Applet class, the init() method has no statements in it. When the programmer uses the init() method in a program and adds statements to it, that is calledoverriding the init() methodThat is an important rule to know. This is terminology used in object-oriented programming, and you will learn more about these features as you continue to progress in your understanding of Java.
Also notice that a method has a name that begins with a lower case letter, and it has an argument list inside the parentheses, even though it may be empty. You know that init() is a method because of these properties. That is an important rule to know. There are other Java methods with names that begin with a capital letter, and you will learn about those methods later.


Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation