X

Play AlgoQuiz

Rate Us :



Share with Friends :

Menu

X

namespace :

It is a class of elements (e.g. addresses, file locations, etc.) in which each element has a name unique to that class, although it may be shared with elements in other classes.

X

javadoc :

Javadoc (originally cased as JavaDoc) is a documentation generator created by Sun Microsystems for the Java language (now owned by Oracle Corporation) for generating API documentation in HTML format from Java source code.

Structure of Java Program :

Java Program is divided into four sections :-


  • Document Section




  • Package Section




  • Import Section




  • Class Definition Section




Document Section :

In document section contain information is about the program. This section is ignored by the compiler. Documentation is provided using comments. Java supports three types of comments :-

  • SingleLine Comment (//) :

It is used to provide single line comment.


  • MultiLine Comment (/*......*/) :

It is used to provide multiple line comment.


  • Documented Comment(/**......*/) :

It can be separated from the source program to build document file(.html). This building of document file is done using utility called javadoc. Documented comments are optional.


Package Section :

Package is a collection of types. These types can be classes, interfaces, or enum. Package is a directory which contain '.class' files. Package provides namespace management & access protection(i.e. security). One source program allow only one package statement.


Import Section :

Import is used for accessing the contents of existing package. Import doesn't include class but add package reference. It adds name of the package to which it belongs. A Java program can have multiple import statements. The default package which is import by any Java program is java.lang


Class Definition Section :

As the function in Java encapsulated inside the class so it called "method". Every Java executable program must have a class which contain 'main()' method. Class is of two types :- Executable & Non-Executable. Class is an user defined data type.


Printing methods :

  • System.out.println()




  • System.out.print()




  • System.out.printf()




System :-

  • System is a predefined class.

  • This class is available in java.lang package.

  • This default class is provided by Java.

out :-

  • It is a variable of PrintStream class.

  • It is a reference variable which holds on address of PrintStream object.

  • It is a static reference variable. So it is binding with class name (i.e. System.out).

println :-

  • It is a method of PrintStream class.

  • It displays data on console (monitor) and insert new line.

print :-

  • It is also a method of PrintStream class.

  • It displays data on console (monitor) without inserting new line.

printf :-

  • It is also a method of PrintStream class.

  • This method display various types of values.

  • It displays one or more than one values.

Constants :-

A constant is a value of a variable that never changes.


static :

It is an access modifier. The static method is called without creating an object of class. Static methods binding with class name.


void :

This means that the method doesn't return any value.


main() :

It is the name of the method that is understandable by JVM.


String [ ] args :

main() method is called from Operating System. The values which are send from Operating System environment are of type 'String'. It is an array because it receives 0 or more values. It is also called command line arguments.

Example :

class Example { public static void main(String [ ] args) { System.out.println("Inside main of String"); } public static void main(int [ ] args) { System.out.println("Inside main of int"); } public static void main(float [ ] args) { System.out.println("Inside main of float"); } }

Output :

javac Example.java java Example Inside main of String
Note :-

  • public is an access modifier. main() method is public because it is accessible outside the environment or package.

  • 'javac' is used to compile the program and 'java' is used to run the program.


X

MiniDoll :

MiniDoll is an application to learn with fun. You can play it to solve some tricky questions related to Java Programming. Either enjoy playing it alone or discuss with your friends to solve it. It is a simple approach to learn by solving questions. This application has different topics of Java and each topic is divided into three phases. Start solving from initial topic to final topic and by the end of every topic you can boost your concept of that topic.