java example programs for practice

Example 1: basic java coding

public class AddTwoNumbers {

   public static void main(String[] args) {
        
      int num1 = 5, num2 = 15, sum;
      sum = num1 + num2;

      System.out.println("Sum of these numbers: "+sum);
   }
}

Example 2: java coding practice

package com.example.packagenames.are.reverse.domain.all.lowercase.seperated.by.dots;
//naming conventions
public class TypeNamesArePascalCase(){
	public static final String CONSTANTS_ARE_UPPER_CASE_WITH_UNDERSCORES="Hello World";
  	private int membersArePrivateAndCamelCase;
  	public int getMembersArePrivateAndCamelCase(){
      	//You can have public getters if you want
    	return membersArePrivateAndCamelCase;
    }
  	public void setMembersArePrivateAndCamelCase(int membersArePrivateAndCamelCase){
    	//You can have public setters if you want
      	this.membersArePrivateAndCamelCase=membersArePrivateAndCamelCase;
    }
  	public void methodsAreCamelCase(){
    	
    }
}

public enum EnumsAreTypes{
	ENUM_CONSTANTS,ARE,CONSTANTS
}

Tags:

Java Example