Java Basics
Java Basics
Session 2
Java
............
software(desktop ApplicationS),
......................................
packages
class
blocks
statements
.................................
import java.lang.*;
class Test
{
public static void main(String[] args)
System.out.println("btps");
Note:-
ex:-print(),btps(),....
but if a method name contain two words combination,then 2nd word, 1st letter should be
capital letter.
ex:-btpsKanpur(),nextInt(),nextDouble(),.....
..................................................................................................
.........................................
.........................................................
...........................
javac
.........
java
......
this file is responsible to run java Prog becoz it internally calls the jvm.
First Way of Writing First Java Program
...........................................
import java.lang.*;
class Test
System.out.println("welcome to BTPS");
if you want to keep your java prog- any where in your System then you have to register the java
..............................
4-Make A folder in YOUR System any where name as My All java Prog.
7-save the java prog where your folder is persent by using .java extention
open the cmd or Console window where your all prog is present.
c.....>javac filename......enter..
ex.
c......>javac Test.java
c....>java ClassName.....enter
ex.
......................
....................................
..............................
..............................
..........................................
...................................................
.................................
1- Can we defined more than one classes inside a single java file?
ans:- Yes, we can define more than one classes in signle java file but after
2-Can we defined more than one main () method in single java file?
ans:- yes we can define more than one main() method in single java file inside seprate
classes.
3-can we defined more than one public classes in single java file?
ans:- No,we can not define more than one public classes in single java file.
we can define only one public class and file name should be same as public class Name.
Note:- whenever we run our java prog- jvm first search the main() method in that class.
..................................................................
No.. IT is not recommondded to keep more than one classes in signle java file.
............................................................
3-System.in.read()
Scanner class is easieast way to take input from user in all amoung ways.
....................................................
ex. next(),nextInt(),nextFloat(),nextLine(),..........
4-Scanner class is final class means we can not create child classes from it.