In java we can print something using print statements. There are two methods uses for these case – print() and println()
We can print same text using these methods. Let’s see below code.
public class code1 { public static void main(String[] args) { System.out.println(“microcodes”); System.out.print(“microcodes”); } } |

print() – this method displays text into console and does not add a new line.
println() – this method displays text into console and add a new line.
Lets understand through some below code examples
public class code2 { public static void main(String[] args) { // using println() method System.out.println(“dipsayak aditi”); System.out.println(“ramesh shravani”); } } |

public class code3 { public static void main(String[] args) { // using println() method System.out.print(“dipsayak aditi”); System.out.print(“ramesh shravani”); } } |

Before starting receiving input using keyboard, first understand simple concepts of packages,classes,functions.
Package – these are collection of classes
Class – these are collection of functions
Function – function basically a set of statements
Receiving inputs
For receiving inputs using keyboard in java, we need to use ‘Scanner’ class.
This class belongs to package of ‘java.util’
Now let’s see below coding example
// importing ‘Scanner’ class from package ‘java.util’ import java.util.Scanner; public class code4 { public static void main(String[] args) { // using ‘Scanner’ class we creates a object called ‘sc’ // System.in -> it helps to get inputs from keyboard Scanner sc = new Scanner(System.in); System.out.println(“\n enter number: “); // sc.nextInt() -> it only passes input as integer int a = sc.nextInt(); } } |

Lets understand through another examples
import java.util.Scanner; public class code5 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(“\n enter String : “); // sc.next() -> it only passes input as string String a = sc.next(); } } |

Lets take another float input and display into screen
import java.util.Scanner; public class code6 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(“\n enter float number : “); // sc.nextFloat() -> it only passes input as string float a = sc.nextFloat(); System.out.println(“\n float number is “); System.out.println(a); } } |

Comments
In java, we can deals with comments.
Comments are those statements which are ignored by the compiler.
Now question arrives, why then we uses it?
Ans – when you or any developer make any application software or program, he/she need to deals with many variables, functions or even classes, third-party libraries and so on. In that time comments used to identify what gone to be used in program. It also helps in future development when another deals with project.
Now let’s understand how we use comments in java?
In java, there are two types of comments – single-line comment and multi-line comment
Single-line comment – this comment has only one single row of statement.
Multi-line comment – this comment uses when programmer needs to declare many lines.
Let’s understand this by below code example
public class comments { public static void main(String[] args) { // single-line comment /* line 1 line 2 line 3 this is a multi-line comment */ } } |
Access modifiers
Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:
At the top level— public, or package-private (no explicit modifier).
At the member level—public, private, protected, or package-private (no explicit modifier).
A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.)
At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
